Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F7583159
reach.php
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
epriestley
Jun 15 2020, 3:15 PM
2020-06-15 15:15:07 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
reach.php
View Options
public
function
newReachForWaypoints
(
array
$waypoints
)
{
$graph
=
$this
->
getGraph
();
$partition
=
array_fuse
(
$this
->
hashes
);
foreach
(
$waypoints
as
$hash
)
{
$waypoint_reach
[
$hash
]
=
$this
->
newReachFromHash
(
$hash
);
}
$stack
=
array
();
foreach
(
$this
->
getHeads
()
as
$hash
)
{
$stack
[]
=
$graph
->
getNode
(
$hash
);
$reach
[
$hash
]
=
$this
->
newReachFromHash
(
$hash
);
}
// Find nodes with multiple children which need to wait until all of their
// children have been reached before they can be painted.
$wait
=
array
();
foreach
(
$partition
as
$hash
)
{
$node
=
$graph
->
getNode
(
$hash
);
$children
=
$node
->
getChildNodes
();
if
(
count
(
$children
)
<
2
)
{
// If the node has one or fewer children, we can paint it as soon
// as we reach it.
continue
;
}
// Discard children which aren't in the partition.
$need
=
array
();
foreach
(
$children
as
$child_node
)
{
$child_hash
=
$child_node
->
getCommitHash
();
if
(!
isset
(
$partition
[
$child_hash
]))
{
continue
;
}
$need
[]
=
$child_hash
;
}
$need_count
=
count
(
$need
);
if
(
$need_count
<
2
)
{
// If we have one or fewer children in the partition, we can paint
// as soon as we reach the node.
continue
;
}
$wait
[
$node
->
getCommitHash
()]
=
$need_count
;
}
while
(
$stack
)
{
$node
=
array_pop
(
$stack
);
$node_hash
=
$node
->
getCommitHash
();
if
(
isset
(
$waypoint_reach
[
$node_hash
]))
{
$node_reach
=
$waypoint_reach
[
$node_hash
];
}
else
{
$node_reach
=
$reach
[
$node_hash
];
}
foreach
(
$node
->
getParentNodes
()
as
$parent_node
)
{
$parent_hash
=
$parent_node
->
getCommitHash
();
if
(
isset
(
$reach
[
$parent_hash
]))
{
$reach
[
$parent_hash
]
=
$this
->
newReach
(
$reach
[
$parent_hash
],
$node_reach
);
continue
;
}
$reach
[
$parent_hash
]
=
$node_reach
;
if
(
isset
(
$wait
[
$parent_hash
]))
{
$wait
[
$parent_hash
]--;
if
(
$wait
[
$parent_hash
])
{
continue
;
}
}
$stack
[]
=
$parent_node
;
}
}
return
id
(
new
ArcanistCommitGraphReach
())
->
setPartition
(
$this
)
->
setReach
(
$reach
);
}
private
function
newReachFromHash
(
$hash
)
{
return
array
(
$hash
=>
$hash
);
}
private
function
newReach
(
$u
,
$v
)
{
return
$u
+
$v
;
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
2403356
Default Alt Text
reach.php (2 KB)
Attached To
Mode
P2143 reach.php
Attached
Detach File
Event Timeline
Log In to Comment