1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-04 04:16:12 +02:00

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] da2935d9a7

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>
This commit is contained in:
Lars Schneider 2016-04-28 08:26:33 +02:00 committed by Junio C Hamano
parent 3d319f2c63
commit 82f2567e3d
2 changed files with 14 additions and 3 deletions

View File

@ -1064,8 +1064,15 @@ def generatePointer(self, contentFile):
if pointerProcess.wait():
os.remove(contentFile)
die('git-lfs pointer command failed. Did you install the extension?')
pointerContents = [i+'\n' for i in pointerFile.split('\n')[2:][:-1]]
oid = pointerContents[1].split(' ')[1].split(':')[1][:-1]
# Git LFS removed the preamble in the output of the 'pointer' command
# starting from version 1.2.0. Check for the preamble here to support
# earlier versions.
# c.f. https://github.com/github/git-lfs/commit/da2935d9a739592bc775c98d8ef4df9c72ea3b43
if pointerFile.startswith('Git LFS pointer for'):
pointerFile = re.sub(r'Git LFS pointer for.*\n\n', '', pointerFile)
oid = re.search(r'^oid \w+:(\w+)', pointerFile, re.MULTILINE).group(1)
localLargeFile = os.path.join(
os.getcwd(),
'.git', 'lfs', 'objects', oid[:2], oid[2:4],
@ -1073,7 +1080,7 @@ def generatePointer(self, contentFile):
)
# LFS Spec states that pointer files should not have the executable bit set.
gitMode = '100644'
return (gitMode, pointerContents, localLargeFile)
return (gitMode, pointerFile, localLargeFile)
def pushFile(self, localLargeFile):
uploadProcess = subprocess.Popen(

View File

@ -13,6 +13,10 @@ test_file_in_lfs () {
FILE="$1" &&
SIZE="$2" &&
EXPECTED_CONTENT="$3" &&
sed -n '1,1 p' "$FILE" | grep "^version " &&
sed -n '2,2 p' "$FILE" | grep "^oid " &&
sed -n '3,3 p' "$FILE" | grep "^size " &&
test_line_count = 3 "$FILE" &&
cat "$FILE" | grep "size $SIZE" &&
HASH=$(cat "$FILE" | grep "oid sha256:" | sed -e "s/oid sha256://g") &&
LFS_FILE=".git/lfs/objects/$(echo "$HASH" | cut -c1-2)/$(echo "$HASH" | cut -c3-4)/$HASH" &&