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

Re: git full diff output issues..

From
Junio C Hamano <junkio@cox.net>
Date
Jun 5, 2005, 08:46 UTC
Message-ID
<7vu0kd42dm.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7v64x5bt9n.fsf@assigned-by-dhcp.cox.net>
>>>>> "JCH" == Junio C Hamano <junkio@cox.net> writes:
>>>>> "LT" == Linus Torvalds <torvalds@osdl.org> writes:
LT> This means, btw, that the "git --diff" format must _not_ do

LT> diff --git a/file /dev/null LT> deleted file mode 100644

JCH> I just checked, and both built-in and git-external-diff-script JCH> should be safe about this issue.

Sorry, I spoke too soon about a week and half ago X-<, and I am bugging you about this because this clearly belongs to "fix" category not "new stuff".

The case you mentioned (i.e. /dev/null) is fine but rename/copy is "broken" according to the definition by git-apply.

What do you want the diff-patch format to say for this one?
    :100644 100644 SHA1-OLD SHA1-NEW R frotz.c nitfol.c
Currently I am saying:
    diff --git a/frotz.c b/nitfol.c
    similarity index 89%
    rename old frotz.c
    rename new nitfol.c
    --- a/frotz.c
    +++ b/nitfol.c
    @@ ...

and this makes git-apply barf, because a/ and b/ names are different. Is the following what you want? That is, do you always want p->two->path (name in the right hand side tree)?

    diff --git a/nitfol.c b/nitfol.c
    similarity index 89%
    rename old frotz.c
    rename new nitfol.c
    --- a/frotz.c
    +++ b/nitfol.c
    @@ ...

According to the current apply.c, git_header_name() does not care as long as a/ and b/ names are the same (that is, I could even say "diff --git a/junkio b/junkio" to make it grok the above example, as long as I have the correct "rename old" and "rename new" in the extended header part). In that sense, it all boils down to which name you, as a human consumer of the patch, would want to see on the header, if we go the route of making a/ and b/ name always the same. However I suspect that this slightly breaks patch reversibility.

If we do care about patch reversibility, having a/ and b/ names to show the pre- and post- paths like my current output does (which _does_ break the current apply.c name checking) is probably the most sensible thing to keep things symmetric. I am not sure if it is worth it to make the name checking logic in apply.c more complicated only to support this rename symmetry, though.

Another possibility; since "diff --git" is a git-specific header format anyway, we could quote things to help apply.c parsing it, without introducing too much clutter for ordinary cases. How about taking advantage of the fact that most pathnames do not contain spaces nor backslashes, and if we see them we simply quote, like this?

    # no need for quote
    diff --git a/frotz.c b/nitfol.c
    rename old frotz.c
    rename new nitfol.c
    
    # patch for "frotz and nitfol.c"
    diff --git a/frotz\ and\ nitfol.c b/frotz\ and\ nitfol.c
    # rename but filename has spaces and a backslash
    diff --git a/old\ name\\with\ bs b/new\ name\\with\ bs
    rename old old name\with bs
    rename new new name\with bs
Previous: Junio C HamanoNext: Linus Torvalds
Message 10 of 13 in “git full diff output issues..”
  1. Linus TorvaldsMay 26, 2005
  2. Linus TorvaldsMay 26, 2005
  3. Junio C HamanoMay 26, 2005
  4. Junio C HamanoMay 26, 2005
  5. Anton AltaparmakovMay 26, 2005
  6. Linus TorvaldsMay 26, 2005
  7. Junio C HamanoMay 26, 2005
  8. Linus TorvaldsMay 26, 2005
  9. Junio C HamanoMay 26, 2005
  10. Junio C HamanoJun 5, 2005
  11. Linus TorvaldsJun 5, 2005
  12. Chris WedgwoodMay 26, 2005
  13. Linus TorvaldsMay 26, 2005

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.