Mercurial > public > mercurial-scm > hg-stable
diff mercurial/patch.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 | 628a4a9e411d |
children | 5414b56cfad6 3da1f60fc80d |
line wrap: on
line diff
--- a/mercurial/patch.py Tue Nov 08 17:08:58 2011 +0100 +++ b/mercurial/patch.py Wed Nov 09 16:55:59 2011 -0800 @@ -723,11 +723,10 @@ # fast case first, no offsets, no fuzz old = h.old() - # patch starts counting at 1 unless we are adding the file - if h.starta == 0: - start = 0 - else: - start = h.starta + self.offset - 1 + start = h.starta + self.offset + # zero length hunk ranges already have their start decremented + if h.lena: + start -= 1 orig_start = start # if there's skew we want to emit the "(offset %d lines)" even # when the hunk cleanly applies at start + skew, so skip the