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