git-p4: fix empty file processing for large file system backend GitLFS

If git-p4 tried to store an empty file in GitLFS then it crashed while parsing the pointer file: oid = re.search(r'^oid \w+:(\w+)', pointerFile, re.MULTILINE).group(1) AttributeError: 'NoneType' object has no attribute 'group' This happens because GitLFS does not create a pointer file for an empty file. Teach git-p4 this behavior to fix the problem and add a test case. Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Lars Schneider committed Dec 4, 2016 at 17:03 UTC d5eb3cf5e7e4274e12e0f249b3a026c029f3b02c
2 files changed +19 -12
git-p4.py
+17 -12
@@ -1005,18 +1005,20 @@ class LargeFileSystem(object):
1005 steps."""
1006 if self.exceedsLargeFileThreshold(relPath, contents) or self.hasLargeFileExtension(relPath):
1007 contentTempFile = self.generateTempFile(contents)
1008 - (git_mode, contents, localLargeFile) = self.generatePointer(contentTempFile)
1009 -
1010 - # Move temp file to final location in large file system
1011 - largeFileDir = os.path.dirname(localLargeFile)
1012 - if not os.path.isdir(largeFileDir):
1013 - os.makedirs(largeFileDir)
1014 - shutil.move(contentTempFile, localLargeFile)
1015 - self.addLargeFile(relPath)
1016 - if gitConfigBool('git-p4.largeFilePush'):
1017 - self.pushFile(localLargeFile)
1018 - if verbose:
1019 - sys.stderr.write("%s moved to large file system (%s)\n" % (relPath, localLargeFile))
1008 + (pointer_git_mode, contents, localLargeFile) = self.generatePointer(contentTempFile)
1009 + if pointer_git_mode:
1010 + git_mode = pointer_git_mode
1011 + if localLargeFile:
1012 + # Move temp file to final location in large file system
1013 + largeFileDir = os.path.dirname(localLargeFile)
1014 + if not os.path.isdir(largeFileDir):
1015 + os.makedirs(largeFileDir)
1016 + shutil.move(contentTempFile, localLargeFile)
1017 + self.addLargeFile(relPath)
1018 + if gitConfigBool('git-p4.largeFilePush'):
1019 + self.pushFile(localLargeFile)
1020 + if verbose:
1021 + sys.stderr.write("%s moved to large file system (%s)\n" % (relPath, localLargeFile))
1022 return (git_mode, contents)
1023
1024 class MockLFS(LargeFileSystem):
@@ -1056,6 +1058,9 @@ class GitLFS(LargeFileSystem):
1058 the actual content. Return also the new location of the actual
1059 content.
1060 """
1061 + if os.path.getsize(contentFile) == 0:
1062 + return (None, '', None)
1063 +
1064 pointerProcess = subprocess.Popen(
1065 ['git', 'lfs', 'pointer', '--file=' + contentFile],
1066 stdout=subprocess.PIPE
t/t9824-git-p4-git-lfs.sh
+2
@@ -42,6 +42,8 @@ test_expect_success 'Create repo with binary files' '
42 (
43 cd "$cli" &&
44
45 + >file0.dat &&
46 + p4 add file0.dat &&
47 echo "content 1 txt 23 bytes" >file1.txt &&
48 p4 add file1.txt &&
49 echo "content 2-3 bin 25 bytes" >file2.dat &&