##// END OF EJS Templates
largefiles: use separate try/except and try/finally as needed for python2.4...
Thomas Arendsen Hein -
r15279:01860816 stable
parent child Browse files
Show More
@@ -320,14 +320,15 b' def override_copy(orig, ui, repo, pats, '
320 nonormalfiles = False
320 nonormalfiles = False
321 nolfiles = False
321 nolfiles = False
322 try:
322 try:
323 installnormalfilesmatchfn(repo[None].manifest())
323 try:
324 result = orig(ui, repo, pats, opts, rename)
324 installnormalfilesmatchfn(repo[None].manifest())
325 except util.Abort, e:
325 result = orig(ui, repo, pats, opts, rename)
326 if str(e) != 'no files to copy':
326 except util.Abort, e:
327 raise e
327 if str(e) != 'no files to copy':
328 else:
328 raise e
329 nonormalfiles = True
329 else:
330 result = 0
330 nonormalfiles = True
331 result = 0
331 finally:
332 finally:
332 restorematchfn()
333 restorematchfn()
333
334
@@ -339,80 +340,81 b' def override_copy(orig, ui, repo, pats, '
339 return result
340 return result
340
341
341 try:
342 try:
342 # When we call orig below it creates the standins but we don't add them
343 try:
343 # to the dir state until later so lock during that time.
344 # When we call orig below it creates the standins but we don't add them
344 wlock = repo.wlock()
345 # to the dir state until later so lock during that time.
346 wlock = repo.wlock()
345
347
346 manifest = repo[None].manifest()
348 manifest = repo[None].manifest()
347 oldmatch = None # for the closure
349 oldmatch = None # for the closure
348 def override_match(repo, pats=[], opts={}, globbed=False,
350 def override_match(repo, pats=[], opts={}, globbed=False,
349 default='relpath'):
351 default='relpath'):
350 newpats = []
352 newpats = []
351 # The patterns were previously mangled to add the standin
353 # The patterns were previously mangled to add the standin
352 # directory; we need to remove that now
354 # directory; we need to remove that now
355 for pat in pats:
356 if match_.patkind(pat) is None and lfutil.shortname in pat:
357 newpats.append(pat.replace(lfutil.shortname, ''))
358 else:
359 newpats.append(pat)
360 match = oldmatch(repo, newpats, opts, globbed, default)
361 m = copy.copy(match)
362 lfile = lambda f: lfutil.standin(f) in manifest
363 m._files = [lfutil.standin(f) for f in m._files if lfile(f)]
364 m._fmap = set(m._files)
365 orig_matchfn = m.matchfn
366 m.matchfn = lambda f: (lfutil.isstandin(f) and
367 lfile(lfutil.splitstandin(f)) and
368 orig_matchfn(lfutil.splitstandin(f)) or
369 None)
370 return m
371 oldmatch = installmatchfn(override_match)
372 listpats = []
353 for pat in pats:
373 for pat in pats:
354 if match_.patkind(pat) is None and lfutil.shortname in pat:
374 if match_.patkind(pat) is not None:
355 newpats.append(pat.replace(lfutil.shortname, ''))
375 listpats.append(pat)
356 else:
376 else:
357 newpats.append(pat)
377 listpats.append(makestandin(pat))
358 match = oldmatch(repo, newpats, opts, globbed, default)
359 m = copy.copy(match)
360 lfile = lambda f: lfutil.standin(f) in manifest
361 m._files = [lfutil.standin(f) for f in m._files if lfile(f)]
362 m._fmap = set(m._files)
363 orig_matchfn = m.matchfn
364 m.matchfn = lambda f: (lfutil.isstandin(f) and
365 lfile(lfutil.splitstandin(f)) and
366 orig_matchfn(lfutil.splitstandin(f)) or
367 None)
368 return m
369 oldmatch = installmatchfn(override_match)
370 listpats = []
371 for pat in pats:
372 if match_.patkind(pat) is not None:
373 listpats.append(pat)
374 else:
375 listpats.append(makestandin(pat))
376
378
377 try:
379 try:
378 origcopyfile = util.copyfile
380 origcopyfile = util.copyfile
379 copiedfiles = []
381 copiedfiles = []
380 def override_copyfile(src, dest):
382 def override_copyfile(src, dest):
381 if lfutil.shortname in src and lfutil.shortname in dest:
383 if lfutil.shortname in src and lfutil.shortname in dest:
382 destlfile = dest.replace(lfutil.shortname, '')
384 destlfile = dest.replace(lfutil.shortname, '')
383 if not opts['force'] and os.path.exists(destlfile):
385 if not opts['force'] and os.path.exists(destlfile):
384 raise IOError('',
386 raise IOError('',
385 _('destination largefile already exists'))
387 _('destination largefile already exists'))
386 copiedfiles.append((src, dest))
388 copiedfiles.append((src, dest))
387 origcopyfile(src, dest)
389 origcopyfile(src, dest)
388
390
389 util.copyfile = override_copyfile
391 util.copyfile = override_copyfile
390 result += orig(ui, repo, listpats, opts, rename)
392 result += orig(ui, repo, listpats, opts, rename)
391 finally:
393 finally:
392 util.copyfile = origcopyfile
394 util.copyfile = origcopyfile
393
395
394 lfdirstate = lfutil.openlfdirstate(ui, repo)
396 lfdirstate = lfutil.openlfdirstate(ui, repo)
395 for (src, dest) in copiedfiles:
397 for (src, dest) in copiedfiles:
396 if lfutil.shortname in src and lfutil.shortname in dest:
398 if lfutil.shortname in src and lfutil.shortname in dest:
397 srclfile = src.replace(lfutil.shortname, '')
399 srclfile = src.replace(lfutil.shortname, '')
398 destlfile = dest.replace(lfutil.shortname, '')
400 destlfile = dest.replace(lfutil.shortname, '')
399 destlfiledir = os.path.dirname(destlfile) or '.'
401 destlfiledir = os.path.dirname(destlfile) or '.'
400 if not os.path.isdir(destlfiledir):
402 if not os.path.isdir(destlfiledir):
401 os.makedirs(destlfiledir)
403 os.makedirs(destlfiledir)
402 if rename:
404 if rename:
403 os.rename(srclfile, destlfile)
405 os.rename(srclfile, destlfile)
404 lfdirstate.remove(os.path.relpath(srclfile,
406 lfdirstate.remove(os.path.relpath(srclfile,
407 repo.root))
408 else:
409 util.copyfile(srclfile, destlfile)
410 lfdirstate.add(os.path.relpath(destlfile,
405 repo.root))
411 repo.root))
406 else:
412 lfdirstate.write()
407 util.copyfile(srclfile, destlfile)
413 except util.Abort, e:
408 lfdirstate.add(os.path.relpath(destlfile,
414 if str(e) != 'no files to copy':
409 repo.root))
415 raise e
410 lfdirstate.write()
416 else:
411 except util.Abort, e:
417 nolfiles = True
412 if str(e) != 'no files to copy':
413 raise e
414 else:
415 nolfiles = True
416 finally:
418 finally:
417 restorematchfn()
419 restorematchfn()
418 wlock.release()
420 wlock.release()
General Comments 0
You need to be logged in to leave comments. Login now