comparison fetch_command.py @ 109:460443a96497

fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
author Patrick Mezard <pmezard@gmail.com>
date Tue, 25 Nov 2008 09:18:29 -0600
parents de19a13edfa8
children a4dcffaa6538
comparison
equal deleted inserted replaced
108:de19a13edfa8 109:460443a96497
175 def stupid_diff_branchrev(ui, svn, hg_editor, branch, r, parentid, tempdir): 175 def stupid_diff_branchrev(ui, svn, hg_editor, branch, r, parentid, tempdir):
176 """Extract all 'branch' content at a given revision. 176 """Extract all 'branch' content at a given revision.
177 177
178 Return a tuple (files, filectxfn) where 'files' is the list of all files 178 Return a tuple (files, filectxfn) where 'files' is the list of all files
179 in the branch at the given revision, and 'filectxfn' is a memctx compatible 179 in the branch at the given revision, and 'filectxfn' is a memctx compatible
180 callable to retrieve individual file information. 180 callable to retrieve individual file information. Raise BadPatchApply upon
181 error.
181 """ 182 """
182 def make_diff_path(b): 183 def make_diff_path(b):
183 if b == None: 184 if b == None:
184 return 'trunk' 185 return 'trunk'
185 return 'branches/' + b 186 return 'branches/' + b
186 187
187 parent_rev, br_p = hg_editor.get_parent_svn_branch_and_rev(r.revnum, branch) 188 parent_rev, br_p = hg_editor.get_parent_svn_branch_and_rev(r.revnum, branch)
188 diff_path = make_diff_path(branch) 189 diff_path = make_diff_path(branch)
189 files_touched = set() 190 files_touched = set()
190 if br_p == branch: 191 try:
191 # letting patch handle binaries sounded 192 if br_p == branch:
192 # cool, but it breaks patch in sad ways 193 # letting patch handle binaries sounded
193 d = svn.get_unified_diff(diff_path, r.revnum, deleted=False, 194 # cool, but it breaks patch in sad ways
194 ignore_type=False) 195 d = svn.get_unified_diff(diff_path, r.revnum, deleted=False,
195 else: 196 ignore_type=False)
196 d = svn.get_unified_diff(diff_path, r.revnum, 197 else:
197 other_path=make_diff_path(br_p), 198 d = svn.get_unified_diff(diff_path, r.revnum,
198 other_rev=parent_rev, 199 other_path=make_diff_path(br_p),
199 deleted=True, ignore_type=True) 200 other_rev=parent_rev,
200 if d: 201 deleted=True, ignore_type=True)
201 ui.status('Branch creation with mods, pulling full rev.\n') 202 if d:
202 raise BadPatchApply() 203 raise BadPatchApply('branch creation with mods')
204 except svnwrap.SubversionRepoCanNotDiff:
205 raise BadPatchApply('subversion diffing code is not supported')
206 except core.SubversionException, e:
207 if (hasattr(e, 'apr_err') and e.apr_err != 160013):
208 raise
209 raise BadPatchApply('previous revision does not exist')
203 opener = merc_util.opener(tempdir) 210 opener = merc_util.opener(tempdir)
204 for m in binary_file_re.findall(d): 211 for m in binary_file_re.findall(d):
205 # we have to pull each binary file by hand as a fulltext, 212 # we have to pull each binary file by hand as a fulltext,
206 # which sucks but we've got no choice 213 # which sucks but we've got no choice
207 files_touched.add(m) 214 files_touched.add(m)
237 # TODO: this happens if the svn server has the wrong mime 244 # TODO: this happens if the svn server has the wrong mime
238 # type stored and doesn't know a file is binary. It would 245 # type stored and doesn't know a file is binary. It would
239 # be better to do one file at a time and only do a 246 # be better to do one file at a time and only do a
240 # full fetch on files that had problems. 247 # full fetch on files that had problems.
241 os.chdir(old_cwd) 248 os.chdir(old_cwd)
242 raise BadPatchApply() 249 raise BadPatchApply('patching failed')
243 for x in changed.iterkeys(): 250 for x in changed.iterkeys():
244 ui.status('M %s\n' % x) 251 ui.status('M %s\n' % x)
245 files_touched.add(x) 252 files_touched.add(x)
246 os.chdir(old_cwd) 253 os.chdir(old_cwd)
247 # if this patch didn't apply right, fall back to exporting the 254 # if this patch didn't apply right, fall back to exporting the
253 if (fn in parent_manifest and 260 if (fn in parent_manifest and
254 'l' in parent_ctx.filectx(fn).flags()): 261 'l' in parent_ctx.filectx(fn).flags()):
255 # I think this might be an underlying bug in svn - 262 # I think this might be an underlying bug in svn -
256 # I get diffs of deleted symlinks even though I 263 # I get diffs of deleted symlinks even though I
257 # specifically said no deletes above. 264 # specifically said no deletes above.
258 ui.status('Pulling whole rev because of a deleted' 265 raise BadPatchApply('deleted symlinked prevent patching')
259 'symlink')
260 raise BadPatchApply()
261 assert False, ('This should only happen on case-insensitive' 266 assert False, ('This should only happen on case-insensitive'
262 ' volumes.') 267 ' volumes.')
263 elif patch_st == 1: 268 elif patch_st == 1:
264 # When converting Django, I saw fuzz on .po files that was 269 # When converting Django, I saw fuzz on .po files that was
265 # causing revisions to end up failing verification. If that 270 # causing revisions to end up failing verification. If that
266 # can be fixed, maybe this won't ever be reached. 271 # can be fixed, maybe this won't ever be reached.
267 ui.status('There was some fuzz, not using diff after all.') 272 raise BadPatchApply('patching succeeded with fuzz')
268 raise BadPatchApply()
269 else: 273 else:
270 ui.status('Not using patch for %s, diff had no hunks.\n' % 274 ui.status('Not using patch for %s, diff had no hunks.\n' %
271 r.revnum) 275 r.revnum)
272 276
273 # we create the files if they don't exist here because we know 277 # we create the files if they don't exist here because we know
493 our_tempdir = tempfile.mkdtemp('svn_fetch_temp', dir=temp_location) 497 our_tempdir = tempfile.mkdtemp('svn_fetch_temp', dir=temp_location)
494 parent_ha = hg_editor.get_parent_revision(r.revnum, b) 498 parent_ha = hg_editor.get_parent_revision(r.revnum, b)
495 try: 499 try:
496 files_touched, filectxfn = stupid_diff_branchrev( 500 files_touched, filectxfn = stupid_diff_branchrev(
497 ui, svn, hg_editor, b, r, parent_ha, our_tempdir) 501 ui, svn, hg_editor, b, r, parent_ha, our_tempdir)
498 except (core.SubversionException, 502 except BadPatchApply, e:
499 BadPatchApply,
500 svnwrap.SubversionRepoCanNotDiff), e:
501 if (hasattr(e, 'apr_err') and e.apr_err != 160013):
502 raise
503 # Either this revision or the previous one does not exist. 503 # Either this revision or the previous one does not exist.
504 ui.status("fetching entire rev previous rev does not exist.\n") 504 ui.status("fetching entire rev: %s.\n" % e.message)
505 files_touched, filectxfn = stupid_fetch_branchrev( 505 files_touched, filectxfn = stupid_fetch_branchrev(
506 svn, hg_editor, b, branches[b], r, parent_ha) 506 svn, hg_editor, b, branches[b], r, parent_ha)
507 507
508 date = r.date.replace('T', ' ').replace('Z', '').split('.')[0] 508 date = r.date.replace('T', ' ').replace('Z', '').split('.')[0]
509 date += ' -0000' 509 date += ' -0000'