Skip to content

Commit 82f2567

Browse files
larsxschneidergitster
authored andcommitted
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] git-lfs/git-lfs@da2935d Signed-off-by: Lars Schneider <[email protected]> Helped-by: Sebastian Schuberth <[email protected]> Helped-by: Ben Woosley <[email protected]> Signed-off-by: Lars Schneider <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3d319f2 commit 82f2567

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

git-p4.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,16 +1064,23 @@ def generatePointer(self, contentFile):
10641064
if pointerProcess.wait():
10651065
os.remove(contentFile)
10661066
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)
10691076
localLargeFile = os.path.join(
10701077
os.getcwd(),
10711078
'.git', 'lfs', 'objects', oid[:2], oid[2:4],
10721079
oid,
10731080
)
10741081
# LFS Spec states that pointer files should not have the executable bit set.
10751082
gitMode = '100644'
1076-
return (gitMode, pointerContents, localLargeFile)
1083+
return (gitMode, pointerFile, localLargeFile)
10771084

10781085
def pushFile(self, localLargeFile):
10791086
uploadProcess = subprocess.Popen(

t/t9824-git-p4-git-lfs.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ test_file_in_lfs () {
1313
FILE="$1" &&
1414
SIZE="$2" &&
1515
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" &&
1620
cat "$FILE" | grep "size $SIZE" &&
1721
HASH=$(cat "$FILE" | grep "oid sha256:" | sed -e "s/oid sha256://g") &&
1822
LFS_FILE=".git/lfs/objects/$(echo "$HASH" | cut -c1-2)/$(echo "$HASH" | cut -c3-4)/$HASH" &&

0 commit comments

Comments
 (0)