##// END OF EJS Templates
handle files with both git binary patches and copy/rename ops
Alexis S. L. Carvalho -
r3716:ab560042 default
parent child Browse files
Show More
@@ -114,6 +114,10 b' def extract(ui, fileobj):'
114 114 return None, message, user, date
115 115 return tmpname, message, user, date
116 116
117 GP_PATCH = 1 << 0 # we have to run patch
118 GP_FILTER = 1 << 1 # there's some copy/rename operation
119 GP_BINARY = 1 << 2 # there's a binary patch
120
117 121 def readgitpatch(patchname):
118 122 """extract git-style metadata about patches from <patchname>"""
119 123 class gitpatch:
@@ -133,7 +137,7 b' def readgitpatch(patchname):'
133 137 gp = None
134 138 gitpatches = []
135 139 # Can have a git patch with only metadata, causing patch to complain
136 dopatch = False
140 dopatch = 0
137 141
138 142 lineno = 0
139 143 for line in pf:
@@ -150,11 +154,10 b' def readgitpatch(patchname):'
150 154 if line.startswith('--- '):
151 155 if gp.op in ('COPY', 'RENAME'):
152 156 gp.copymod = True
153 dopatch = 'filter'
157 dopatch |= GP_FILTER
154 158 gitpatches.append(gp)
155 159 gp = None
156 if not dopatch:
157 dopatch = True
160 dopatch |= GP_PATCH
158 161 continue
159 162 if line.startswith('rename from '):
160 163 gp.op = 'RENAME'
@@ -174,14 +177,13 b' def readgitpatch(patchname):'
174 177 elif line.startswith('new mode '):
175 178 gp.mode = int(line.rstrip()[-3:], 8)
176 179 elif line.startswith('GIT binary patch'):
177 if not dopatch:
178 dopatch = 'binary'
180 dopatch |= GP_BINARY
179 181 gp.binary = True
180 182 if gp:
181 183 gitpatches.append(gp)
182 184
183 185 if not gitpatches:
184 dopatch = True
186 dopatch = GP_PATCH
185 187
186 188 return (dopatch, gitpatches)
187 189
@@ -312,13 +314,14 b' def patch(patchname, ui, strip=1, cwd=No'
312 314
313 315 fuzz = False
314 316 if dopatch:
315 if dopatch in ('filter', 'binary'):
317 filterpatch = dopatch & (GP_FILTER | GP_BINARY)
318 if filterpatch:
316 319 patchname = dogitpatch(patchname, gitpatches, cwd=cwd)
317 320 try:
318 if dopatch != 'binary':
321 if dopatch & GP_PATCH:
319 322 fuzz = __patch(patchname)
320 323 finally:
321 if dopatch == 'filter':
324 if filterpatch:
322 325 os.unlink(patchname)
323 326
324 327 return fuzz
@@ -143,3 +143,22 b' hg locate rename2 rename3 rename3-2'
143 143 hg cat rename3
144 144 echo
145 145 hg cat rename3-2
146
147 echo foo > foo
148 hg add foo
149 hg ci -m 'add foo'
150 echo % binary files and regular patch hunks
151 hg import -m binaryregular - <<EOF
152 diff --git a/binary b/binary
153 new file mode 100644
154 index 0000000000000000000000000000000000000000..593f4708db84ac8fd0f5cc47c634f38c013fe9e4
155 GIT binary patch
156 literal 4
157 Lc\${NkU|;|M00aO5
158
159 diff --git a/foo b/foo2
160 rename from foo
161 rename to foo2
162 EOF
163 cat foo2
164 hg manifest | grep binary
@@ -54,3 +54,7 b' a'
54 54 b
55 55 c
56 56 a
57 % binary files and regular patch hunks
58 applying patch from stdin
59 foo
60 045c85ba38952325e126c70962cc0f9d9077bc67 644 binary
General Comments 0
You need to be logged in to leave comments. Login now