git-p4: add file streaming progress in verbose mode
If a file is streamed from P4 to Git then the verbose mode prints continuously the progress as percentage like this: //depot/file.bin 20% (10 MB) Upon completion the progress is overwritten with depot source, local file and size like this: //depot/file.bin --> local/file.bin (10 MB) Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Lars Schneider committed
Sep 26, 2015 at 09:55 UTC
d2176a5060c73a04846e270ab07b90aad4d8b8f0
1 file changed
+18
-2
git-p4.py
+18
-2
@@ -2171,7 +2171,9 @@ class P4Sync(Command, P4UserMap):
2171
def streamOneP4File(self, file, contents):
2172
relPath = self.stripRepoPath(file['depotFile'], self.branchPrefixes)
2173
if verbose:
2174
- sys.stderr.write("%s\n" % relPath)
2174
+ size = int(self.stream_file['fileSize'])
2175
+ sys.stdout.write('\r%s --> %s (%i MB)\n' % (file['depotFile'], relPath, size/1024/1024))
2176
+ sys.stdout.flush()
2177
2178
(type_base, type_mods) = split_p4_type(file["type"])
2179
@@ -2248,7 +2250,8 @@ class P4Sync(Command, P4UserMap):
2250
def streamOneP4Deletion(self, file):
2251
relPath = self.stripRepoPath(file['path'], self.branchPrefixes)
2252
if verbose:
2251
- sys.stderr.write("delete %s\n" % relPath)
2253
+ sys.stdout.write("delete %s\n" % relPath)
2254
+ sys.stdout.flush()
2255
self.gitStream.write("D %s\n" % relPath)
2256
2257
# handle another chunk of streaming data
@@ -2288,10 +2291,23 @@ class P4Sync(Command, P4UserMap):
2291
# 'data' field we need to append to our array
2292
for k in marshalled.keys():
2293
if k == 'data':
2294
+ if 'streamContentSize' not in self.stream_file:
2295
+ self.stream_file['streamContentSize'] = 0
2296
+ self.stream_file['streamContentSize'] += len(marshalled['data'])
2297
self.stream_contents.append(marshalled['data'])
2298
else:
2299
self.stream_file[k] = marshalled[k]
2300
2301
+ if (verbose and
2302
+ 'streamContentSize' in self.stream_file and
2303
+ 'fileSize' in self.stream_file and
2304
+ 'depotFile' in self.stream_file):
2305
+ size = int(self.stream_file["fileSize"])
2306
+ if size > 0:
2307
+ progress = 100*self.stream_file['streamContentSize']/size
2308
+ sys.stdout.write('\r%s %d%% (%i MB)' % (self.stream_file['depotFile'], progress, int(size/1024/1024)))
2309
+ sys.stdout.flush()
2310
+
2311
self.stream_have_file_info = True
2312
2313
# Stream directly from "p4 files" into "git fast-import"