git-p4: do not fail in verbose mode for missing 'fileSize' key
authorLuke Diamand <luke@diamand.org>
Fri, 12 Oct 2018 05:28:31 +0000 (06:28 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 12 Oct 2018 13:38:29 +0000 (22:38 +0900)
If deleting or moving a file, sometimes P4 doesn't report the file size.

The code handles this just fine but some logging crashes. Stop this
happening.

There was some earlier discussion on the list about this:

https://public-inbox.org/git/xmqq1sqpp1vv.fsf@gitster.mtv.corp.google.com/

Signed-off-by: Luke Diamand <luke@diamand.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-p4.py
index 7fab255584e5bca70aef305f6ead73330694a88b..5701bad06ae7d076f2f26708a81db759ea028a0e 100755 (executable)
--- a/git-p4.py
+++ b/git-p4.py
@@ -2775,7 +2775,10 @@ def streamOneP4File(self, file, contents):
         relPath = self.stripRepoPath(file['depotFile'], self.branchPrefixes)
         relPath = self.encodeWithUTF8(relPath)
         if verbose:
-            size = int(self.stream_file['fileSize'])
+            if 'fileSize' in self.stream_file:
+                size = int(self.stream_file['fileSize'])
+            else:
+                size = 0 # deleted files don't get a fileSize apparently
             sys.stdout.write('\r%s --> %s (%i MB)\n' % (file['depotFile'], relPath, size/1024/1024))
             sys.stdout.flush()