changeset 39389:b26350d9d7b5

lfs: use a context manager to control the progress bar lifetime
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 25 Aug 2018 12:41:58 -0400
parents ddfd80029306
children a65ad9b22a00
files hgext/lfs/blobstore.py hgext/lfs/wrapper.py
diffstat 2 files changed, 12 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/lfs/blobstore.py	Sat Aug 25 12:26:44 2018 -0400
+++ b/hgext/lfs/blobstore.py	Sat Aug 25 12:41:58 2018 -0400
@@ -405,8 +405,7 @@
         if len(objects) > 1:
             self.ui.note(_('lfs: need to transfer %d objects (%s)\n')
                          % (len(objects), util.bytecount(total)))
-        progress = self.ui.makeprogress(topic, total=total)
-        progress.update(0)
+
         def transfer(chunk):
             for obj in chunk:
                 objsize = obj.get('size', 0)
@@ -439,14 +438,15 @@
         else:
             oids = transfer(sorted(objects, key=lambda o: o.get('oid')))
 
-        processed = 0
-        blobs = 0
-        for _one, oid in oids:
-            processed += sizes[oid]
-            blobs += 1
-            progress.update(processed)
-            self.ui.note(_('lfs: processed: %s\n') % oid)
-        progress.complete()
+        with self.ui.makeprogress(topic, total=total) as progress:
+            progress.update(0)
+            processed = 0
+            blobs = 0
+            for _one, oid in oids:
+                processed += sizes[oid]
+                blobs += 1
+                progress.update(processed)
+                self.ui.note(_('lfs: processed: %s\n') % oid)
 
         if blobs > 0:
             if action == 'upload':
--- a/hgext/lfs/wrapper.py	Sat Aug 25 12:26:44 2018 -0400
+++ b/hgext/lfs/wrapper.py	Sat Aug 25 12:41:58 2018 -0400
@@ -344,17 +344,14 @@
     repo.ui.debug('lfs: computing set of blobs to upload\n')
     pointers = {}
 
-    progress = repo.ui.makeprogress(_('lfs search'), _('changesets'), len(revs))
-
-    try:
+    makeprogress = repo.ui.makeprogress
+    with makeprogress(_('lfs search'), _('changesets'), len(revs)) as progress:
         for r in revs:
             ctx = repo[r]
             for p in pointersfromctx(ctx).values():
                 pointers[p.oid()] = p
             progress.increment()
         return sorted(pointers.values())
-    finally:
-        progress.complete()
 
 def pointerfromctx(ctx, f, removed=False):
     """return a pointer for the named file from the given changectx, or None if