D3805: relink: use progress helper

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Tue Jun 19 00:45:07 UTC 2018


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This doesn't use progress.increment() because progress output is
  skipped for some positions (so we may end up calling "update(0),
  update(2), update(7)", or similar).

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/relink.py

CHANGE DETAILS

diff --git a/hgext/relink.py b/hgext/relink.py
--- a/hgext/relink.py
+++ b/hgext/relink.py
@@ -94,6 +94,7 @@
     # mozilla-central as of 2010-06-10 had a ratio of just over 7:5.
     total = live * 3 // 2
     src = src.store.path
+    progress = ui.makeprogress(_('collecting'), unit=_('files'), total=total)
     pos = 0
     ui.status(_("tip has %d files, estimated total number of files: %d\n")
               % (live, total))
@@ -108,9 +109,9 @@
                 continue
             pos += 1
             candidates.append((os.path.join(relpath, filename), st))
-            ui.progress(_('collecting'), pos, filename, _('files'), total)
+            progress.update(pos, item=filename)
 
-    ui.progress(_('collecting'), None)
+    progress.complete()
     ui.status(_('collected %d candidate storage files\n') % len(candidates))
     return candidates
 
@@ -132,7 +133,8 @@
         return st
 
     targets = []
-    total = len(candidates)
+    progress = ui.makeprogress(_('pruning'), unit=_('files'),
+                               total=len(candidates))
     pos = 0
     for fn, st in candidates:
         pos += 1
@@ -143,9 +145,9 @@
             ui.debug('not linkable: %s\n' % fn)
             continue
         targets.append((fn, ts.st_size))
-        ui.progress(_('pruning'), pos, fn, _('files'), total)
+        progress.update(pos, item=fn)
 
-    ui.progress(_('pruning'), None)
+    progress.complete()
     ui.status(_('pruned down to %d probably relinkable files\n') % len(targets))
     return targets
 
@@ -164,8 +166,9 @@
     relinked = 0
     savedbytes = 0
 
+    progress = ui.makeprogress(_('relinking'), unit=_('files'),
+                               total=len(files))
     pos = 0
-    total = len(files)
     for f, sz in files:
         pos += 1
         source = os.path.join(src, f)
@@ -186,13 +189,13 @@
             continue
         try:
             relinkfile(source, tgt)
-            ui.progress(_('relinking'), pos, f, _('files'), total)
+            progress.update(pos, item=f)
             relinked += 1
             savedbytes += sz
         except OSError as inst:
             ui.warn('%s: %s\n' % (tgt, stringutil.forcebytestr(inst)))
 
-    ui.progress(_('relinking'), None)
+    progress.complete()
 
     ui.status(_('relinked %d files (%s reclaimed)\n') %
               (relinked, util.bytecount(savedbytes)))



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


More information about the Mercurial-devel mailing list