Re: Filename quoting / parsing problem
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:47:58
Andreas Gruenbacher [off-list ref] 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.