From: larsxschneider@gmail.com
To: git@vger.kernel.org
Cc: luke@diamand.org, sschuberth@gmail.com,
Lars Schneider <larsxschneider@gmail.com>
Subject: [PATCH v2 2/2] git-p4: fix Git LFS pointer parsing
Date: Wed, 20 Apr 2016 10:10:09 +0200 [thread overview]
Message-ID: <1461139809-6573-3-git-send-email-larsxschneider@gmail.com> (raw)
In-Reply-To: <1461139809-6573-1-git-send-email-larsxschneider@gmail.com>
From: Lars Schneider <larsxschneider@gmail.com>
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.
[1] https://github.com/github/git-lfs/commit/da2935d9a739592bc775c98d8ef4df9c72ea3b43
Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
---
git-p4.py | 15 ++++++++++++---
t/t9824-git-p4-git-lfs.sh | 4 ++++
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index 527d44b..ab52bc3 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1064,8 +1064,17 @@ class GitLFS(LargeFileSystem):
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
+ preamble = 'Git LFS pointer for ' + contentFile + '\n\n'
+ if pointerFile.startswith(preamble):
+ pointerFile = pointerFile[len(preamble):]
+
+ oidEntry = [i for i in pointerFile.split('\n') if i.startswith('oid')]
+ oid = oidEntry[0].split(' ')[1].split(':')[1]
localLargeFile = os.path.join(
os.getcwd(),
'.git', 'lfs', 'objects', oid[:2], oid[2:4],
@@ -1073,7 +1082,7 @@ class GitLFS(LargeFileSystem):
)
# 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(
diff --git a/t/t9824-git-p4-git-lfs.sh b/t/t9824-git-p4-git-lfs.sh
index 0b664a3..ca93ac8 100755
--- a/t/t9824-git-p4-git-lfs.sh
+++ b/t/t9824-git-p4-git-lfs.sh
@@ -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" &&
--
2.5.1
next prev parent reply other threads:[~2016-04-20 8:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-20 8:10 [PATCH v2 0/2] git-p4: fix Git LFS pointer parsing larsxschneider
2016-04-20 8:10 ` [PATCH v2 1/2] travis-ci: update Git-LFS and P4 to the latest version larsxschneider
2016-04-20 8:10 ` larsxschneider [this message]
2016-04-20 8:59 ` [PATCH v2 2/2] git-p4: fix Git LFS pointer parsing Sebastian Schuberth
2016-04-20 18:30 ` Junio C Hamano
2016-04-20 20:03 ` Lars Schneider
2016-04-20 21:01 ` Junio C Hamano
2016-04-22 7:53 ` Lars Schneider
2016-04-22 7:55 ` Sebastian Schuberth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1461139809-6573-3-git-send-email-larsxschneider@gmail.com \
--to=larsxschneider@gmail.com \
--cc=git@vger.kernel.org \
--cc=luke@diamand.org \
--cc=sschuberth@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).