git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/1] git-p4: fix `sync --verbose` traceback due to 'fileSize'

From
AMAndrey Mazo <amazo@checkvideo.com>
Date
Apr 17, 2018, 16:22 UTC
Message-ID
<2e2b2add4e4fffa4228b8ab9f6cd47fa9bf25207.1523981210.git.amazo@checkvideo.com>
In-Reply-To
<cover.1523981210.git.amazo@checkvideo.com>
Perforce server 2007.2 (and maybe others) doesn't return "fileSize"
attribute in its reply to `p4 -G print` command.
This causes the following traceback when running `git p4 sync --verbose`:
"""
    Traceback (most recent call last):
      File "/usr/libexec/git-core/git-p4", line 3839, in <module>
	main()
      File "/usr/libexec/git-core/git-p4", line 3833, in main
	if not cmd.run(args):
      File "/usr/libexec/git-core/git-p4", line 3567, in run
	self.importChanges(changes)
      File "/usr/libexec/git-core/git-p4", line 3233, in importChanges
	self.commit(description, filesForCommit, branch, parent)
      File "/usr/libexec/git-core/git-p4", line 2855, in commit
	self.streamP4Files(files)
      File "/usr/libexec/git-core/git-p4", line 2747, in streamP4Files
	cb=streamP4FilesCbSelf)
      File "/usr/libexec/git-core/git-p4", line 552, in p4CmdList
	cb(entry)
      File "/usr/libexec/git-core/git-p4", line 2741, in streamP4FilesCbSelf
	self.streamP4FilesCb(entry)
      File "/usr/libexec/git-core/git-p4", line 2689, in streamP4FilesCb
	self.streamOneP4File(self.stream_file, self.stream_contents)
      File "/usr/libexec/git-core/git-p4", line 2566, in streamOneP4File
	size = int(self.stream_file['fileSize'])
    KeyError: 'fileSize'
"""

Fix this by omitting the file size information from the verbose print out. Also, don't use "self.stream_file" directly, but rather use passed in "file" argument. (which point to the same "self.stream_file" for all existing callers)

Signed-off-by: Andrey Mazo <amazo@checkvideo.com>
---
 git-p4.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index 7bb9cadc6..6f05f915a 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -2566,8 +2566,12 @@ class P4Sync(Command, P4UserMap):
         relPath = self.stripRepoPath(file['depotFile'], self.branchPrefixes)
         relPath = self.encodeWithUTF8(relPath)
         if verbose:
-            size = int(self.stream_file['fileSize'])
-            sys.stdout.write('\r%s --> %s (%i MB)\n' % (file['depotFile'], relPath, size/1024/1024))
+            size = file.get('fileSize', None)
+            if size is None:
+                sizeStr = ''
+            else:
+                sizeStr = ' (%i MB)' % (int(size)/1024/1024)
+            sys.stdout.write('\r%s --> %s%s\n' % (file['depotFile'], relPath, sizeStr))
             sys.stdout.flush()
 
         (type_base, type_mods) = split_p4_type(file["type"])
-- 
2.16.1
Previous: Andrey MazoNext: Thandesha VK
Message 3 of 15 in “[BUG] git p4 clone fails when p4 sizes does not return 'fileSize' key”
  1. Thandesha VKApr 16, 2018
  2. Andrey MazoApr 17, 2018
  3. 1/1 git-p4: fix `sync --verbose` traceback due to 'fileSize'Andrey Mazo, Apr 17, 2018
  4. Thandesha VKApr 17, 2018
  5. Mazo, AndreyApr 17, 2018
  6. Thandesha VKApr 17, 2018
  7. Mazo, AndreyApr 17, 2018
  8. Thandesha VKApr 17, 2018
  9. Luke DiamandApr 18, 2018
  10. Thandesha VKApr 18, 2018
  11. Mazo, AndreyApr 17, 2018
  12. Mazo, AndreyApr 17, 2018
  13. Thandesha VKApr 17, 2018
  14. Mazo, AndreyApr 17, 2018
  15. Thandesha VKApr 17, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.