comparison 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
comparison
equal deleted inserted replaced
15461:6ba2fc0a87ab 15462:2b1ec74c961f
178 # by recording this hunk's starting point as the next place to 178 # by recording this hunk's starting point as the next place to
179 # start looking for function lines, we avoid reading any line in 179 # start looking for function lines, we avoid reading any line in
180 # the file more than once. 180 # the file more than once.
181 lastfunc[0] = astart 181 lastfunc[0] = astart
182 182
183 yield "@@ -%d,%d +%d,%d @@%s\n" % (astart + 1, alen, 183 # zero-length hunk ranges report their start line as one less
184 bstart + 1, blen, func) 184 if alen:
185 astart += 1
186 if blen:
187 bstart += 1
188
189 yield "@@ -%d,%d +%d,%d @@%s\n" % (astart, alen,
190 bstart, blen, func)
185 for x in delta: 191 for x in delta:
186 yield x 192 yield x
187 for x in xrange(a2, aend): 193 for x in xrange(a2, aend):
188 yield ' ' + l1[x] 194 yield ' ' + l1[x]
189 195