Mercurial > public > mercurial-scm > hg-stable
diff mercurial/util.py @ 38386:63e6f5ae84bc
copystore: use progress helper
Differential Revision: https://phab.mercurial-scm.org/D3781
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Sun, 17 Jun 2018 22:57:34 -0700 |
parents | 565074cc9ac6 |
children | da2a7d8354b2 |
line wrap: on
line diff
--- 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