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

Re: Filename quoting / parsing problem

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 6, 2010, 01:08 UTC
Message-ID
<7viqbgniq1.fsf@alter.siamese.dyndns.org>
In-Reply-To
<201001022148.47841.agruen@suse.de>
Andreas Gruenbacher <agruen@suse.de> writes:
> Right now, git generates lines like "diff --git a/f a/f b/f b/f" in some 
> corner cases, and from such lines alone, it is not possible to tell what the 
> two file names are (either "a/f a/f" and "b/f b/f", or "a/f a/f b/f" and 
> "b/f").  I can only find that out by looking at the other header lines.

I would understand "a/f a/f b/f a/f", which would be a diff of "f a/f" between two versions.

"a/f a/f b/f b/f" could be rename from "f /a/f" to "f b/f" (or "f a/f b/f" to "f"). But you will always get "rename from" and "rename to" in that case.

So you can (and I think git-apply does) follow this simple rule:
    If you see +++/---/rename from/rename to/new file/deleted file, use
    the names you find there.  Otherwise, because there is no rename,
    "diff --git" lines has two identical names that follow a/ and b/, so
    use that name.

The parsing code in builtin-apply.c is not so dense; you should be able to lift it from there, I think.

Although an output of "a/f a/f b/f b/f" without "rename from/to" is possible with --no-index of two unrelated files, --no-index output is not even something that is meant to be appliable, so I wouldn't worry too much about it.

Previous: Junio C HamanoNext: Andreas Schwab
Message 9 of 10 in “Filename quoting / parsing problem”
  1. Andreas GruenbacherJan 1, 2010
  2. Junio C HamanoJan 1, 2010
  3. Junio C HamanoJan 1, 2010
  4. Andreas GruenbacherJan 2, 2010
  5. Junio C HamanoJan 2, 2010
  6. Andreas GruenbacherJan 2, 2010
  7. Andreas GruenbacherJan 6, 2010
  8. Junio C HamanoJan 6, 2010
  9. Junio C HamanoJan 6, 2010
  10. Andreas SchwabJan 6, 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.