# HG changeset patch # User Augie Fackler # Date 2015-03-19 14:24:22 # Node ID 2ddfac2f163e1f287c65732273936d121ab694b2 # Parent 5b85a5bc5bbb9d8365953609d98e4dce7110e9b0 util: add progress callback support to copyfiles diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -739,20 +739,27 @@ def copyfile(src, dest, hardlink=False): except shutil.Error, inst: raise Abort(str(inst)) -def copyfiles(src, dst, hardlink=None): - """Copy a directory tree using hardlinks if possible""" +def copyfiles(src, dst, hardlink=None, progress=lambda t, pos: None): + """Copy a directory tree using hardlinks if possible.""" + num = 0 if hardlink is None: hardlink = (os.stat(src).st_dev == os.stat(os.path.dirname(dst)).st_dev) + if hardlink: + topic = _('linking') + else: + topic = _('copying') - num = 0 if os.path.isdir(src): os.mkdir(dst) for name, kind in osutil.listdir(src): srcname = os.path.join(src, name) dstname = os.path.join(dst, name) - hardlink, n = copyfiles(srcname, dstname, hardlink) + def nprog(t, pos): + if pos is not None: + return progress(t, pos + num) + hardlink, n = copyfiles(srcname, dstname, hardlink, progress=nprog) num += n else: if hardlink: @@ -764,6 +771,8 @@ def copyfiles(src, dst, hardlink=None): else: shutil.copy(src, dst) num += 1 + progress(topic, num) + progress(topic, None) return hardlink, num