# HG changeset patch # User Martin von Zweigbergk # Date 1529301454 25200 # Node ID 63e6f5ae84bc6f1c0898cfb68b45b4b7e852cee2 # Parent 3a7c33a2cc5e8e909bc6c27fe8a31a6fc0ee8d78 copystore: use progress helper Differential Revision: https://phab.mercurial-scm.org/D3781 diff -r 3a7c33a2cc5e -r 63e6f5ae84bc mercurial/hg.py --- a/mercurial/hg.py Sun Jun 17 22:09:15 2018 -0700 +++ b/mercurial/hg.py Sun Jun 17 22:57:34 2018 -0700 @@ -372,13 +372,9 @@ destlock = None try: hardlink = None + topic = _('linking') if hardlink else _('copying') + progress = ui.makeprogress(topic) num = 0 - closetopic = [None] - def prog(topic, pos): - if pos is None: - closetopic[0] = topic - else: - ui.progress(topic, pos + num) srcpublishing = srcrepo.publishing() srcvfs = vfsmod.vfs(srcrepo.sharedpath) dstvfs = vfsmod.vfs(destpath) @@ -395,16 +391,13 @@ # lock to avoid premature writing to the target destlock = lock.lock(dstvfs, lockfile) hardlink, n = util.copyfiles(srcvfs.join(f), dstvfs.join(f), - hardlink, progress=prog) + hardlink, progress) num += n if hardlink: ui.debug("linked %d files\n" % num) - if closetopic[0]: - ui.progress(closetopic[0], None) else: ui.debug("copied %d files\n" % num) - if closetopic[0]: - ui.progress(closetopic[0], None) + progress.complete() return destlock except: # re-raises release(destlock) diff -r 3a7c33a2cc5e -r 63e6f5ae84bc mercurial/util.py --- a/mercurial/util.py Sun Jun 17 22:09:15 2018 -0700 +++ b/mercurial/util.py Sun Jun 17 22:57:34 2018 -0700 @@ -1631,31 +1631,30 @@ except shutil.Error as inst: raise error.Abort(str(inst)) -def copyfiles(src, dst, hardlink=None, progress=lambda t, pos: None): +def copyfiles(src, dst, hardlink=None, progress=None): """Copy a directory tree using hardlinks if possible.""" num = 0 - gettopic = lambda: hardlink and _('linking') or _('copying') + def settopic(): + if progress: + progress.topic = _('linking') if hardlink else _('copying') if os.path.isdir(src): if hardlink is None: hardlink = (os.stat(src).st_dev == os.stat(os.path.dirname(dst)).st_dev) - topic = gettopic() + settopic() os.mkdir(dst) for name, kind in listdir(src): srcname = os.path.join(src, name) dstname = os.path.join(dst, name) - def nprog(t, pos): - if pos is not None: - return progress(t, pos + num) - hardlink, n = copyfiles(srcname, dstname, hardlink, progress=nprog) + hardlink, n = copyfiles(srcname, dstname, hardlink, progress) num += n else: if hardlink is None: hardlink = (os.stat(os.path.dirname(src)).st_dev == os.stat(os.path.dirname(dst)).st_dev) - topic = gettopic() + settopic() if hardlink: try: @@ -1666,8 +1665,8 @@ else: shutil.copy(src, dst) num += 1 - progress(topic, num) - progress(topic, None) + if progress: + progress.increment() return hardlink, num