From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Junio C Hamano <gitster@pobox.com>,
James Vega <vega.james@gmail.com>,
git@vger.kernel.org
Subject: Re: git-apply fails on creating a new file, with both -p and --directory specified
Date: Mon, 07 Dec 2009 23:28:01 -0800 [thread overview]
Message-ID: <7v3a3lorge.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <20091208060109.GB9951@coredump.intra.peff.net> (Jeff King's message of "Tue\, 8 Dec 2009 01\:01\:09 -0500")
Jeff King <peff@peff.net> writes:
> On Tue, Dec 08, 2009 at 12:47:24AM -0500, Jeff King wrote:
>
>> There is a slightly different approach we could take, too: keep the
>> "deletion" hunk as a first-class hunk, and just meld the content hunk's
>> output into it. Then both cases would get the "Stage deletion" question
>> instead of the "Stage this hunk" you get now for non-empty files (which
>> just happens to trigger a deletion due to the headers).
>
> BTW, the code for this is the much smaller change below. If you prefer
> that, I can squash in the test and write up an appropriate commit
> message.
Doubly interesting, as I recall reading "That would take some refactoring,
though, as pulling the deletion hunk"
... goes and looks ...
Ah, Ok, the "refactoring" refers to the "header reordering weirdness".
That might be something we may want to fix someday, when we find ourselves
needing to add a feature to turn deletion into non-deletion or vice versa
during "add -p" [e]dit, as I suspect that the "hunk editing" codepath does
not keep track of what the user's patch is doing, to the point that it
does not even know how many lines there are supposed to be in the
resulting hunk that it asks "git apply" to recount. There is no way to
add/delete "deleted file" line if the logic does not know what the patch
is doing.
But someday is not today. I think this six-liner is preferable.
> diff --git a/git-add--interactive.perl b/git-add--interactive.perl
> index 35f4ef1..02e97b9 100755
> --- a/git-add--interactive.perl
> +++ b/git-add--interactive.perl
> @@ -1217,7 +1217,11 @@ sub patch_update_file {
> if (@{$mode->{TEXT}}) {
> unshift @hunk, $mode;
> }
> - if (@{$deletion->{TEXT}} && !@hunk) {
> + if (@{$deletion->{TEXT}}) {
> + foreach my $hunk (@hunk) {
> + push @{$deletion->{TEXT}}, @{$hunk->{TEXT}};
> + push @{$deletion->{DISPLAY}}, @{$hunk->{DISPLAY}};
> + }
> @hunk = ($deletion);
> }
>
next prev parent reply other threads:[~2009-12-08 7:28 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-23 19:45 git-apply fails on creating a new file, with both -p and --directory specified Steven J. Murdoch
2009-11-25 10:56 ` Junio C Hamano
2009-12-07 21:35 ` James Vega
2009-12-08 2:59 ` Junio C Hamano
2009-12-08 3:20 ` Junio C Hamano
2009-12-08 5:47 ` Jeff King
2009-12-08 6:01 ` Jeff King
2009-12-08 6:49 ` James Vega
2009-12-08 7:28 ` Junio C Hamano [this message]
2009-12-08 7:49 ` Jeff King
2009-12-08 7:53 ` Junio C Hamano
2009-12-08 7:11 ` Junio C Hamano
2009-12-08 7:38 ` Jeff King
2009-12-08 3:39 ` James Vega
-- strict thread matches above, loose matches on Subject: below --
2010-04-28 12:29 Matthias Lehmann
2010-04-29 8:20 ` Matthias Lehmann
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=7v3a3lorge.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=vega.james@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.
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).