remotefilelog: use progress helper in basestore
authorMartin von Zweigbergk <martinvonz@google.com>
Tue, 04 Dec 2018 16:09:20 -0800
changeset 53606 ad21fbcb1ba5c819925b1c17c9137ec2ad725381
parent 53605 05afb32e93809d983dbb1e89cec50938a9d59dc0
child 53607 fbd053af2eda078a0f53aea5af86db1b438da375
push id1079
push usergszorc@mozilla.com
push dateMon, 10 Dec 2018 19:44:59 +0000
remotefilelog: use progress helper in basestore Differential Revision: https://phab.mercurial-scm.org/D5376
hgext/remotefilelog/basestore.py
--- a/hgext/remotefilelog/basestore.py
+++ b/hgext/remotefilelog/basestore.py
@@ -72,24 +72,25 @@ class basestore(object):
                 for node in nodes:
                     ledger.markdataentry(self, filename, node)
                     ledger.markhistoryentry(self, filename, node)
 
     def cleanup(self, ledger):
         ui = self.ui
         entries = ledger.sources.get(self, [])
         count = 0
+        progress = ui.makeprogress(_("cleaning up"), unit="files",
+                                   total=len(entries))
         for entry in entries:
             if entry.gced or (entry.datarepacked and entry.historyrepacked):
-                ui.progress(_("cleaning up"), count, unit="files",
-                            total=len(entries))
+                progress.update(count)
                 path = self._getfilepath(entry.filename, entry.node)
                 util.tryunlink(path)
             count += 1
-        ui.progress(_("cleaning up"), None)
+        progress.complete()
 
         # Clean up the repo cache directory.
         self._cleanupdirectory(self._getrepocachepath())
 
     # BELOW THIS ARE NON-STANDARD APIS
 
     def _cleanupdirectory(self, rootdir):
         """Removes the empty directories and unnecessary files within the root
@@ -297,41 +298,41 @@ class basestore(object):
         except (ValueError, RuntimeError):
             pass
 
         return False
 
     def gc(self, keepkeys):
         ui = self.ui
         cachepath = self._path
-        _removing = _("removing unnecessary files")
-        _truncating = _("enforcing cache limit")
 
         # prune cache
         import Queue
         queue = Queue.PriorityQueue()
         originalsize = 0
         size = 0
         count = 0
         removed = 0
 
         # keep files newer than a day even if they aren't needed
         limit = time.time() - (60 * 60 * 24)
 
-        ui.progress(_removing, count, unit="files")
+        progress = ui.makeprogress(_("removing unnecessary files"),
+                                   unit="files")
+        progress.update(0)
         for root, dirs, files in os.walk(cachepath):
             for file in files:
                 if file == 'repos':
                     continue
 
                 # Don't delete pack files
                 if '/packs/' in root:
                     continue
 
-                ui.progress(_removing, count, unit="files")
+                progress.update(count)
                 path = os.path.join(root, file)
                 key = os.path.relpath(path, cachepath)
                 count += 1
                 try:
                     pathstat = os.stat(path)
                 except OSError as e:
                     # errno.ENOENT = no such file or directory
                     if e.errno != errno.ENOENT:
@@ -352,39 +353,40 @@ class basestore(object):
                         # errno.ENOENT = no such file or directory
                         if e.errno != errno.ENOENT:
                             raise
                         msg = _("warning: file %s was removed by another "
                                 "process\n")
                         ui.warn(msg % path)
                         continue
                     removed += 1
-        ui.progress(_removing, None)
+        progress.complete()
 
         # remove oldest files until under limit
         limit = ui.configbytes("remotefilelog", "cachelimit")
         if size > limit:
             excess = size - limit
+            progress = ui.makeprogress(_("enforcing cache limit"), unit="bytes",
+                                       total=excess)
             removedexcess = 0
             while queue and size > limit and size > 0:
-                ui.progress(_truncating, removedexcess, unit="bytes",
-                            total=excess)
+                progress.update(removedexcess)
                 atime, oldpath, oldpathstat = queue.get()
                 try:
                     shallowutil.unlinkfile(oldpath)
                 except OSError as e:
                     # errno.ENOENT = no such file or directory
                     if e.errno != errno.ENOENT:
                         raise
                     msg = _("warning: file %s was removed by another process\n")
                     ui.warn(msg % oldpath)
                 size -= oldpathstat.st_size
                 removed += 1
                 removedexcess += oldpathstat.st_size
-        ui.progress(_truncating, None)
+            progress.complete()
 
         ui.status(_("finished: removed %s of %s files (%0.2f GB to %0.2f GB)\n")
                   % (removed, count,
                      float(originalsize) / 1024.0 / 1024.0 / 1024.0,
                      float(size) / 1024.0 / 1024.0 / 1024.0))
 
 class baseunionstore(object):
     def __init__(self, *args, **kwargs):