Thread (7 messages) 7 messages, 2 authors, 2020-02-04

Re: [PATCH v2 00/14] git-p4: python3 compatibility

From: Yang Zhao <hidden>
Date: 2020-02-03 18:11:20
Subsystem: the rest · Maintainer: Linus Torvalds

On Mon, Feb 3, 2020 at 4:54 AM Luke Diamand [off-list ref] wrote:
One very small bug report:

When doing "git p4 sync" it prints out the percent complete. It looks
like it's no longer rounding it sensibly, so where before it would say
77%, now it says 77.7777777%.

It's this line:

   sys.stdout.write("\rImporting revision %s (%s%%)" % (change, cnt *
100 / len(changes)))

I think / just needs replacing with //.
Good catch.

The patch below should do the trick, and be more explicit about how
we're formatting things.

I'll roll it into the GitHub branch.
diff --git a/git-p4.py b/git-p4.py
index ca0a874501..183959ec8c 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -2960,7 +2960,7 @@ def streamP4FilesCb(self, marshalled):
             size = int(self.stream_file["fileSize"])
             if size > 0:
                 progress = 100*self.stream_file['streamContentSize']/size
-                sys.stdout.write('\r%s %d%% (%i MB)' %
(self.stream_file['depotFile'], progress, int(size/1024/1024)))
+                sys.stdout.write('\r{} {:.0%} ({}
MB)'.format(self.stream_file['depotFile'], progress,
int(size/1024/1024)))
                 sys.stdout.flush()

         self.stream_have_file_info = True
@@ -3435,7 +3435,7 @@ def importChanges(self, changes, origin_revision=0):
             self.updateOptionDict(description)

             if not self.silent:
-                sys.stdout.write("\rImporting revision %s (%s%%)" %
(change, cnt * 100 / len(changes)))
+                sys.stdout.write("\rImporting revision {}
({:.0%})".format(change, cnt / len(changes)))
                 sys.stdout.flush()
             cnt = cnt + 1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help