Improve "thread" rendering of unusually-shaped graphs
Summary:
Ref T4788. This fixes all the bugs I was immediately able to catch:
- "Directory-Like" graph shapes could draw too many vertical lines.
- "Reverse-Directory-Like" graph shapes could draw too few vertical lines.
- Terminated, branched graph shapes drew the very last line to the wrong place.
This covers the behavior with tests, so we should be able to fix more stuff later without breaking anything.
Test Plan:
- Added failing tests and made them pass.
{F1708158}
{F1708159}
{F1708160}
{F1708161}
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4788
Differential Revision: https://secure.phabricator.com/D16216
This commit is contained in:
@@ -23,7 +23,7 @@ final class PHUIDiffGraphView extends Phobject {
|
||||
return $this->isTail;
|
||||
}
|
||||
|
||||
public function renderGraph(array $parents) {
|
||||
public function renderRawGraph(array $parents) {
|
||||
// This keeps our accumulated information about each line of the
|
||||
// merge/branch graph.
|
||||
$graph = array();
|
||||
@@ -47,7 +47,10 @@ final class PHUIDiffGraphView extends Phobject {
|
||||
$line = '';
|
||||
$found = false;
|
||||
$pos = count($threads);
|
||||
for ($n = 0; $n < $count; $n++) {
|
||||
|
||||
$thread_count = $pos;
|
||||
for ($n = 0; $n < $thread_count; $n++) {
|
||||
|
||||
if (empty($threads[$n])) {
|
||||
$line .= ' ';
|
||||
continue;
|
||||
@@ -147,16 +150,30 @@ final class PHUIDiffGraphView extends Phobject {
|
||||
$line = $graph[$key]['line'];
|
||||
$len = strlen($line);
|
||||
for ($ii = 0; $ii < $len; $ii++) {
|
||||
if (isset($terminated[$ii])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$c = $line[$ii];
|
||||
if ($c == 'o') {
|
||||
// If we've already terminated this thread, we don't need to add
|
||||
// a terminator.
|
||||
if (isset($terminated[$ii])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$terminated[$ii] = true;
|
||||
|
||||
// If this thread is joinining some other node here, we don't want
|
||||
// to terminate it.
|
||||
if (isset($graph[$key + 1])) {
|
||||
$joins = $graph[$key + 1]['join'];
|
||||
if (in_array($ii, $joins)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$graph[$key]['line'][$ii] = 'x';
|
||||
} else if ($c != ' ') {
|
||||
$terminated[$ii] = true;
|
||||
} else {
|
||||
unset($terminated[$ii]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,6 +183,12 @@ final class PHUIDiffGraphView extends Phobject {
|
||||
$graph[] = $last;
|
||||
}
|
||||
|
||||
return array($graph, $count);
|
||||
}
|
||||
|
||||
public function renderGraph(array $parents) {
|
||||
list($graph, $count) = $this->renderRawGraph($parents);
|
||||
|
||||
// Render into tags for the behavior.
|
||||
|
||||
foreach ($graph as $k => $meta) {
|
||||
|
||||
Reference in New Issue
Block a user