Skip to content

Commit d2176a5

Browse files
larsxschneidergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7960e70 commit d2176a5

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

git-p4.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,9 @@ def splitFilesIntoBranches(self, commit):
21712171
def streamOneP4File(self, file, contents):
21722172
relPath = self.stripRepoPath(file['depotFile'], self.branchPrefixes)
21732173
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()
21752177

21762178
(type_base, type_mods) = split_p4_type(file["type"])
21772179

@@ -2248,7 +2250,8 @@ def streamOneP4File(self, file, contents):
22482250
def streamOneP4Deletion(self, file):
22492251
relPath = self.stripRepoPath(file['path'], self.branchPrefixes)
22502252
if verbose:
2251-
sys.stderr.write("delete %s\n" % relPath)
2253+
sys.stdout.write("delete %s\n" % relPath)
2254+
sys.stdout.flush()
22522255
self.gitStream.write("D %s\n" % relPath)
22532256

22542257
# handle another chunk of streaming data
@@ -2288,10 +2291,23 @@ def streamP4FilesCb(self, marshalled):
22882291
# 'data' field we need to append to our array
22892292
for k in marshalled.keys():
22902293
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'])
22912297
self.stream_contents.append(marshalled['data'])
22922298
else:
22932299
self.stream_file[k] = marshalled[k]
22942300

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+
22952311
self.stream_have_file_info = True
22962312

22972313
# Stream directly from "p4 files" into "git fast-import"

0 commit comments

Comments
 (0)