summaryrefslogtreecommitdiff
path: root/src/diff_output.c
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2013-01-11 11:34:13 -0800
committerVicent Martí <vicent@github.com>2013-01-11 11:34:13 -0800
commit6e19edaa40559a53b8fbf544fe0a6d1f05096614 (patch)
tree46e17b0abda74291e6c66209c1fda25602ba9923 /src/diff_output.c
parent80d647adc31e3c8721dc578140494f916463f623 (diff)
parent805c476c83d100696b9ebe578f0ee2399d55b3c8 (diff)
downloadlibgit2-6e19edaa40559a53b8fbf544fe0a6d1f05096614.tar.gz
Merge pull request #1229 from arrbee/fix-diff-patch-line-numbers
Fix diff patch line number calculation
Diffstat (limited to 'src/diff_output.c')
-rw-r--r--src/diff_output.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/src/diff_output.c b/src/diff_output.c
index f98665dfb..d75a7bb94 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -821,6 +821,9 @@ static int diff_patch_hunk_cb(
hunk->line_start = patch->lines_size;
hunk->line_count = 0;
+ patch->oldno = range->old_start;
+ patch->newno = range->new_start;
+
return 0;
}
@@ -879,24 +882,23 @@ static int diff_patch_line_cb(
++line->lines;
}
- if (!last) {
- line->oldno = hunk->range.old_start;
- line->newno = hunk->range.new_start;
- } else {
- switch (last->origin) {
- case GIT_DIFF_LINE_ADDITION:
- line->oldno = last->oldno;
- line->newno = last->newno + last->lines;
- break;
- case GIT_DIFF_LINE_DELETION:
- line->oldno = last->oldno + last->lines;
- line->newno = last->newno;
- break;
- default:
- line->oldno = last->oldno + last->lines;
- line->newno = last->newno + last->lines;
- break;
- }
+ switch (line_origin) {
+ case GIT_DIFF_LINE_ADDITION:
+ line->oldno = -1;
+ line->newno = patch->newno;
+ patch->newno += line->lines;
+ break;
+ case GIT_DIFF_LINE_DELETION:
+ line->oldno = patch->oldno;
+ line->newno = -1;
+ patch->oldno += line->lines;
+ break;
+ default:
+ line->oldno = patch->oldno;
+ line->newno = patch->newno;
+ patch->oldno += line->lines;
+ patch->newno += line->lines;
+ break;
}
hunk->line_count++;