diff hgext/largefiles/basestore.py @ 39390:a65ad9b22a00

largefiles: use a context manager to control the progress bar lifetime
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 25 Aug 2018 13:09:24 -0400
parents 164306d3f4b4
children 566daffc607d
line wrap: on
line diff
--- a/hgext/largefiles/basestore.py	Sat Aug 25 12:41:58 2018 -0400
+++ b/hgext/largefiles/basestore.py	Sat Aug 25 13:09:24 2018 -0400
@@ -62,25 +62,24 @@
 
         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:
-            progress.update(at)
-            at += 1
-            ui.note(_('getting %s:%s\n') % (filename, hash))
+        with ui.makeprogress(_('getting largefiles'), unit=_('files'),
+                             total=len(files)) as progress:
+            for filename, hash in files:
+                progress.update(at)
+                at += 1
+                ui.note(_('getting %s:%s\n') % (filename, hash))
 
-            if not available.get(hash):
-                ui.warn(_('%s: largefile %s not available from %s\n')
-                        % (filename, hash, util.hidepassword(self.url)))
-                missing.append(filename)
-                continue
+                if not available.get(hash):
+                    ui.warn(_('%s: largefile %s not available from %s\n')
+                            % (filename, hash, util.hidepassword(self.url)))
+                    missing.append(filename)
+                    continue
 
-            if self._gethash(filename, hash):
-                success.append((filename, hash))
-            else:
-                missing.append(filename)
+                if self._gethash(filename, hash):
+                    success.append((filename, hash))
+                else:
+                    missing.append(filename)
 
-        progress.complete()
         return (success, missing)
 
     def _gethash(self, filename, hash):