Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F94015094
DiffusionLowLevelMercurialBranchesQuery.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Dec 3, 06:38
Size
1 KB
Mime Type
text/x-php
Expires
Thu, Dec 5, 06:38 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22711892
Attached To
rPH Phabricator
DiffusionLowLevelMercurialBranchesQuery.php
View Options
<?php
/**
* Execute and parse a low-level Mercurial branches query using `hg branches`.
*/
final
class
DiffusionLowLevelMercurialBranchesQuery
extends
DiffusionLowLevelQuery
{
private
$contains
;
public
function
withContainsCommit
(
$commit
)
{
$this
->
contains
=
$commit
;
return
$this
;
}
protected
function
executeQuery
()
{
$repository
=
$this
->
getRepository
();
$specs
=
array
();
if
(
$this
->
contains
!==
null
)
{
$specs
[
'all'
]
=
hgsprintf
(
'(descendants(%s) and head())'
,
$this
->
contains
);
$specs
[
'open'
]
=
hgsprintf
(
'(descendants(%s) and head() and not closed())'
,
$this
->
contains
);
}
else
{
$specs
[
'all'
]
=
hgsprintf
(
'head()'
);
$specs
[
'open'
]
=
hgsprintf
(
'head() and not closed()'
);
}
$futures
=
array
();
foreach
(
$specs
as
$key
=>
$spec
)
{
$futures
[
$key
]
=
$repository
->
getLocalCommandFuture
(
'log --template %s --rev %s'
,
'{node}
\1
{branch}
\2
'
,
$spec
);
}
$branches
=
array
();
$open
=
array
();
foreach
(
new
FutureIterator
(
$futures
)
as
$key
=>
$future
)
{
list
(
$stdout
)
=
$future
->
resolvex
();
$lines
=
explode
(
"
\2
"
,
$stdout
);
$lines
=
array_filter
(
$lines
);
foreach
(
$lines
as
$line
)
{
list
(
$node
,
$branch
)
=
explode
(
"
\1
"
,
$line
);
$id
=
$node
.
'/'
.
$branch
;
if
(
empty
(
$branches
[
$id
]))
{
$branches
[
$id
]
=
id
(
new
DiffusionRepositoryRef
())
->
setShortName
(
$branch
)
->
setCommitIdentifier
(
$node
);
}
if
(
$key
==
'open'
)
{
$open
[
$id
]
=
true
;
}
}
}
foreach
(
$branches
as
$id
=>
$branch
)
{
$branch
->
setRawFields
(
array
(
'closed'
=>
(
empty
(
$open
[
$id
])),
));
}
return
array_values
(
$branches
);
}
}
Event Timeline
Log In to Comment