{"thread":{"id":"8663","subject":"filenames with \" b\" in them create confusing git diff-tree output","startedAt":"2007-06-20T11:15:39Z","lastAt":"2007-06-20T20:50:12Z","messageCount":4,"participants":["Paul Mackerras","Junio C Hamano","Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"45430","messageId":"18041.3163.329391.298926@cargo.ozlabs.ibm.com","threadId":"8663","inReplyTo":null,"subject":"filenames with \" b\" in them create confusing git diff-tree output","fromName":"Paul Mackerras","fromEmail":"paulus@samba.org","sentAt":"2007-06-20T11:15:39Z","receivedAt":"2007-06-20T11:15:39Z","isPatch":false,"sender":{"key":"paulus@samba.org","avatar":"https://avatars.githubusercontent.com/u/1606439?v=4"},"body":"While trying to improve gitk's handling of filenames with spaces, I\nrealised that the header line in git diff-tree's output can be\ninherently ambiguous, since it doesn't put quotes around filenames\nwith spaces (although it does for filenames with other special\ncharacters in them).\n\nFor example:\n\npaulus@quango:~/gitk/testrepo$ mkdir \"test b\"\npaulus@quango:~/gitk/testrepo$ cat >\"test b/foo\"\nstuff\npaulus@quango:~/gitk/testrepo$ git add \"test b/foo\"\npaulus@quango:~/gitk/testrepo$ git commit -a\nCreated commit 71a3074: Add a \"test b\" directory\n 1 files changed, 1 insertions(+), 0 deletions(-)\n create mode 100644 test b/foo\npaulus@quango:~/gitk/testrepo$ git diff-tree -r -p -C HEAD\n71a3074e723c3e5eb599e6b3c47e3267a3cac3bc\ndiff --git a/test b/foo b/test b/foo\nnew file mode 100644\nindex 0000000..f2e4113\n--- /dev/null\n+++ b/test b/foo\n@@ -0,0 +1 @@\n+stuff\n\nNote how there appear to be 4 filenames on the \"diff --git\" line.  At\npresent gitk will interpret that as a diff between \"test\" and\n\"foo b/test b/foo\", since it looks for \" a/\" and \" b/\" to delimit the\nfilenames.  Of course if the file got renamed it could get even more\nconfusing. :)\n\nWould there be any ill effects from quoting filenames with spaces, do\nyou think?  It seems the simplest fix to me (and I will make gitk\nhandle quoted filenames, which it doesn't at present :).\n\nPaul.\n"},{"id":"45435","messageId":"7v4pl2v1lf.fsf@assigned-by-dhcp.pobox.com","threadId":"8663","inReplyTo":"18041.3163.329391.298926@cargo.ozlabs.ibm.com","subject":"Re: filenames with \" b\" in them create confusing git diff-tree output","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-06-20T19:59:40Z","receivedAt":"2007-06-20T19:59:40Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Paul Mackerras <paulus@samba.org> writes:\n\n> paulus@quango:~/gitk/testrepo$ git diff-tree -r -p -C HEAD\n> 71a3074e723c3e5eb599e6b3c47e3267a3cac3bc\n> diff --git a/test b/foo b/test b/foo\n> new file mode 100644\n> index 0000000..f2e4113\n> --- /dev/null\n> +++ b/test b/foo\n> @@ -0,0 +1 @@\n> +stuff\n>\n> Note how there appear to be 4 filenames on the \"diff --git\" line.  At\n> present gitk will interpret that as a diff between \"test\" and\n> \"foo b/test b/foo\", since it looks for \" a/\" and \" b/\" to delimit the\n> filenames.  Of course if the file got renamed it could get even more\n> confusing. :)\n\nYour example, \"a/test b/foo\" vs \"b/test b/foo\", can be and IS\nparsed unambiguously by git-apply (you can try \"git apply\n--stat\" your example).  IOW, the code to correctly handle it\nalready exists ;-)\n\nIf you are seeing a rename/copy you would get explicit rename\nlines between \"diff --git\" header and \"index HEXHEX..HEXHEX\"\nline, what we (i.e. git-apply) do is to make sure the\ninformation we get on the \"diff --git\" header and those on\nrename/copy lines match.  The latter is more reliable, of\ncourse, as they are in strictly one-line-per-filename format,\nand in fact we use the information from there instead of \"diff\n--git\" line for rename patches.  And for non-rename case, you\ncan find all instances of \"b/\", and see if what follows to the\nend of line of which instance of b/ does match what is between\n\"diff --git a/\" and that \"b/\".\n\nIn your example, you have three possible \"b/\" that indicates the\nbeginning of a name:\n\n\tfoo b/test b/foo\n        test b/foo\n        foo\n\nThe leading part after \"diff --git a/\" for the above three\npossibilities are:\n\n\ttest\n        test b/foo\n\ttest b/foo b/test\n\nand you can tell the second one gives the match.\n\n> Would there be any ill effects from quoting filenames with spaces, do\n> you think?\n\nIt is very common (I would not do that personally but I do not\nhave a strong reason to advise against when people want to do\nso) to have a space in filenames.\n"},{"id":"45440","messageId":"alpine.LFD.0.98.0706201315310.3593@woody.linux-foundation.org","threadId":"8663","inReplyTo":"7v4pl2v1lf.fsf@assigned-by-dhcp.pobox.com","subject":"Re: filenames with \" b\" in them create confusing git diff-tree output","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2007-06-20T20:23:12Z","receivedAt":"2007-06-20T20:23:12Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Wed, 20 Jun 2007, Junio C Hamano wrote:\n> \n> Your example, \"a/test b/foo\" vs \"b/test b/foo\", can be and IS\n> parsed unambiguously by git-apply (you can try \"git apply\n> --stat\" your example).  IOW, the code to correctly handle it\n> already exists ;-)\n\nWell, in all fairness, I *did* hate having to write the code to handle all \nthe name handling in git-apply.\n\nEscaping whitespace (or at least giving the _option_ to do so) might well \nbe a good way to not have to be as smart as git-apply is.\n\ngit-apply didn't have that option, since git-apply has as one primary \nmotivation the need to be able to handle patches that come from non-git \nsources, so git-apply goes to quite some extreme lengths to try to make \nsense of an inherently rather ambiguous format (that the git diffs then \n*made* unambiguous, but using pretty subtle rules in order to stay \ncompatible).\n\nSome maybe we should have some generic method of asking for any filename \nto be quoted in particular ways?\n\n\t\tLinus\n"},{"id":"45442","messageId":"7v3b0mtkor.fsf@assigned-by-dhcp.pobox.com","threadId":"8663","inReplyTo":"alpine.LFD.0.98.0706201315310.3593@woody.linux-foundation.org","subject":"Re: filenames with \" b\" in them create confusing git diff-tree output","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-06-20T20:50:12Z","receivedAt":"2007-06-20T20:50:12Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Torvalds <torvalds@linux-foundation.org> writes:\n\n> Some maybe we should have some generic method of asking for any filename \n> to be quoted in particular ways?\n\nProbably, especially if you notice there has been a separate\nthread whose title begins with a word \"Stupid\".\n"}]}