mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 21:40:55 +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();
|
||||
$changes = rtrim($hunk->getChanges(), "\n");
|
||||
foreach (explode("\n", $changes) as $line) {
|
||||
$type = $line[1]; // Change type in the original diff.
|
||||
if ($line[0] == ' ') {
|
||||
$diff_type = $line[0]; // Change type in diff of diffs.
|
||||
$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.
|
||||
$key = max(last_key($olds), last_key($news)) + 1;
|
||||
$olds[$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_new++;
|
||||
} else if ($line[0] == '-') {
|
||||
$olds[] = array($n_old, $type);
|
||||
$n_old++;
|
||||
} else if ($line[0] == '+') {
|
||||
$news[] = array($n_new, $type);
|
||||
}
|
||||
if (($diff_type == '+' || $diff_type == ' ') && $orig_type != '-') {
|
||||
$n_new++;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue