##// 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 320 nonormalfiles = False
321 321 nolfiles = False
322 322 try:
323 installnormalfilesmatchfn(repo[None].manifest())
324 result = orig(ui, repo, pats, opts, rename)
325 except util.Abort, e:
326 if str(e) != 'no files to copy':
327 raise e
328 else:
329 nonormalfiles = True
330 result = 0
323 try:
324 installnormalfilesmatchfn(repo[None].manifest())
325 result = orig(ui, repo, pats, opts, rename)
326 except util.Abort, e:
327 if str(e) != 'no files to copy':
328 raise e
329 else:
330 nonormalfiles = True
331 result = 0
331 332 finally:
332 333 restorematchfn()
333 334
@@ -339,80 +340,81 b' def override_copy(orig, ui, repo, pats, '
339 340 return result
340 341
341 342 try:
342 # When we call orig below it creates the standins but we don't add them
343 # to the dir state until later so lock during that time.
344 wlock = repo.wlock()
343 try:
344 # When we call orig below it creates the standins but we don't add them
345 # to the dir state until later so lock during that time.
346 wlock = repo.wlock()
345 347
346 manifest = repo[None].manifest()
347 oldmatch = None # for the closure
348 def override_match(repo, pats=[], opts={}, globbed=False,
349 default='relpath'):
350 newpats = []
351 # The patterns were previously mangled to add the standin
352 # directory; we need to remove that now
348 manifest = repo[None].manifest()
349 oldmatch = None # for the closure
350 def override_match(repo, pats=[], opts={}, globbed=False,
351 default='relpath'):
352 newpats = []
353 # The patterns were previously mangled to add the standin
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 373 for pat in pats:
354 if match_.patkind(pat) is None and lfutil.shortname in pat:
355 newpats.append(pat.replace(lfutil.shortname, ''))
374 if match_.patkind(pat) is not None:
375 listpats.append(pat)
356 376 else:
357 newpats.append(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))
377 listpats.append(makestandin(pat))
376 378
377 try:
378 origcopyfile = util.copyfile
379 copiedfiles = []
380 def override_copyfile(src, dest):
381 if lfutil.shortname in src and lfutil.shortname in dest:
382 destlfile = dest.replace(lfutil.shortname, '')
383 if not opts['force'] and os.path.exists(destlfile):
384 raise IOError('',
385 _('destination largefile already exists'))
386 copiedfiles.append((src, dest))
387 origcopyfile(src, dest)
379 try:
380 origcopyfile = util.copyfile
381 copiedfiles = []
382 def override_copyfile(src, dest):
383 if lfutil.shortname in src and lfutil.shortname in dest:
384 destlfile = dest.replace(lfutil.shortname, '')
385 if not opts['force'] and os.path.exists(destlfile):
386 raise IOError('',
387 _('destination largefile already exists'))
388 copiedfiles.append((src, dest))
389 origcopyfile(src, dest)
388 390
389 util.copyfile = override_copyfile
390 result += orig(ui, repo, listpats, opts, rename)
391 finally:
392 util.copyfile = origcopyfile
391 util.copyfile = override_copyfile
392 result += orig(ui, repo, listpats, opts, rename)
393 finally:
394 util.copyfile = origcopyfile
393 395
394 lfdirstate = lfutil.openlfdirstate(ui, repo)
395 for (src, dest) in copiedfiles:
396 if lfutil.shortname in src and lfutil.shortname in dest:
397 srclfile = src.replace(lfutil.shortname, '')
398 destlfile = dest.replace(lfutil.shortname, '')
399 destlfiledir = os.path.dirname(destlfile) or '.'
400 if not os.path.isdir(destlfiledir):
401 os.makedirs(destlfiledir)
402 if rename:
403 os.rename(srclfile, destlfile)
404 lfdirstate.remove(os.path.relpath(srclfile,
396 lfdirstate = lfutil.openlfdirstate(ui, repo)
397 for (src, dest) in copiedfiles:
398 if lfutil.shortname in src and lfutil.shortname in dest:
399 srclfile = src.replace(lfutil.shortname, '')
400 destlfile = dest.replace(lfutil.shortname, '')
401 destlfiledir = os.path.dirname(destlfile) or '.'
402 if not os.path.isdir(destlfiledir):
403 os.makedirs(destlfiledir)
404 if rename:
405 os.rename(srclfile, destlfile)
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 411 repo.root))
406 else:
407 util.copyfile(srclfile, destlfile)
408 lfdirstate.add(os.path.relpath(destlfile,
409 repo.root))
410 lfdirstate.write()
411 except util.Abort, e:
412 if str(e) != 'no files to copy':
413 raise e
414 else:
415 nolfiles = True
412 lfdirstate.write()
413 except util.Abort, e:
414 if str(e) != 'no files to copy':
415 raise e
416 else:
417 nolfiles = True
416 418 finally:
417 419 restorematchfn()
418 420 wlock.release()
General Comments 0
You need to be logged in to leave comments. Login now