##// END OF EJS Templates
copystore: use progress helper...
Martin von Zweigbergk -
r38399:63e6f5ae default
parent child Browse files
Show More
@@ -372,13 +372,9 b' def copystore(ui, srcrepo, destpath):'
372 destlock = None
372 destlock = None
373 try:
373 try:
374 hardlink = None
374 hardlink = None
375 topic = _('linking') if hardlink else _('copying')
376 progress = ui.makeprogress(topic)
375 num = 0
377 num = 0
376 closetopic = [None]
377 def prog(topic, pos):
378 if pos is None:
379 closetopic[0] = topic
380 else:
381 ui.progress(topic, pos + num)
382 srcpublishing = srcrepo.publishing()
378 srcpublishing = srcrepo.publishing()
383 srcvfs = vfsmod.vfs(srcrepo.sharedpath)
379 srcvfs = vfsmod.vfs(srcrepo.sharedpath)
384 dstvfs = vfsmod.vfs(destpath)
380 dstvfs = vfsmod.vfs(destpath)
@@ -395,16 +391,13 b' def copystore(ui, srcrepo, destpath):'
395 # lock to avoid premature writing to the target
391 # lock to avoid premature writing to the target
396 destlock = lock.lock(dstvfs, lockfile)
392 destlock = lock.lock(dstvfs, lockfile)
397 hardlink, n = util.copyfiles(srcvfs.join(f), dstvfs.join(f),
393 hardlink, n = util.copyfiles(srcvfs.join(f), dstvfs.join(f),
398 hardlink, progress=prog)
394 hardlink, progress)
399 num += n
395 num += n
400 if hardlink:
396 if hardlink:
401 ui.debug("linked %d files\n" % num)
397 ui.debug("linked %d files\n" % num)
402 if closetopic[0]:
403 ui.progress(closetopic[0], None)
404 else:
398 else:
405 ui.debug("copied %d files\n" % num)
399 ui.debug("copied %d files\n" % num)
406 if closetopic[0]:
400 progress.complete()
407 ui.progress(closetopic[0], None)
408 return destlock
401 return destlock
409 except: # re-raises
402 except: # re-raises
410 release(destlock)
403 release(destlock)
@@ -1631,31 +1631,30 b' def copyfile(src, dest, hardlink=False, '
1631 except shutil.Error as inst:
1631 except shutil.Error as inst:
1632 raise error.Abort(str(inst))
1632 raise error.Abort(str(inst))
1633
1633
1634 def copyfiles(src, dst, hardlink=None, progress=lambda t, pos: None):
1634 def copyfiles(src, dst, hardlink=None, progress=None):
1635 """Copy a directory tree using hardlinks if possible."""
1635 """Copy a directory tree using hardlinks if possible."""
1636 num = 0
1636 num = 0
1637
1637
1638 gettopic = lambda: hardlink and _('linking') or _('copying')
1638 def settopic():
1639 if progress:
1640 progress.topic = _('linking') if hardlink else _('copying')
1639
1641
1640 if os.path.isdir(src):
1642 if os.path.isdir(src):
1641 if hardlink is None:
1643 if hardlink is None:
1642 hardlink = (os.stat(src).st_dev ==
1644 hardlink = (os.stat(src).st_dev ==
1643 os.stat(os.path.dirname(dst)).st_dev)
1645 os.stat(os.path.dirname(dst)).st_dev)
1644 topic = gettopic()
1646 settopic()
1645 os.mkdir(dst)
1647 os.mkdir(dst)
1646 for name, kind in listdir(src):
1648 for name, kind in listdir(src):
1647 srcname = os.path.join(src, name)
1649 srcname = os.path.join(src, name)
1648 dstname = os.path.join(dst, name)
1650 dstname = os.path.join(dst, name)
1649 def nprog(t, pos):
1651 hardlink, n = copyfiles(srcname, dstname, hardlink, progress)
1650 if pos is not None:
1651 return progress(t, pos + num)
1652 hardlink, n = copyfiles(srcname, dstname, hardlink, progress=nprog)
1653 num += n
1652 num += n
1654 else:
1653 else:
1655 if hardlink is None:
1654 if hardlink is None:
1656 hardlink = (os.stat(os.path.dirname(src)).st_dev ==
1655 hardlink = (os.stat(os.path.dirname(src)).st_dev ==
1657 os.stat(os.path.dirname(dst)).st_dev)
1656 os.stat(os.path.dirname(dst)).st_dev)
1658 topic = gettopic()
1657 settopic()
1659
1658
1660 if hardlink:
1659 if hardlink:
1661 try:
1660 try:
@@ -1666,8 +1665,8 b' def copyfiles(src, dst, hardlink=None, p'
1666 else:
1665 else:
1667 shutil.copy(src, dst)
1666 shutil.copy(src, dst)
1668 num += 1
1667 num += 1
1669 progress(topic, num)
1668 if progress:
1670 progress(topic, None)
1669 progress.increment()
1671
1670
1672 return hardlink, num
1671 return hardlink, num
1673
1672
General Comments 0
You need to be logged in to leave comments. Login now