{"thread":{"id":"19244","subject":"[PATCH] Disallow '\\' in ref names","startedAt":"2009-05-08T05:32:37Z","lastAt":"2009-05-08T08:04:28Z","messageCount":6,"participants":["Robin Rosenberg","Andreas Ericsson","Johannes Sixt","Michael J Gruber"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"113304","messageId":"1241760757-26068-1-git-send-email-robin.rosenberg@dewire.com","threadId":"19244","inReplyTo":null,"subject":"[PATCH] Disallow '\\' in ref names","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2009-05-08T05:32:37Z","receivedAt":"2009-05-08T05:32:37Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"This is asking for trouble since '\\' is a directory separator in\nWindows and thus may produce unpredictable results.\n\nSigned-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\n---\n Documentation/git-check-ref-format.txt |    2 ++\n refs.c                                 |    3 ++-\n 2 files changed, 4 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git-check-ref-format.txt b/Documentation/git-check-ref-format.txt\nindex c1ce268..4884520 100644\n--- a/Documentation/git-check-ref-format.txt\n+++ b/Documentation/git-check-ref-format.txt\n@@ -38,6 +38,8 @@ imposes the following rules on how references are named:\n \n . They cannot contain a sequence `@{`.\n \n+- They cannot contain a `\\\\`\n+\n These rules make it easy for shell script based tools to parse\n reference names, pathname expansion by the shell when a reference name is used\n unquoted (by mistake), and also avoids ambiguities in certain\ndiff --git a/refs.c b/refs.c\nindex e65a3b4..fc33bc6 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -682,12 +682,13 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)\n  * - it has ASCII control character, \"~\", \"^\", \":\" or SP, anywhere, or\n  * - it ends with a \"/\".\n  * - it ends with \".lock\"\n+ * - it contains a \"\\\" (backslash)\n  */\n \n static inline int bad_ref_char(int ch)\n {\n \tif (((unsigned) ch) <= ' ' ||\n-\t    ch == '~' || ch == '^' || ch == ':')\n+\t    ch == '~' || ch == '^' || ch == ':' || ch == '\\\\')\n \t\treturn 1;\n \t/* 2.13 Pattern Matching Notation */\n \tif (ch == '?' || ch == '[') /* Unsupported */\n-- \n1.6.3.dirty\n"},{"id":"113311","messageId":"4A03D776.6070309@op5.se","threadId":"19244","inReplyTo":"1241760757-26068-1-git-send-email-robin.rosenberg@dewire.com","subject":"Re: [PATCH] Disallow '\\' in ref names","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2009-05-08T06:55:50Z","receivedAt":"2009-05-08T06:55:50Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Robin Rosenberg wrote:\n> This is asking for trouble since '\\' is a directory separator in\n> Windows and thus may produce unpredictable results.\n> \n\nNAK. We allow / on unixy systems, and that's the path separator there.\nJunio even makes extensive use of it to create per-contributor\nnamespaces for topic-branches.\n\nAre you guessing this might be a problem in the future, or have you\nactually run into it?\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n\nRegister now for Nordic Meet on Nagios, June 3-4 in Stockholm\n http://nordicmeetonnagios.op5.org/\n\nConsidering the successes of the wars on alcohol, poverty, drugs and\nterror, I think we should give some serious thought to declaring war\non peace.\n"},{"id":"113313","messageId":"4A03DC9C.2050204@viscovery.net","threadId":"19244","inReplyTo":"4A03D776.6070309@op5.se","subject":"Re: [PATCH] Disallow '\\' in ref names","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2009-05-08T07:17:48Z","receivedAt":"2009-05-08T07:17:48Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Andreas Ericsson schrieb:\n> Robin Rosenberg wrote:\n>> This is asking for trouble since '\\' is a directory separator in\n>> Windows and thus may produce unpredictable results.\n>>\n> \n> NAK. We allow / on unixy systems, and that's the path separator there.\n> Junio even makes extensive use of it to create per-contributor\n> namespaces for topic-branches.\n> \n> Are you guessing this might be a problem in the future, or have you\n> actually run into it?\n\nThis is not possible on Windows:\n\n$ git update-ref refs/heads/foo\\bar HEAD\nfatal: Unable to create '.git/refs/heads/foo\\bar.lock': No such file or\ndirectory\n\nThe problem is that git doesn't create the directory .git/refs/heads/foo\nbecause the ref handling only mkdir()s directories that were split off\nfrom the ref at forward-slashes.\n\nThe decision not to mangle command line arguments that are refs (on\nWindows) was intentional. (We do mangle pathspec, i.e. we convert '\\' to\n'/'.) But back then I did not think about what should happen if a ref\ncontains a backslash.\n\nBTW, it's the same problem with backslash in path components: Just don't\ndo that if you want to be cross-platfrom.\n\n-- Hannes\n"},{"id":"113318","messageId":"4A03E343.4020000@op5.se","threadId":"19244","inReplyTo":"4A03DC9C.2050204@viscovery.net","subject":"Re: [PATCH] Disallow '\\' in ref names","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2009-05-08T07:46:11Z","receivedAt":"2009-05-08T07:46:11Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Johannes Sixt wrote:\n> Andreas Ericsson schrieb:\n>> Robin Rosenberg wrote:\n>>> This is asking for trouble since '\\' is a directory separator in\n>>> Windows and thus may produce unpredictable results.\n>>>\n>> NAK. We allow / on unixy systems, and that's the path separator there.\n>> Junio even makes extensive use of it to create per-contributor\n>> namespaces for topic-branches.\n>>\n>> Are you guessing this might be a problem in the future, or have you\n>> actually run into it?\n> \n> This is not possible on Windows:\n> \n> $ git update-ref refs/heads/foo\\bar HEAD\n> fatal: Unable to create '.git/refs/heads/foo\\bar.lock': No such file or\n> directory\n> \n> The problem is that git doesn't create the directory .git/refs/heads/foo\n> because the ref handling only mkdir()s directories that were split off\n> from the ref at forward-slashes.\n> \n\nOk. Isn't the slash -> backslash conversion thing supposed to be done by\na macro? I seem to remember something about PATH_DELIM.\n\n> The decision not to mangle command line arguments that are refs (on\n> Windows) was intentional. (We do mangle pathspec, i.e. we convert '\\' to\n> '/'.) But back then I did not think about what should happen if a ref\n> contains a backslash.\n> \n\nBut what about when locating directory cutoffs for mkdir() stuff?\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n\nRegister now for Nordic Meet on Nagios, June 3-4 in Stockholm\n http://nordicmeetonnagios.op5.org/\n\nConsidering the successes of the wars on alcohol, poverty, drugs and\nterror, I think we should give some serious thought to declaring war\non peace.\n"},{"id":"113321","messageId":"4A03E551.8080904@drmicha.warpmail.net","threadId":"19244","inReplyTo":"1241760757-26068-1-git-send-email-robin.rosenberg@dewire.com","subject":"Re: [PATCH] Disallow '\\' in ref names","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2009-05-08T07:54:57Z","receivedAt":"2009-05-08T07:54:57Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Robin Rosenberg venit, vidit, dixit 08.05.2009 07:32:\n> This is asking for trouble since '\\' is a directory separator in\n> Windows and thus may produce unpredictable results.\n> \n> Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\n> ---\n>  Documentation/git-check-ref-format.txt |    2 ++\n>  refs.c                                 |    3 ++-\n>  2 files changed, 4 insertions(+), 1 deletions(-)\n> \n> diff --git a/Documentation/git-check-ref-format.txt b/Documentation/git-check-ref-format.txt\n> index c1ce268..4884520 100644\n> --- a/Documentation/git-check-ref-format.txt\n> +++ b/Documentation/git-check-ref-format.txt\n> @@ -38,6 +38,8 @@ imposes the following rules on how references are named:\n>  \n>  . They cannot contain a sequence `@{`.\n>  \n> +- They cannot contain a `\\\\`\n\nMinor nit from the doc watch dog:\n\n+. They cannot contain a `\\\\`.\n\n> +\n>  These rules make it easy for shell script based tools to parse\n>  reference names, pathname expansion by the shell when a reference name is used\n>  unquoted (by mistake), and also avoids ambiguities in certain\n> diff --git a/refs.c b/refs.c\n> index e65a3b4..fc33bc6 100644\n> --- a/refs.c\n> +++ b/refs.c\n> @@ -682,12 +682,13 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)\n>   * - it has ASCII control character, \"~\", \"^\", \":\" or SP, anywhere, or\n>   * - it ends with a \"/\".\n>   * - it ends with \".lock\"\n> + * - it contains a \"\\\" (backslash)\n>   */\n>  \n>  static inline int bad_ref_char(int ch)\n>  {\n>  \tif (((unsigned) ch) <= ' ' ||\n> -\t    ch == '~' || ch == '^' || ch == ':')\n> +\t    ch == '~' || ch == '^' || ch == ':' || ch == '\\\\')\n>  \t\treturn 1;\n>  \t/* 2.13 Pattern Matching Notation */\n>  \tif (ch == '?' || ch == '[') /* Unsupported */\n"},{"id":"113323","messageId":"4A03E78C.8000801@viscovery.net","threadId":"19244","inReplyTo":"4A03E343.4020000@op5.se","subject":"Re: [PATCH] Disallow '\\' in ref names","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2009-05-08T08:04:28Z","receivedAt":"2009-05-08T08:04:28Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Andreas Ericsson schrieb:\n> Johannes Sixt wrote:\n>> Andreas Ericsson schrieb:\n>>> Robin Rosenberg wrote:\n>>>> This is asking for trouble since '\\' is a directory separator in\n>>>> Windows and thus may produce unpredictable results.\n>>>>\n>>> NAK. We allow / on unixy systems, and that's the path separator there.\n>>> Junio even makes extensive use of it to create per-contributor\n>>> namespaces for topic-branches.\n>>>\n>>> Are you guessing this might be a problem in the future, or have you\n>>> actually run into it?\n>>\n>> This is not possible on Windows:\n>>\n>> $ git update-ref refs/heads/foo\\bar HEAD\n>> fatal: Unable to create '.git/refs/heads/foo\\bar.lock': No such file or\n>> directory\n>>\n>> The problem is that git doesn't create the directory .git/refs/heads/foo\n>> because the ref handling only mkdir()s directories that were split off\n>> from the ref at forward-slashes.\n>>\n> \n> Ok. Isn't the slash -> backslash conversion thing supposed to be done by\n> a macro? I seem to remember something about PATH_DELIM.\n\nIt is is_dir_sep(). This macro is only used with pathspec, not with refs.\nTherefore, backslashes in refs enter git unaltered and cause havoc on\nWindows because git internally only knows how to treat forward-slashes in\nrefs in a special way.\n\nNote that using is_dir_sep() in refs is not a solution because then refs\nthat were read from the file system would be reported with a forward-slash.\n\n>> The decision not to mangle command line arguments that are refs (on\n>> Windows) was intentional. (We do mangle pathspec, i.e. we convert '\\' to\n>> '/'.) But back then I did not think about what should happen if a ref\n>> contains a backslash.\n> \n> But what about when locating directory cutoffs for mkdir() stuff?\n\nI can't parse your statement. ;)\n\n-- Hannes\n"}]}