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

Re: [PATCH] Teach 'git apply' to look at $GIT_DIR/config

From
Junio C Hamano <junkio@cox.net>
Date
Feb 18, 2007, 01:47 UTC
Message-ID
<7v3b54p78r.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.63.0702180210490.22628@wbgn013.biozentrum.uni-wuerzburg.de>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 16 quoted lines
>> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>> 
>> > On Sat, 17 Feb 2007, Junio C Hamano wrote:
>> > ...
>> >> But I think Jeff is right.  It would make sense to let apply
>> >> and perhaps 'diff', if we can somehow merge 'diff2' into it,
>> >> still read from $HOME/.gitconfig if available.
>> >
>> > Yes, especially if you are soo used to colours as I grew to be used to 
>> > them. This was literally one of the reasons I wrote diff2 in the first 
>> > place. Another was --color-words.
>> 
>> True.  Paches welcome ;-).
>
> I sent it out already... It was titled "[PATCH] Add `git diff2`, a GNU 
> diff workalike" ;-)

I thought we were talking about making 'git apply' to read from $HOME/.gitconfig even outside a git repository.

A funny thing is that I was suspecting that calling git_config() would fail if you are not in a git repository after you called setup_git_directory_gently() with no_git_ok). The lower level does return error because ".git/config" does not exist, but it does not call error() to say why it failed. Callers typically ignore the return value from the function, so it ends up working.

So this simple patch is the welcomed one for now ;-)
-- >8 --
diff --git a/builtin-apply.c b/builtin-apply.c
index 6ed257d..20fb5bd 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -2622,11 +2622,9 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
 
 	prefix = setup_git_directory_gently(&is_not_gitdir);
 	prefix_length = prefix ? strlen(prefix) : 0;
-	if (!is_not_gitdir) {
-		git_config(git_apply_config);
-		if (apply_default_whitespace)
-			parse_whitespace_option(apply_default_whitespace);
-	}
+	git_config(git_apply_config);
+	if (apply_default_whitespace)
+		parse_whitespace_option(apply_default_whitespace);
 
 	for (i = 1; i < argc; i++) {
 		const char *arg = argv[i];

-- 8< --

> The longer I think about it, the more I am convinced that trying to 
> integrate diff2 into diff _will_ lead to errors due to my trained, but 
> disobeying, fingers.
>
> I also debated with myself calling it diff-two or diff-direct (both not 
> really convincing), or even diff-file (too similar to diff-files), but I 
> could not come up with a better name than diff2. Which is also very easy 
> to write, I have to say.

Hmmmmmmmmmmmmmmmmmmmm.

I do agree diff-file is too confusing with diff-files, but...

In any case, I am done for the evening, and your patch did not
apply to any of the well-known versions, so perhaps I can take a
rest and have dinner and hope to find a respun one that
everybody on the list agrees with its name in my mailbox later?
;-)

I've parked the --color --check one at near the tip of 'pu', but
it appears its handling of whitespace warning is broken.

For example, from a patch that does this (I replaced a HT with =
and SP with _):

        @@ -1,6 +1,6 @@
         # The default target of this Makefile is...
         all:
        -
        +_=ab_
         # Define NO_OPENSSL
         # This also implies
         #

I get:

        Makefile:3: space before tab.white space at end: +=ab_
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     ~

where ~ are colored in whitespace warning color.

	
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 37 of 49 in “Teach core.autocrlf to 'git apply'”
  1. Teach core.autocrlf to 'git apply'Junio C Hamano, Feb 17, 2007
  2. Teach 'git apply' to look at $GIT_DIR/configJunio C Hamano, Feb 17, 2007
  3. Jeff KingFeb 17, 2007
  4. Junio C HamanoFeb 17, 2007
  5. Jeff KingFeb 17, 2007
  6. Linus TorvaldsFeb 19, 2007
  7. Shawn O. PearceFeb 19, 2007
  8. Junio C HamanoFeb 19, 2007
  9. Linus TorvaldsFeb 19, 2007
  10. Junio C HamanoFeb 19, 2007
  11. Linus TorvaldsFeb 20, 2007
  12. Junio C HamanoFeb 20, 2007
  13. Johannes SchindelinFeb 20, 2007
  14. Junio C HamanoFeb 20, 2007
  15. Johannes SchindelinFeb 20, 2007
  16. git-apply: require -p<n> when working in a subdirectory.Junio C Hamano, Feb 20, 2007
  17. apply: fix memory leak in prefix_one()Johannes Schindelin, Feb 20, 2007
  18. Junio C HamanoFeb 20, 2007
  19. Johannes SchindelinFeb 20, 2007
  20. git-apply: do not lose cwd when run from a subdirectory.Junio C Hamano, Feb 20, 2007
  21. Junio C HamanoFeb 20, 2007
  22. Linus TorvaldsFeb 20, 2007
  23. Daniel BarkalowFeb 21, 2007
  24. Junio C HamanoFeb 21, 2007
  25. Daniel BarkalowFeb 21, 2007
  26. Linus TorvaldsFeb 21, 2007
  27. Junio C HamanoFeb 21, 2007
  28. git-apply: notice "diff --git" patch againJunio C Hamano, Feb 21, 2007
  29. git-apply: guess correct -p<n> value for non-git patches.Junio C Hamano, Feb 22, 2007
  30. Johannes SchindelinFeb 20, 2007
  31. Simon 'corecode' SchubertFeb 20, 2007
  32. Johannes SchindelinFeb 18, 2007
  33. Junio C HamanoFeb 18, 2007
  34. Johannes SchindelinFeb 18, 2007
  35. Junio C HamanoFeb 18, 2007
  36. Johannes SchindelinFeb 18, 2007
  37. Junio C HamanoFeb 18, 2007
  38. Johannes SchindelinFeb 18, 2007
  39. Junio C HamanoFeb 18, 2007
  40. Johannes SchindelinFeb 18, 2007
  41. Jakub NarebskiFeb 18, 2007
  42. Johannes SchindelinFeb 18, 2007
  43. Junio C HamanoFeb 18, 2007
  44. Johannes SchindelinFeb 18, 2007
  45. Junio C HamanoFeb 18, 2007
  46. Johannes SchindelinFeb 18, 2007
  47. Junio C HamanoFeb 18, 2007
  48. Johannes SchindelinFeb 18, 2007
  49. Junio C HamanoFeb 18, 2007

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.