From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
"Shawn O. Pearce" <spearce@spearce.org>,
Git Mailing List <git@vger.kernel.org>
Subject: Re: git apply --directory broken for new files
Date: Sat, 11 Oct 2008 20:18:39 -0700 [thread overview]
Message-ID: <7vk5ceijqo.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <20080927015422.GA31783@coredump.intra.peff.net> (Jeff King's message of "Fri, 26 Sep 2008 21:54:22 -0400")
Jeff King <peff@peff.net> writes:
> apply --directory: handle creation and deletion patches
>
> We carefully verify that the input to git-apply is sane, including
> cross-checking that the filenames we see in "+++" headers match what was
> provided on the command line of "diff --git". When --directory is used,
> however, we ended up comparing the unadorned name to one with the
> prepended root, causing us to complain about a mismatch.
>
> We simply need to prepend the root directory, if any, when pulling the
> name out of the git header.
Thanks.
c4730f3 (Teach "git apply" to prepend a prefix with "--root=<root>",
2008-07-01) did a half-baked job to teach find_name() which is used to
parse traditional diff and also is used to set patch->old_name and
patch->new_name by gitdiff_verify_name() when parsing "copy from", "copy
to", "rename from", and "rename to". The caller of git_header_name() uses
the return value to set patch->def_name that is used when "deleted file"
and "new file" are parsed, which should have been taught this trick by the
same commit.
However,...
> diff --git a/builtin-apply.c b/builtin-apply.c
> index 2ab4aba..f9070d5 100644
> --- a/builtin-apply.c
> +++ b/builtin-apply.c
> @@ -787,6 +787,13 @@ static char *git_header_name(char *line, int llen)
> break;
> }
> if (second[len] == '\n' && !memcmp(name, second, len)) {
> + if (root) {
> + char *ret = xmalloc(root_len + len + 1);
> + strcpy(ret, root);
> + memcpy(ret + root_len, name, len);
> + ret[root_len + len] = '\0';
> + return ret;
> + }
> return xmemdupz(name, len);
> }
> }
I suspect this is only half of the story, because the code to parse:
diff --git "a/f\244o/bar.c" "b/f\244o/bar.c"
in the same function before the part you patched needs similar
treatment. There are two return of strbuf_detach(&first, NULL)
in the if(){} block, and the return value needs to be prefixed with the
value of --directory when given.
It would be easier to do this --directory prefixing in the sole caller of
git_header_name(), though.
next prev parent reply other threads:[~2008-10-12 3:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-25 20:41 git apply --directory broken for new files H. Peter Anvin
2008-09-27 1:54 ` Jeff King
2008-10-12 3:18 ` Junio C Hamano [this message]
2008-10-12 4:06 ` Jeff King
2008-10-12 6:36 ` 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=7vk5ceijqo.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=hpa@zytor.com \
--cc=peff@peff.net \
--cc=spearce@spearce.org \
/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).