git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git-apply fails on creating a new file, with both -p and --directory specified

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 8, 2009, 07:28 UTC
Message-ID
<7v3a3lorge.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20091208060109.GB9951@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 11 quoted lines
> 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.
Show 17 quoted lines
> 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);
>  	}
>  
Previous: James VegaNext: Jeff King
Message 9 of 14 in “git-apply fails on creating a new file, with both -p and --directory specified”
  1. Steven J. MurdochNov 23, 2009
  2. Junio C HamanoNov 25, 2009
  3. James VegaDec 7, 2009
  4. Junio C HamanoDec 8, 2009
  5. Junio C HamanoDec 8, 2009
  6. Jeff KingDec 8, 2009
  7. Jeff KingDec 8, 2009
  8. James VegaDec 8, 2009
  9. Junio C HamanoDec 8, 2009
  10. Jeff KingDec 8, 2009
  11. Junio C HamanoDec 8, 2009
  12. Junio C HamanoDec 8, 2009
  13. Jeff KingDec 8, 2009
  14. James VegaDec 8, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.