D3781: copystore: use progress helper

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Mon Jun 18 10:24:55 EDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG63e6f5ae84bc: copystore: use progress helper (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3781?vs=9152&id=9185

REVISION DETAIL
  https://phab.mercurial-scm.org/D3781

AFFECTED FILES
  mercurial/hg.py
  mercurial/util.py

CHANGE DETAILS

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -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
 
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -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)



To: martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list