Patchwork [2,of,4] lfs: use a context manager to control the progress bar lifetime

login
register
mail settings
Submitter Matt Harbison
Date Sept. 1, 2018, 6:05 a.m.
Message ID <f01ec535806db02e65db.1535781931@Envy>
Download mbox | patch
Permalink /patch/34231/
State Accepted
Headers show

Comments

Matt Harbison - Sept. 1, 2018, 6:05 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1535215318 14400
#      Sat Aug 25 12:41:58 2018 -0400
# Node ID f01ec535806db02e65db9845d80914de7663a1bd
# Parent  bcd44b97559a0150b988f812ffc28be1f7f9d452
lfs: use a context manager to control the progress bar lifetime

Patch

diff --git a/hgext/lfs/blobstore.py b/hgext/lfs/blobstore.py
--- a/hgext/lfs/blobstore.py
+++ b/hgext/lfs/blobstore.py
@@ -405,8 +405,7 @@  class _gitlfsremote(object):
         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 @@  class _gitlfsremote(object):
         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':
diff --git a/hgext/lfs/wrapper.py b/hgext/lfs/wrapper.py
--- a/hgext/lfs/wrapper.py
+++ b/hgext/lfs/wrapper.py
@@ -344,17 +344,14 @@  def extractpointers(repo, revs):
     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