Patchwork D7134: phabricator: use context manager form of progress in uploadchunks

login
register
mail settings
Submitter phabricator
Date Oct. 18, 2019, 6:21 a.m.
Message ID <differential-rev-PHID-DREV-wdyi2zchtpghbbyxoime-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/42470/
State Superseded
Headers show

Comments

phabricator - Oct. 18, 2019, 6:21 a.m.
Kwan created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Follow-up to 453079605242 <https://phab.mercurial-scm.org/rHG4530796052427266c945b129de1a17b1539783fe> / D7046 <https://phab.mercurial-scm.org/D7046>.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D7134

AFFECTED FILES
  hgext/phabricator.py

CHANGE DETAILS




To: Kwan, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -609,26 +609,25 @@ 
     """
     ui = fctx.repo().ui
     chunks = callconduit(ui, b'file.querychunks', {b'filePHID': fphid})
-    progress = ui.makeprogress(
+    with ui.makeprogress(
         _(b'uploading file chunks'), unit=_(b'chunks'), total=len(chunks)
-    )
-    for chunk in chunks:
-        progress.increment()
-        if chunk[b'complete']:
-            continue
-        bstart = int(chunk[b'byteStart'])
-        bend = int(chunk[b'byteEnd'])
-        callconduit(
-            ui,
-            b'file.uploadchunk',
-            {
-                b'filePHID': fphid,
-                b'byteStart': bstart,
-                b'data': base64.b64encode(fctx.data()[bstart:bend]),
-                b'dataEncoding': b'base64',
-            },
-        )
-    progress.complete()
+    ) as progress:
+        for chunk in chunks:
+            progress.increment()
+            if chunk[b'complete']:
+                continue
+            bstart = int(chunk[b'byteStart'])
+            bend = int(chunk[b'byteEnd'])
+            callconduit(
+                ui,
+                b'file.uploadchunk',
+                {
+                    b'filePHID': fphid,
+                    b'byteStart': bstart,
+                    b'data': base64.b64encode(fctx.data()[bstart:bend]),
+                    b'dataEncoding': b'base64',
+                },
+            )
 
 
 def uploadfile(fctx):