##// END OF EJS Templates
patch: better handling of sequence of offset patch hunks (issue1941)...
Greg Onufer -
r10135:9a4034b6 stable
parent child Browse files
Show More
@@ -0,0 +1,67 b''
1 #!/bin/sh
2
3 cat > writepatterns.py <<EOF
4 import sys
5
6 path = sys.argv[1]
7 patterns = sys.argv[2:]
8
9 fp = file(path, 'wb')
10 for pattern in patterns:
11 count = int(pattern[0:-1])
12 char = pattern[-1] + '\n'
13 fp.write(char*count)
14 fp.close()
15 EOF
16
17 echo % prepare repo
18 hg init a
19 cd a
20
21 # These initial lines of Xs were not in the original file used to generate
22 # the patch. So all the patch hunks need to be applied to a constant offset
23 # within this file. If the offset isn't tracked then the hunks can be
24 # applied to the wrong lines of this file.
25 python ../writepatterns.py a 34X 10A 1B 10A 1C 10A 1B 10A 1D 10A 1B 10A 1E 10A 1B 10A
26 hg commit -Am adda
27
28 # This is a cleaner patch generated via diff
29 # In this case it reproduces the problem when
30 # the output of hg export does not
31 echo % import patch
32 hg import -v -m 'b' -d '2 0' - <<EOF
33 --- a/a 2009-12-08 19:26:17.000000000 -0800
34 +++ b/a 2009-12-08 19:26:17.000000000 -0800
35 @@ -9,7 +9,7 @@
36 A
37 A
38 B
39 -A
40 +a
41 A
42 A
43 A
44 @@ -53,7 +53,7 @@
45 A
46 A
47 B
48 -A
49 +a
50 A
51 A
52 A
53 @@ -75,7 +75,7 @@
54 A
55 A
56 B
57 -A
58 +a
59 A
60 A
61 A
62 EOF
63
64 echo % compare imported changes against reference file
65 python ../writepatterns.py aref 34X 10A 1B 1a 9A 1C 10A 1B 10A 1D 10A 1B 1a 9A 1E 10A 1B 1a 9A
66 diff -u aref a
67
@@ -0,0 +1,10 b''
1 % prepare repo
2 adding a
3 % import patch
4 applying patch from stdin
5 patching file a
6 Hunk #1 succeeded at 43 (offset 34 lines).
7 Hunk #2 succeeded at 87 (offset 34 lines).
8 Hunk #3 succeeded at 109 (offset 34 lines).
9 a
10 % compare imported changes against reference file
@@ -286,6 +286,7 b' class patchfile(object):'
286 self.hash = {}
286 self.hash = {}
287 self.dirty = 0
287 self.dirty = 0
288 self.offset = 0
288 self.offset = 0
289 self.skew = 0
289 self.rej = []
290 self.rej = []
290 self.fileprinted = False
291 self.fileprinted = False
291 self.printfile(False)
292 self.printfile(False)
@@ -423,7 +424,10 b' class patchfile(object):'
423 else:
424 else:
424 start = h.starta + self.offset - 1
425 start = h.starta + self.offset - 1
425 orig_start = start
426 orig_start = start
426 if diffhelpers.testhunk(old, self.lines, start) == 0:
427 # if there's skew we want to emit the "(offset %d lines)" even
428 # when the hunk cleanly applies at start + skew, so skip the
429 # fast case code
430 if self.skew == 0 and diffhelpers.testhunk(old, self.lines, start) == 0:
427 if h.rmfile():
431 if h.rmfile():
428 self.unlink(self.fname)
432 self.unlink(self.fname)
429 else:
433 else:
@@ -439,7 +443,7 b' class patchfile(object):'
439 # override the start line and use eof here
443 # override the start line and use eof here
440 search_start = len(self.lines)
444 search_start = len(self.lines)
441 else:
445 else:
442 search_start = orig_start
446 search_start = orig_start + self.skew
443
447
444 for fuzzlen in xrange(3):
448 for fuzzlen in xrange(3):
445 for toponly in [ True, False ]:
449 for toponly in [ True, False ]:
@@ -451,6 +455,7 b' class patchfile(object):'
451 newlines = h.new(fuzzlen, toponly)
455 newlines = h.new(fuzzlen, toponly)
452 self.lines[l : l + len(old)] = newlines
456 self.lines[l : l + len(old)] = newlines
453 self.offset += len(newlines) - len(old)
457 self.offset += len(newlines) - len(old)
458 self.skew = l - orig_start
454 self.dirty = 1
459 self.dirty = 1
455 if fuzzlen:
460 if fuzzlen:
456 fuzzstr = "with fuzz %d " % fuzzlen
461 fuzzstr = "with fuzz %d " % fuzzlen
General Comments 0
You need to be logged in to leave comments. Login now