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
Linus Torvalds <torvalds@linux-foundation.org>
Date
Feb 20, 2007, 00:11 UTC
Message-ID
<Pine.LNX.4.64.0702191601300.20368@woody.linux-foundation.org>
In-Reply-To
<7vwt2d4s6c.fsf@assigned-by-dhcp.cox.net>
On Mon, 19 Feb 2007, Junio C Hamano wrote:
> 
> Hmm.  I am puzzled.  Are you suggesting to change behaviour of
> "git apply" with --index?

Yeah. Or at least _verify_ that the patch is within the subdirectory we are in right now. Right now, we do neither, and it will actually change files outside that subdirectory, which I think is a bit dangerous.

> git generated patch, or patches on the kernel list that are not
> generated with git are always relative to the top-level, so I
> think the current --index behaviour makes tons of sense.

I agree that it is sensible, but it's sensible only within the context of purely self-generated patches, where the patch itself was generated not just with git, but with that exact project.

Imagine somebody sending you a patch to a set of files, and they didn't use git to generate that patch. What would it look right? Right, it might well look like

	diff -u file.c.orig file.c
	--- file.c.orig
	+++ file.c
	@@ -29,6 +29,7 @@
	...
and it happens to be in some subdirectory. What would you do?

I'd use "git apply". And I would be really upset *if* git-apply actually applied the patch to some *other* subdirectory than the one I was in.

(Again, "Makefile" is a common case, since you often have it at multiple levels - maybe it would try to apply the changes to the top-level Makefile, even though I was in the drivers/usb/ subdirectory).

Now, I personally actually always work in the top-level directory, so I don't actually much care. I'm so used to editing the patches themselves that that is what I always end up doing, but I do believe that I'm odd in that. Few enough people have worked with unified diffs for over 15 years, and are perfectly happy to edit not just the headers, but the actual contents too, and fixing up the line numbers to make it all come out right. I do that regularly (not daily, but I probably do it almost once a month - I decide that I like somebody's patch and want to apply it, but fix up some whitespace issue in the patch where he had the opening brace of an "if"-statement on the wrong line etc).

So while I *personally* would probably never be impacted, just because I alway work in the top directory anyway, I do that partly exactly because I'm the top-level maintainer. Somebody who maintains drivers/usb/ might well get patches to a driver that only edits the xyzzy.c and xyzzy.h files within that subdirectory, and it really does make sense that he be able to do "git apply < patch" in that situation.

		Linus
Previous: Junio C HamanoNext: Junio C Hamano
Message 11 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.