From: Laszlo Ersek <lersek@redhat.com>
To: gitster@pobox.com, git@vger.kernel.org,
jordan.l.justen@intel.com, matt.fleming@intel.com,
lersek@redhat.com
Subject: [PATCH for-maint] apply: gitdiff_verify_name(): accept "/dev/null\r"
Date: Tue, 23 Sep 2014 03:09:43 +0200 [thread overview]
Message-ID: <1411434583-27692-1-git-send-email-lersek@redhat.com> (raw)
The edk2 (EFI Development Kit II) project at
<https://github.com/tianocore/edk2/> uses CRLF line endings.
The following small reproducer demonstrates how gitdiff_verify_name()
breaks when it meets the usual git patches workflow in combination with
CRLF line endings:
1. Prepare the test repo:
mkdir testdir
cd testdir
git init
git config core.whitespace cr-at-eol
git config am.keepcr true
touch f1
git add f1
git commit -m 'initial import'
2. In the contributor role, write a patch that creates a new file
(adhering to the CRLF convention), submit it, then clean up:
git checkout -b branch1 master
echo 'hello world' | unix2dos >f2
git add f2
git commit -m 'add f2'
git format-patch master..branch1
git send-email 0001-add-f2.patch
# send it to yourself -- make sure it goes through your MTA
git clean -fdx
3. In the reviewer / tester / maintainer role, save the patch from your
email client to a local file. Assume that your email client does not
corrupt the patch when saving it. (Thunderbird doesn't corrupt it, for
example.) Once saved, try to apply the patch email to a new branch.
git checkout -b branch2 master
git am /path/to/the/saved/file
-> Applying: add f2
-> fatal: git apply: bad git-diff - expected /dev/null on line 9
This happens because am.keepcr==true keeps the CRLFs intact (as it should
in fact), but then "/dev/null\r" in the diff header trips up
gitdiff_verify_name().
Fix it by reusing the is_dev_null() helper function, which in effect
changes the condition from
memcmp("/dev/null", line, 9) || line[9] != '\n'
to
memcmp("/dev/null", line, 9) || !isspace(line[9])
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
Notes:
I'm not subscribed to the list; please keep me CC'd. Thanks.
builtin/apply.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/apply.c b/builtin/apply.c
index 6b7c764..a9c6a08 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -955,7 +955,7 @@ static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name,
}
else {
/* expect "/dev/null" */
- if (memcmp("/dev/null", line, 9) || line[9] != '\n')
+ if (!is_dev_null(line))
die(_("git apply: bad git-diff - expected /dev/null on line %d"), linenr);
return NULL;
}
--
1.8.3.1
next reply other threads:[~2014-09-23 1:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-23 1:09 Laszlo Ersek [this message]
2014-09-23 18:54 ` [PATCH for-maint] apply: gitdiff_verify_name(): accept "/dev/null\r" Junio C Hamano
2014-09-23 19:31 ` Laszlo Ersek
2014-09-23 19:56 ` Junio C Hamano
2014-09-23 20:33 ` Laszlo Ersek
2014-09-23 20:40 ` Junio C Hamano
2014-09-23 20:57 ` Laszlo Ersek
2014-09-23 20:02 ` Junio C Hamano
2014-09-23 20:32 ` Laszlo Ersek
2014-09-23 20:35 ` Junio C Hamano
2014-09-23 20:49 ` Laszlo Ersek
2014-09-23 21:35 ` Junio C Hamano
2014-09-24 12:56 ` Laszlo Ersek
2014-09-24 17:55 ` Junio C Hamano
2014-09-23 20:17 ` Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1411434583-27692-1-git-send-email-lersek@redhat.com \
--to=lersek@redhat.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jordan.l.justen@intel.com \
--cc=matt.fleming@intel.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.
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 NNTP newsgroup(s).