largefiles: use progress helper
authorMartin von Zweigbergk <martinvonz@google.com>
Mon, 18 Jun 2018 15:14:39 -0700
changeset 38407 164306d3f4b4
parent 38406 65d1d7da63d1
child 38408 6540333acb95
largefiles: use progress helper Differential Revision: https://phab.mercurial-scm.org/D3808
hgext/largefiles/basestore.py
hgext/largefiles/lfcommands.py
hgext/largefiles/lfutil.py
--- a/hgext/largefiles/basestore.py	Mon Jun 18 15:05:52 2018 -0700
+++ b/hgext/largefiles/basestore.py	Mon Jun 18 15:14:39 2018 -0700
@@ -62,9 +62,10 @@
 
         at = 0
         available = self.exists(set(hash for (_filename, hash) in files))
+        progress = ui.makeprogress(_('getting largefiles'), unit=_('files'),
+                                   total=len(files))
         for filename, hash in files:
-            ui.progress(_('getting largefiles'), at, unit=_('files'),
-                total=len(files))
+            progress.update(at)
             at += 1
             ui.note(_('getting %s:%s\n') % (filename, hash))
 
@@ -79,7 +80,7 @@
             else:
                 missing.append(filename)
 
-        ui.progress(_('getting largefiles'), None)
+        progress.complete()
         return (success, missing)
 
     def _gethash(self, filename, hash):
--- a/hgext/largefiles/lfcommands.py	Mon Jun 18 15:05:52 2018 -0700
+++ b/hgext/largefiles/lfcommands.py	Mon Jun 18 15:14:39 2018 -0700
@@ -118,12 +118,14 @@
                 matcher = None
 
             lfiletohash = {}
+            progress = ui.makeprogress(_('converting revisions'),
+                                       unit=_('revisions'),
+                                       total=rsrc['tip'].rev())
             for ctx in ctxs:
-                ui.progress(_('converting revisions'), ctx.rev(),
-                    unit=_('revisions'), total=rsrc['tip'].rev())
+                progress.update(ctx.rev())
                 _lfconvert_addchangeset(rsrc, rdst, ctx, revmap,
                     lfiles, normalfiles, matcher, size, lfiletohash)
-            ui.progress(_('converting revisions'), None)
+            progress.complete()
 
             if rdst.wvfs.exists(lfutil.shortname):
                 rdst.wvfs.rmtree(lfutil.shortname)
@@ -368,9 +370,10 @@
     files = [h for h in files if not retval[h]]
     ui.debug("%d largefiles need to be uploaded\n" % len(files))
 
+    progress = ui.makeprogress(_('uploading largefiles'), unit=_('files'),
+                               total=len(files))
     for hash in files:
-        ui.progress(_('uploading largefiles'), at, unit=_('files'),
-                    total=len(files))
+        progress.update(at)
         source = lfutil.findfile(rsrc, hash)
         if not source:
             raise error.Abort(_('largefile %s missing from store'
@@ -378,7 +381,7 @@
         # XXX check for errors here
         store.put(source, hash)
         at += 1
-    ui.progress(_('uploading largefiles'), None)
+    progress.complete()
 
 def verifylfiles(ui, repo, all=False, contents=False):
     '''Verify that every largefile revision in the current changeset
--- a/hgext/largefiles/lfutil.py	Mon Jun 18 15:05:52 2018 -0700
+++ b/hgext/largefiles/lfutil.py	Mon Jun 18 15:14:39 2018 -0700
@@ -501,9 +501,10 @@
     return filelist
 
 def getlfilestoupload(repo, missing, addfunc):
+    progress = repo.ui.makeprogress(_('finding outgoing largefiles'),
+                                    unit=_('revisions'), total=len(missing))
     for i, n in enumerate(missing):
-        repo.ui.progress(_('finding outgoing largefiles'), i,
-            unit=_('revisions'), total=len(missing))
+        progress.update(i)
         parents = [p for p in repo[n].parents() if p != node.nullid]
 
         oldlfstatus = repo.lfstatus
@@ -530,7 +531,7 @@
         for fn in files:
             if isstandin(fn) and fn in ctx:
                 addfunc(fn, readasstandin(ctx[fn]))
-    repo.ui.progress(_('finding outgoing largefiles'), None)
+    progress.complete()
 
 def updatestandinsbymatch(repo, match):
     '''Update standins in the working directory according to specified match