git-p4: fix Git LFS pointer parsing

Git LFS 1.2.0 removed a preamble from the output of the 'git lfs pointer' command [1] which broke the parsing of this output. Adjust the parser to support the old and the new format. Please note that this patch slightly changes the second return parameter from a list of LF terminated strings to a single string that contains a number of LF characters. [1] https://github.com/github/git-lfs/commit/da2935d9a739592bc775c98d8ef4df9c72ea3b43 Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Helped-by: Sebastian Schuberth <sschuberth@gmail.com> Helped-by: Ben Woosley <ben.woosley@gmail.com> Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Lars Schneider committed Apr 28, 2016 at 08:26 UTC 82f2567e3d01a6eeb4c6a0b9139232034de6e60f
2 files changed +14 -3
git-p4.py
+10 -3
@@ -1064,8 +1064,15 @@ class GitLFS(LargeFileSystem):
1064 if pointerProcess.wait():
1065 os.remove(contentFile)
1066 die('git-lfs pointer command failed. Did you install the extension?')
1067 - pointerContents = [i+'\n' for i in pointerFile.split('\n')[2:][:-1]]
1068 - oid = pointerContents[1].split(' ')[1].split(':')[1][:-1]
1067 +
1068 + # Git LFS removed the preamble in the output of the 'pointer' command
1069 + # starting from version 1.2.0. Check for the preamble here to support
1070 + # earlier versions.
1071 + # c.f. https://github.com/github/git-lfs/commit/da2935d9a739592bc775c98d8ef4df9c72ea3b43
1072 + if pointerFile.startswith('Git LFS pointer for'):
1073 + pointerFile = re.sub(r'Git LFS pointer for.*\n\n', '', pointerFile)
1074 +
1075 + oid = re.search(r'^oid \w+:(\w+)', pointerFile, re.MULTILINE).group(1)
1076 localLargeFile = os.path.join(
1077 os.getcwd(),
1078 '.git', 'lfs', 'objects', oid[:2], oid[2:4],
@@ -1073,7 +1080,7 @@ class GitLFS(LargeFileSystem):
1080 )
1081 # LFS Spec states that pointer files should not have the executable bit set.
1082 gitMode = '100644'
1076 - return (gitMode, pointerContents, localLargeFile)
1083 + return (gitMode, pointerFile, localLargeFile)
1084
1085 def pushFile(self, localLargeFile):
1086 uploadProcess = subprocess.Popen(
t/t9824-git-p4-git-lfs.sh
+4
@@ -13,6 +13,10 @@ test_file_in_lfs () {
13 FILE="$1" &&
14 SIZE="$2" &&
15 EXPECTED_CONTENT="$3" &&
16 + sed -n '1,1 p' "$FILE" | grep "^version " &&
17 + sed -n '2,2 p' "$FILE" | grep "^oid " &&
18 + sed -n '3,3 p' "$FILE" | grep "^size " &&
19 + test_line_count = 3 "$FILE" &&
20 cat "$FILE" | grep "size $SIZE" &&
21 HASH=$(cat "$FILE" | grep "oid sha256:" | sed -e "s/oid sha256://g") &&
22 LFS_FILE=".git/lfs/objects/$(echo "$HASH" | cut -c1-2)/$(echo "$HASH" | cut -c3-4)/$HASH" &&