Re: Filename quoting / parsing problem
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 1, 2010, 19:50 UTC
- Message-ID
- <7vws01li4c.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <201001011844.23571.agruen@suse.de>
Andreas Gruenbacher <agruen@suse.de> writes:
Show 8 quoted lines
> Git quotes file names as documented in the git-diff manual page: > > TAB, LF, double quote and backslash characters in pathnames are represented > as \t, \n, \" and \\, respectively. If there is need for such substitution > then the whole pathname is put in double quotes. > > Spaces in file names currently do not trigger quoting. (And \r triggers > quoting even though the man page doesn't say so).
Any control character is quoted; the documentation quoted above lists only the common ones that have non-octal representation.
$ git init one
Initialized empty Git repository in /var/tmp/gomi/one/.git/
$ cd one
$ >hello && git add hello && git commit -m 'hello'
[master (root-commit) 5338884] hello
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 hello
$ >'a^Afile' ; >'b file' ; 'c file '
$ git add 'a^Afile' 'b file' 'c file 'In the above sequence that attempts to reproduce the issue, "^A" actually is a byte with value \001 (typically you would type ^V^A to get it from the terminal on the shell). "^G" seems to get "\a" even though it is not in the list (that is why I said "only the common ones" above).
$ git ls-files -s | cat -e
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 "a\001file"$
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 b file$
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 c file $
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 hello$I used "cat -e" to make it easier to see that "c file " not only has SP in it but it has trailing space. Let's try the result.
$ git diff --cached | cat -e
diff --git "a/a\001file" "b/a\001file"$
new file mode 100644$
index 0000000..e69de29$
diff --git a/b file b/b file$
new file mode 100644$
index 0000000..e69de29$
diff --git a/c file b/c file $
new file mode 100644$
index 0000000..e69de29$
$ git diff --cached >P.diffAnd as you described, "b file" and "c file " are not quoted and they do not have ---/+++ lines.
But observe this:
$ git reset --hard
$ ls
P.diff hello
$ git ls-files -s
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 helloWe are now back in the state without any of these files, and P.diff records a patch to recreate these three files, one with quoting and the other two without.
$ git apply --index P.diff
$ git ls-files -s | cat -e
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 "a\001file"$
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 b file$
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 c file $
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 hello$This demonstrates that The claim below is false, doesn't it?
> Not parseable: > diff --git a/baz b/baz > new file mode 100644 > index 0000000..e69de29
Both "b file" and "c file " are parsed by "git apply" perfectly fine.