##// END OF EJS Templates
mdiff/patch: fix bad hunk handling for unified diffs with zero context...
Nicolas Venegas -
r15462:2b1ec74c stable
parent child Browse files
Show More
@@ -180,8 +180,14 b' def _unidiff(t1, t2, l1, l2, opts=defaul'
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):
@@ -723,11 +723,10 b' class patchfile(object):'
723
723
724 # fast case first, no offsets, no fuzz
724 # fast case first, no offsets, no fuzz
725 old = h.old()
725 old = h.old()
726 # patch starts counting at 1 unless we are adding the file
726 start = h.starta + self.offset
727 if h.starta == 0:
727 # zero length hunk ranges already have their start decremented
728 start = 0
728 if h.lena:
729 else:
729 start -= 1
730 start = h.starta + self.offset - 1
731 orig_start = start
730 orig_start = start
732 # if there's skew we want to emit the "(offset %d lines)" even
731 # if there's skew we want to emit the "(offset %d lines)" even
733 # when the hunk cleanly applies at start + skew, so skip the
732 # when the hunk cleanly applies at start + skew, so skip the
@@ -89,23 +89,65 b' invalid diff.unified'
89 abort: diff context lines count must be an integer, not 'foo'
89 abort: diff context lines count must be an integer, not 'foo'
90 [255]
90 [255]
91
91
92 test off-by-one error with diff -p
92 0 lines of context hunk header matches gnu diff hunk header
93
94 $ hg init diffzero
95 $ cd diffzero
96 $ cat > f1 << EOF
97 > c2
98 > c4
99 > c5
100 > EOF
101 $ hg commit -Am0
102 adding f1
103
104 $ cat > f2 << EOF
105 > c1
106 > c2
107 > c3
108 > c4
109 > EOF
110 $ diff -U0 f1 f2
111 --- f1 * (glob)
112 +++ f2 * (glob)
113 @@ -0,0 +1 @@
114 +c1
115 @@ -1,0 +3 @@
116 +c3
117 @@ -3 +4,0 @@
118 -c5
119 [1]
93
120
94 $ hg init diffp
121 $ mv f2 f1
95 $ cd diffp
122 $ hg diff -U0 --nodates
96 $ echo a > a
123 diff -r 55d8ff78db23 f1
97 $ hg ci -Ama
124 --- a/f1
98 adding a
125 +++ b/f1
99 $ rm a
126 @@ -0,0 +1,1 @@
100 $ echo b > a
127 +c1
101 $ echo a >> a
128 @@ -1,0 +3,1 @@
102 $ echo c >> a
129 +c3
103 $ hg diff -U0 -p --nodates
130 @@ -3,1 +4,0 @@
104 diff -r cb9a9f314b8b a
131 -c5
105 --- a/a
106 +++ b/a
107 @@ -1,0 +1,1 @@
108 +b
109 @@ -2,0 +3,1 @@ a
110 +c
111
132
133 $ hg diff -U0 --nodates --git
134 diff --git a/f1 b/f1
135 --- a/f1
136 +++ b/f1
137 @@ -0,0 +1,1 @@
138 +c1
139 @@ -1,0 +3,1 @@
140 +c3
141 @@ -3,1 +4,0 @@
142 -c5
143
144 $ hg diff -U0 --nodates -p
145 diff -r 55d8ff78db23 f1
146 --- a/f1
147 +++ b/f1
148 @@ -0,0 +1,1 @@
149 +c1
150 @@ -1,0 +3,1 @@ c2
151 +c3
152 @@ -3,1 +4,0 @@ c4
153 -c5
@@ -958,3 +958,39 b' diff lines looking like headers'
958 $ diff want have
958 $ diff want have
959 $ cd ..
959 $ cd ..
960
960
961 import a unified diff with no lines of context (diff -U0)
962
963 $ hg init diffzero
964 $ cd diffzero
965 $ cat > f << EOF
966 > c2
967 > c4
968 > c5
969 > EOF
970 $ hg commit -Am0
971 adding f
972
973 $ hg import --no-commit - << EOF
974 > # HG changeset patch
975 > # User test
976 > # Date 0 0
977 > # Node ID f4974ab632f3dee767567b0576c0ec9a4508575c
978 > # Parent 8679a12a975b819fae5f7ad3853a2886d143d794
979 > 1
980 > diff -r 8679a12a975b -r f4974ab632f3 f
981 > --- a/f Thu Jan 01 00:00:00 1970 +0000
982 > +++ b/f Thu Jan 01 00:00:00 1970 +0000
983 > @@ -0,0 +1,1 @@
984 > +c1
985 > @@ -1,0 +3,1 @@
986 > +c3
987 > @@ -3,1 +4,0 @@
988 > -c5
989 > EOF
990 applying patch from stdin
991
992 $ cat f
993 c1
994 c2
995 c3
996 c4
General Comments 0
You need to be logged in to leave comments. Login now