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

Filenames and prefixes in extended diffs

From
AGAndreas Gruenbacher <agruen@suse.de>
Date
Jan 13, 2010, 16:13 UTC
Message-ID
<201001131713.05505.agruen@suse.de>

I'm having a problem filename prefixes in git's extended diffs for patches which rename or copy files: those patches include the old and new filenames in "rename from", "rename to", "copy from", and "copy to" headers, e.g.,

	$ git show -M
	diff --git a/f b/g
	similarity index 87%
	rename from f
	rename to g
	index f00c965..3bb459b 100644
	--- a/f
	+++ b/g
	@@ -8,3 +8,4 @@
	 8
	 9
	 10
	+11

Unlike the filenames in the "diff --git", "---", and "+++" headers, the "rename from", "rename to", "copy from", and "copy to" filenames do not include prefixes.

Now when applying a patch, GNU patch's -p option determines the number of pathname components to strip off from filenames. This obviously can't work consistently for the prefixed and prefix-less headers.

Can git be changed to include prefixes in all filenames?

The only alternative I see is to ignore the filenames in the rename/copy headers and rely only on the "diff --git" line. (The "---" and "+++" headers are not guaranteed to exist.) What's worse, as already discussed here, the "diff --git" line uses space as a separator between filenames yet it doesn't quote spaces in filenames. When being forced to ignore rename/copy headers, this defect would make things much worse.

Any ideas?

Thanks, Andreas

Next: Junio C Hamano
Message 1 of 20 in “Filenames and prefixes in extended diffs”
  1. Andreas GruenbacherJan 13, 2010
  2. Junio C HamanoJan 13, 2010
  3. Junio C HamanoJan 14, 2010
  4. Nanako ShiraishiJan 15, 2010
  5. Junio C HamanoJan 15, 2010
  6. grep: prepare to run outside of a work treeJunio C Hamano, Jan 15, 2010
  7. grep --no-index: allow use of "git grep" outside a git repositoryJunio C Hamano, Jan 15, 2010
  8. Jeff KingJan 15, 2010
  9. Junio C HamanoJan 16, 2010
  10. Jeff KingJan 16, 2010
  11. Junio C HamanoJan 16, 2010
  12. David AguilarJan 16, 2010
  13. Junio C HamanoJan 16, 2010
  14. Jeff KingJan 18, 2010
  15. Junio C HamanoJan 18, 2010
  16. Junio C HamanoJan 18, 2010
  17. Jeff KingJan 18, 2010
  18. Junio C HamanoJan 18, 2010
  19. Jeff KingJan 18, 2010
  20. Andreas GruenbacherJan 18, 2010

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.