mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-03 19:31:02 +01:00
Fix computing line numbers in diff of diffs
Test Plan: Live in prod. Auditors: jungejason
This commit is contained in:
parent
99df72b81c
commit
a2f4d661b9
1 changed files with 11 additions and 8 deletions
|
@ -133,19 +133,22 @@ final class DifferentialChangesetParser {
|
||||||
$n_new = $hunk->getNewOffset();
|
$n_new = $hunk->getNewOffset();
|
||||||
$changes = rtrim($hunk->getChanges(), "\n");
|
$changes = rtrim($hunk->getChanges(), "\n");
|
||||||
foreach (explode("\n", $changes) as $line) {
|
foreach (explode("\n", $changes) as $line) {
|
||||||
$type = $line[1]; // Change type in the original diff.
|
$diff_type = $line[0]; // Change type in diff of diffs.
|
||||||
if ($line[0] == ' ') {
|
$orig_type = $line[1]; // Change type in the original diff.
|
||||||
|
if ($diff_type == ' ') {
|
||||||
// Use the same key for lines that are next to each other.
|
// Use the same key for lines that are next to each other.
|
||||||
$key = max(last_key($olds), last_key($news)) + 1;
|
$key = max(last_key($olds), last_key($news)) + 1;
|
||||||
$olds[$key] = null;
|
$olds[$key] = null;
|
||||||
$news[$key] = null;
|
$news[$key] = null;
|
||||||
|
} else if ($diff_type == '-') {
|
||||||
|
$olds[] = array($n_old, $orig_type);
|
||||||
|
} else if ($diff_type == '+') {
|
||||||
|
$news[] = array($n_new, $orig_type);
|
||||||
|
}
|
||||||
|
if (($diff_type == '-' || $diff_type == ' ') && $orig_type != '-') {
|
||||||
$n_old++;
|
$n_old++;
|
||||||
$n_new++;
|
}
|
||||||
} else if ($line[0] == '-') {
|
if (($diff_type == '+' || $diff_type == ' ') && $orig_type != '-') {
|
||||||
$olds[] = array($n_old, $type);
|
|
||||||
$n_old++;
|
|
||||||
} else if ($line[0] == '+') {
|
|
||||||
$news[] = array($n_new, $type);
|
|
||||||
$n_new++;
|
$n_new++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue