# HG changeset patch # User Patrick Mezard # Date 1261609273 -3600 # Node ID 270367ec4d30292df4f4a135ae5443ca68ddf029 # Parent 821793e3049c37a095db5de48360e398e4b53fce# Parent 9a4034b630c4218db26091c75175ed3168ea42cb Merge with crew-stable diff -r 821793e3049c -r 270367ec4d30 mercurial/patch.py --- a/mercurial/patch.py Wed Dec 23 23:28:53 2009 +0100 +++ b/mercurial/patch.py Thu Dec 24 00:01:13 2009 +0100 @@ -294,6 +294,7 @@ self.hash = {} self.dirty = 0 self.offset = 0 + self.skew = 0 self.rej = [] self.fileprinted = False self.printfile(False) @@ -449,7 +450,10 @@ else: start = h.starta + self.offset - 1 orig_start = start - if diffhelpers.testhunk(old, self.lines, start) == 0: + # if there's skew we want to emit the "(offset %d lines)" even + # when the hunk cleanly applies at start + skew, so skip the + # fast case code + if self.skew == 0 and diffhelpers.testhunk(old, self.lines, start) == 0: if h.rmfile(): self.unlink(self.fname) else: @@ -465,7 +469,7 @@ # override the start line and use eof here search_start = len(self.lines) else: - search_start = orig_start + search_start = orig_start + self.skew for fuzzlen in xrange(3): for toponly in [ True, False ]: @@ -477,6 +481,7 @@ newlines = h.new(fuzzlen, toponly) self.lines[l : l + len(old)] = newlines self.offset += len(newlines) - len(old) + self.skew = l - orig_start self.dirty = 1 if fuzzlen: fuzzstr = "with fuzz %d " % fuzzlen diff -r 821793e3049c -r 270367ec4d30 tests/test-patch-offset --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-patch-offset Thu Dec 24 00:01:13 2009 +0100 @@ -0,0 +1,67 @@ +#!/bin/sh + +cat > writepatterns.py <