{"thread":{"id":"25791","subject":"Re: [PATCH] get_cwd_relative(): do not misinterpret root path","startedAt":"2010-11-19T20:41:59Z","lastAt":"2010-11-20T06:50:51Z","messageCount":2,"participants":["Clemens Buchacher","Nguyễn Thái Ngọc Duy"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"156208","messageId":"20101119204159.GA28622@localhost","threadId":"25791","inReplyTo":"1290158239-12138-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] get_cwd_relative(): do not misinterpret root path","fromName":"Clemens Buchacher","fromEmail":"drizzd@aon.at","sentAt":"2010-11-19T20:41:59Z","receivedAt":"2010-11-19T20:41:59Z","isPatch":true,"sender":{"key":"drizzd@gmx.net","avatar":"https://avatars.githubusercontent.com/u/59082?v=4"},"body":"Hi Duy,\n\nThanks for looking into this.\n\nOn Fri, Nov 19, 2010 at 04:17:19PM +0700, Nguyễn Thái Ngọc Duy wrote:\n> \n> @@ -965,6 +965,12 @@ char *get_relative_cwd(char *buffer, int size, const char *dir)\n>  \tcase '/':\n>  \t\treturn cwd + 1;\n>  \tdefault:\n> +\t\t/*\n> +\t\t * dir can end with a path separator when it's root\n> +\t\t * directory. Return proper prefix in that case.\n> +\t\t */\n> +\t\tif (is_dir_sep(dir[-1]))\n> +\t\t\treturn cwd;\n>  \t\treturn NULL;\n>  \t}\n>  }\n\nmake_absolute_path() already rewrites dir to contain slashes only.\nI think it is confusing to use is_dir_sep() here, when we only\ncheck for / above.\n\nOtherwise, the patch looks good to me.\n\nClemens\n"},{"id":"156250","messageId":"1290235851-23276-1-git-send-email-pclouds@gmail.com","threadId":"25791","inReplyTo":"20101119204159.GA28622@localhost","subject":"[PATCH v2] get_cwd_relative(): do not misinterpret root path","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-11-20T06:50:51Z","receivedAt":"2010-11-20T06:50:51Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Commit 490544b (get_cwd_relative(): do not misinterpret suffix as\nsubdirectory) handles case where:\n\ndir = \"/path/work\";\ncwd = \"/path/work-xyz\";\n\nWhen it comes to the end of get_cwd_relative(), dir is at '\\0' and cwd\nis at '-'. The rest of cwd, \"-xyz\", clearly cannot be the relative\npath from dir to cwd. However there is another case where:\n\ndir = \"/\";          /* or even \"c:/\" */\ncwd = \"/path/to/here\";\n\nIn this special case, while *cwd == 'p', which is not a path\nseparator, the rest of cwd, \"path/to/here\", can be returned as a\nrelative path from dir to cwd.\n\nHandle this case and make t1509 pass again.\n\nReported-by: Albert Strasheim <fullung@gmail.com>\nReported-by: Matthijs Kooijman <matthijs@stdin.nl>\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n 2010/11/20 Clemens Buchacher <drizzd@aon.at>:\n > make_absolute_path() already rewrites dir to contain slashes only.\n > I think it is confusing to use is_dir_sep() here, when we only\n > check for / above.\n\n I was thinking about GIT_WORK_TREE=\"c:\\\" (so dir would be \"c:\\\") when\n I wrote that. It is recognized as absolute path, no normalization\n will be done.\n\n But then the comparison part earlier in this function would fail because\n getcwd in Windows port always return '/'.\n\n I will make a patch to convert GIT_WORK_TREE (and GIT_DIR too?) to '/'\n so everything is consistent.\n\n dir.c |    6 ++++++\n 1 files changed, 6 insertions(+), 0 deletions(-)\n\ndiff --git a/dir.c b/dir.c\nindex b2dfb69..b687504 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -965,6 +965,12 @@ char *get_relative_cwd(char *buffer, int size, const char *dir)\n \tcase '/':\n \t\treturn cwd + 1;\n \tdefault:\n+\t\t/*\n+\t\t * dir can end with a path separator when it's root\n+\t\t * directory. Return proper prefix in that case.\n+\t\t */\n+\t\tif (dir[-1] == '/')\n+\t\t\treturn cwd;\n \t\treturn NULL;\n \t}\n }\n-- \n1.7.3.2.316.gda8b3\n"}]}