##// END OF EJS Templates
patch: handle empty vs no file in git patches (issue906)
Patrick Mezard -
r5852:03ce5a91 default
parent child Browse files
Show More
@@ -499,7 +499,7 b' class patchfile:'
499 499 return -1
500 500
501 501 class hunk:
502 def __init__(self, desc, num, lr, context):
502 def __init__(self, desc, num, lr, context, gitpatch=None):
503 503 self.number = num
504 504 self.desc = desc
505 505 self.hunk = [ desc ]
@@ -509,6 +509,7 b' class hunk:'
509 509 self.read_context_hunk(lr)
510 510 else:
511 511 self.read_unified_hunk(lr)
512 self.gitpatch = gitpatch
512 513
513 514 def read_unified_hunk(self, lr):
514 515 m = unidesc.match(self.desc)
@@ -663,10 +664,12 b' class hunk:'
663 664 return len(self.a) == self.lena and len(self.b) == self.lenb
664 665
665 666 def createfile(self):
666 return self.starta == 0 and self.lena == 0
667 create = self.gitpatch is None or self.gitpatch.op == 'ADD'
668 return self.starta == 0 and self.lena == 0 and create
667 669
668 670 def rmfile(self):
669 return self.startb == 0 and self.lenb == 0
671 remove = self.gitpatch is None or self.gitpatch.op == 'DELETE'
672 return self.startb == 0 and self.lenb == 0 and remove
670 673
671 674 def fuzzit(self, l, fuzz, toponly):
672 675 # this removes context lines from the top and bottom of list 'l'. It
@@ -918,7 +921,8 b' def applydiff(ui, fp, changed, strip=1, '
918 921 try:
919 922 if context == None and x.startswith('***************'):
920 923 context = True
921 current_hunk = hunk(x, hunknum + 1, lr, context)
924 gpatch = changed.get(bfile[2:], (None, None))[1]
925 current_hunk = hunk(x, hunknum + 1, lr, context, gpatch)
922 926 except PatchError, err:
923 927 ui.debug(err)
924 928 current_hunk = None
@@ -153,3 +153,31 b' echo line0 >> a'
153 153 hg ci -m brancha
154 154 hg import -v tip.patch
155 155 cd ..
156
157 # Test hunk touching empty files (issue906)
158 hg init empty
159 cd empty
160 touch a
161 touch b1
162 touch c1
163 echo d > d
164 hg ci -Am init
165 echo a > a
166 echo b > b1
167 hg mv b1 b2
168 echo c > c1
169 hg copy c1 c2
170 rm d
171 touch d
172 hg diff --git
173 hg ci -m empty
174 hg export --git tip > empty.diff
175 hg up -C 0
176 hg import empty.diff
177 for name in a b1 b2 c1 c2 d;
178 do
179 echo % $name file
180 test -f $name && cat $name
181 done
182 cd ..
183
@@ -132,3 +132,48 b' applying tip.patch'
132 132 patching file a
133 133 Hunk #1 succeeded at 1 with fuzz 2 (offset -2 lines).
134 134 a
135 adding a
136 adding b1
137 adding c1
138 adding d
139 diff --git a/a b/a
140 --- a/a
141 +++ b/a
142 @@ -0,0 +1,1 @@
143 +a
144 diff --git a/b1 b/b2
145 rename from b1
146 rename to b2
147 --- a/b1
148 +++ b/b2
149 @@ -0,0 +1,1 @@
150 +b
151 diff --git a/c1 b/c1
152 --- a/c1
153 +++ b/c1
154 @@ -0,0 +1,1 @@
155 +c
156 diff --git a/c1 b/c2
157 copy from c1
158 copy to c2
159 --- a/c1
160 +++ b/c2
161 @@ -0,0 +1,1 @@
162 +c
163 diff --git a/d b/d
164 --- a/d
165 +++ b/d
166 @@ -1,1 +0,0 @@
167 -d
168 4 files updated, 0 files merged, 2 files removed, 0 files unresolved
169 applying empty.diff
170 % a file
171 a
172 % b1 file
173 % b2 file
174 b
175 % c1 file
176 c
177 % c2 file
178 c
179 % d file
General Comments 0
You need to be logged in to leave comments. Login now