remotefilelog: use progress helper in fileserverclient
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 05 Dec 2018 09:30:01 -0800
changeset 53611 e58cd7ede1c3d21d2cb8216cf948abb3be6f660c
parent 53610 b6a6dc1a14bd0b51e5015d12b426aaa96e2cdcba
child 53612 b34b1b865ef953933ac92e651e7c72789411b188
push id1079
push usergszorc@mozilla.com
push dateMon, 10 Dec 2018 19:44:59 +0000
remotefilelog: use progress helper in fileserverclient Differential Revision: https://phab.mercurial-scm.org/D5381
hgext/remotefilelog/fileserverclient.py
--- a/hgext/remotefilelog/fileserverclient.py
+++ b/hgext/remotefilelog/fileserverclient.py
@@ -37,17 +37,16 @@ from . import (
 
 # Statistics for debugging
 fetchcost = 0
 fetches = 0
 fetched = 0
 fetchmisses = 0
 
 _lfsmod = None
-_downloading = _('downloading')
 
 def getcachekey(reponame, file, id):
     pathhash = node.hex(hashlib.sha1(file).digest())
     return os.path.join(reponame, pathhash[:2], pathhash[2:], id)
 
 def getlocalkey(file, id):
     pathhash = node.hex(hashlib.sha1(file).digest())
     return os.path.join(pathhash, id)
@@ -327,17 +326,18 @@ class fileserverclient(object):
             if self.cacheprocesspasspath:
                 request += file + '\0'
             request += fullid + "\n"
             idmap[fullid] = file
 
         cache.request(request)
 
         total = count
-        self.ui.progress(_downloading, 0, total=count)
+        progress = self.ui.makeprogress(_('downloading'), total=count)
+        progress.update(0)
 
         missed = []
         count = 0
         while True:
             missingid = cache.receiveline()
             if not missingid:
                 missedset = set(missed)
                 for missingid in idmap:
@@ -347,37 +347,37 @@ class fileserverclient(object):
                     "falling back to server\n"))
                 break
             if missingid == "0":
                 break
             if missingid.startswith("_hits_"):
                 # receive progress reports
                 parts = missingid.split("_")
                 count += int(parts[2])
-                self.ui.progress(_downloading, count, total=total)
+                progress.update(count)
                 continue
 
             missed.append(missingid)
 
         global fetchmisses
         fetchmisses += len(missed)
 
         count = [total - len(missed)]
         fromcache = count[0]
-        self.ui.progress(_downloading, count[0], total=total)
+        progress.update(count[0], total=total)
         self.ui.log("remotefilelog", "remote cache hit rate is %r of %r\n",
                     count[0], total, hit=count[0], total=total)
 
         oldumask = os.umask(0o002)
         try:
             # receive cache misses from master
             if missed:
                 def progresstick():
                     count[0] += 1
-                    self.ui.progress(_downloading, count[0], total=total)
+                    progress.update(count[0])
                 # When verbose is true, sshpeer prints 'running ssh...'
                 # to stdout, which can interfere with some command
                 # outputs
                 verbose = self.ui.verbose
                 self.ui.verbose = False
                 try:
                     with self._connect() as conn:
                         remote = conn.peer
@@ -422,17 +422,17 @@ class fileserverclient(object):
                     raise
                 finally:
                     self.ui.verbose = verbose
                 # send to memcache
                 count[0] = len(missed)
                 request = "set\n%d\n%s\n" % (count[0], "\n".join(missed))
                 cache.request(request)
 
-            self.ui.progress(_downloading, None)
+            progress.complete()
 
             # mark ourselves as a user of this cache
             writedata.markrepo(self.repo.path)
         finally:
             os.umask(oldumask)
 
     def receivemissing(self, pipe, filename, node):
         line = pipe.readline()[:-1]