Mercurial > public > mercurial-scm > hg-stable
diff mercurial/mdiff.py @ 15462:2b1ec74c961f stable
mdiff/patch: fix bad hunk handling for unified diffs with zero context
Prior to this patch "hg diff -U0", i.e., zero lines of context, would
output hunk headers with a start line one greater than what GNU patch
and git output. Guido van Rossum documents the unified diff format[1]
as having a start line value "one lower than one would expect" for
zero length hunks.
Comparing the behaviour of the three systems prior to this patch in
transforming
c1
c3
to
c1
c2
c3
- GNU "diff -U0" reports the hunk as "@@ -1,0 +2 @@"
- "git diff -U0" reports the hunk as "@@ -1,0 +2 @@"
- "hg diff -U0" reports the hunk as "@@ -2,0 +2,1 @@"
After this patch, "hg diff -U0" reports "@@ -1,0 +2,1 @@".
Since "hg export --config diff.unified=0" outputs zero-context unified
diffs, "hg import" has also been updated to account for start lines
one less than expected for zero length hunk ranges.
[1]: http://www.artima.com/weblogs/viewpost.jsp?thread=164293
author | Nicolas Venegas <nvenegas@atlassian.com> |
---|---|
date | Wed, 09 Nov 2011 16:55:59 -0800 |
parents | 16dc9a32ca04 |
children | f520c9616db5 3774e1453ef4 |
line wrap: on
line diff
--- a/mercurial/mdiff.py Tue Nov 08 17:08:58 2011 +0100 +++ b/mercurial/mdiff.py Wed Nov 09 16:55:59 2011 -0800 @@ -180,8 +180,14 @@ # the file more than once. lastfunc[0] = astart - yield "@@ -%d,%d +%d,%d @@%s\n" % (astart + 1, alen, - bstart + 1, blen, func) + # zero-length hunk ranges report their start line as one less + if alen: + astart += 1 + if blen: + bstart += 1 + + yield "@@ -%d,%d +%d,%d @@%s\n" % (astart, alen, + bstart, blen, func) for x in delta: yield x for x in xrange(a2, aend):