{"thread":{"id":"22589","subject":"[PATCH 1/4] make_absolute_path(): Do not append redundant slash","startedAt":"2010-02-09T17:02:27Z","lastAt":"2010-02-11T12:44:51Z","messageCount":12,"participants":["Nguyễn Thái Ngọc Duy","Johannes Sixt","João Carlos Mendes Luís","Nguyen Thai Ngoc Duy"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"134048","messageId":"1265734950-15145-1-git-send-email-pclouds@gmail.com","threadId":"22589","inReplyTo":null,"subject":"[PATCH 1/4] make_absolute_path(): Do not append redundant slash","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-09T17:02:27Z","receivedAt":"2010-02-09T17:02:27Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"make_absolute_path(\"foo\") at root returns \"//foo\". This patch makes it\nreturn \"/foo\" correctly.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n .. so that \"git init\" will show \"initialized empty Git in /.git\"\n\n abspath.c |    5 +++--\n 1 files changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/abspath.c b/abspath.c\nindex b88122c..e72aede 100644\n--- a/abspath.c\n+++ b/abspath.c\n@@ -54,8 +54,9 @@ const char *make_absolute_path(const char *path)\n \t\t\tif (len + strlen(last_elem) + 2 > PATH_MAX)\n \t\t\t\tdie (\"Too long path name: '%s/%s'\",\n \t\t\t\t\t\tbuf, last_elem);\n-\t\t\tbuf[len] = '/';\n-\t\t\tstrcpy(buf + len + 1, last_elem);\n+\t\t\tif (*buf != '/' || buf[1] != '\\0')\n+\t\t\t\tbuf[len++] = '/';\n+\t\t\tstrcpy(buf + len, last_elem);\n \t\t\tfree(last_elem);\n \t\t\tlast_elem = NULL;\n \t\t}\n-- \n1.7.0.rc2.182.g3adef\n"},{"id":"134049","messageId":"1265734950-15145-2-git-send-email-pclouds@gmail.com","threadId":"22589","inReplyTo":"1265734950-15145-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 2/4] rev-parse: make --git-dir return /.git instead of //.git","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-09T17:02:28Z","receivedAt":"2010-02-09T17:02:28Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-rev-parse.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\nindex a8c5043..9c22cd1 100644\n--- a/builtin-rev-parse.c\n+++ b/builtin-rev-parse.c\n@@ -647,7 +647,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\t}\n \t\t\t\tif (!getcwd(cwd, PATH_MAX))\n \t\t\t\t\tdie_errno(\"unable to get current working directory\");\n-\t\t\t\tprintf(\"%s/.git\\n\", cwd);\n+\t\t\t\tprintf(\"%s%s.git\\n\", cwd, *cwd == '/' && cwd[1] == '\\0' ? \"\" : \"/\");\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--is-inside-git-dir\")) {\n-- \n1.7.0.rc2.182.g3adef\n"},{"id":"134051","messageId":"1265734950-15145-3-git-send-email-pclouds@gmail.com","threadId":"22589","inReplyTo":"1265734950-15145-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 3/4] Support working directory located at root","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-09T17:02:29Z","receivedAt":"2010-02-09T17:02:29Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Git should work regardless where the working directory is located,\neven at root. This patch fixes two places where it assumes working\ndirectory always have parent directory.\n\nIn setup_git_directory_gently(), when Git goes up to root and finds\n.git there, it happily sets worktree to \"\" instead of \"/\".\n\nIn prefix_path(), loosen the outside repo check a little bit. Usually\nwhen a path XXX is inside worktree /foo, it must be either \"/foo\", or\n\"/foo/...\". When worktree is simply \"/\", we can safely ignore the\ncheck: we have a slash at the beginning already.\n\nNot related to worktree, but also set gitdir correctly if a bare repo\nis placed (insanely?) at root.\n\nThanks João Carlos Mendes Luís for pointing out this problem.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n I said I would have code change for DOS drive too. But I take it back.\n Supporting GIT_DIR=C:\\.git might be easy, GIT_DIR=C:.git is not.\n\n setup.c |    6 +++---\n 1 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/setup.c b/setup.c\nindex b38cbee..4d24a74 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -25,7 +25,7 @@ const char *prefix_path(const char *prefix, int len, const char *path)\n \t\tlen = strlen(work_tree);\n \t\ttotal = strlen(sanitized) + 1;\n \t\tif (strncmp(sanitized, work_tree, len) ||\n-\t\t    (sanitized[len] != '\\0' && sanitized[len] != '/')) {\n+\t\t    (len > 1 && sanitized[len] != '\\0' && sanitized[len] != '/')) {\n \t\terror_out:\n \t\t\tdie(\"'%s' is outside repository\", orig);\n \t\t}\n@@ -403,7 +403,7 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \t\t\tif (!work_tree_env)\n \t\t\t\tinside_work_tree = 0;\n \t\t\tif (offset != len) {\n-\t\t\t\tcwd[offset] = '\\0';\n+\t\t\t\tcwd[offset ? offset : 1] = '\\0';\n \t\t\t\tset_git_dir(cwd);\n \t\t\t} else\n \t\t\t\tset_git_dir(\".\");\n@@ -427,7 +427,7 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \tinside_git_dir = 0;\n \tif (!work_tree_env)\n \t\tinside_work_tree = 1;\n-\tgit_work_tree_cfg = xstrndup(cwd, offset);\n+\tgit_work_tree_cfg = xstrndup(cwd, offset ? offset : 1);\n \tif (check_repository_format_gently(nongit_ok))\n \t\treturn NULL;\n \tif (offset == len)\n-- \n1.7.0.rc2.182.g3adef\n"},{"id":"134050","messageId":"1265734950-15145-4-git-send-email-pclouds@gmail.com","threadId":"22589","inReplyTo":"1265734950-15145-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 4/4] Add test for using Git at root of file system","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-09T17:02:30Z","receivedAt":"2010-02-09T17:02:30Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This kind of test requires a throw-away root filesystem so that it can\nplay on. If you have such a system, go ahead, \"chmod 777 /\" and run\nthis test manually (\"make test\" with root permission won't work).\n\nIf you don't but have Linux, static linked busybox, rsync and root\npermission, then run \"t/t1509/prepare-chroot.sh /tmp/test\". You will be\ninstructed to create /dev/null and given a command to chroot into.\nWithin chroot, you will be placed at directory \"t\" of Git source code\nFeel free to burn your chroot.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n May have problem committing. Anyway I don't need commit now.\n\n t/t1509-root-worktree.sh  |  244 +++++++++++++++++++++++++++++++++++++++++++++\n t/t1509/excludes          |   14 +++\n t/t1509/prepare-chroot.sh |   38 +++++++\n 3 files changed, 296 insertions(+), 0 deletions(-)\n create mode 100755 t/t1509-root-worktree.sh\n create mode 100644 t/t1509/excludes\n create mode 100755 t/t1509/prepare-chroot.sh\n\ndiff --git a/t/t1509-root-worktree.sh b/t/t1509-root-worktree.sh\nnew file mode 100755\nindex 0000000..ae01b6d\n--- /dev/null\n+++ b/t/t1509-root-worktree.sh\n@@ -0,0 +1,244 @@\n+#!/bin/sh\n+\n+test_description='Test Git when git repository is located at root\n+\n+This test requires write access in root. Do not bother if you do not\n+have a throwaway chroot or VM.\n+\n+Script t1509/prepare-chroot.sh may help you setup chroot, then you\n+can chroot in and execute this test from there.\n+'\n+\n+. ./test-lib.sh\n+\n+test_cmp_val() {\n+\techo \"$1\" > expected\n+\techo \"$2\" > result\n+\ttest_cmp expected result\n+}\n+\n+test_vars() {\n+\ttest_expect_success \"$1: gitdir\" '\n+\t\ttest_cmp_val \"'\"$2\"'\" \"$(git rev-parse --git-dir)\"\n+\t'\n+\n+\ttest_expect_success \"$1: worktree\" '\n+\t\ttest_cmp_val \"'\"$3\"'\" \"$(git rev-parse --show-toplevel)\"\n+\t'\n+\n+\ttest_expect_success \"$1: prefix\" '\n+\t\ttest_cmp_val \"'\"$4\"'\" \"$(git rev-parse --show-prefix)\"\n+\t'\n+}\n+\n+test_foobar_root() {\n+\ttest_expect_success 'add relative' '\n+\t\ttest -z \"$(cd / && git ls-files)\" &&\n+\t\tgit add foo/foome &&\n+\t\tgit add foo/bar/barme &&\n+\t\tgit add me &&\n+\t\t( cd / && git ls-files --stage ) > result &&\n+\t\ttest_cmp /ls.expected result &&\n+\t\trm \"$(git rev-parse --git-dir)/index\"\n+\t'\n+\n+\ttest_expect_success 'add absolute' '\n+\t\ttest -z \"$(cd / && git ls-files)\" &&\n+\t\tgit add /foo/foome &&\n+\t\tgit add /foo/bar/barme &&\n+\t\tgit add /me &&\n+\t\t( cd / && git ls-files --stage ) > result &&\n+\t\ttest_cmp /ls.expected result &&\n+\t\trm \"$(git rev-parse --git-dir)/index\"\n+\t'\n+\n+}\n+\n+test_foobar_foo() {\n+\ttest_expect_success 'add relative' '\n+\t\ttest -z \"$(cd / && git ls-files)\" &&\n+\t\tgit add foome &&\n+\t\tgit add bar/barme &&\n+\t\tgit add ../me &&\n+\t\t( cd / && git ls-files --stage ) > result &&\n+\t\ttest_cmp /ls.expected result &&\n+\t\trm \"$(git rev-parse --git-dir)/index\"\n+\t'\n+\n+\ttest_expect_success 'add absolute' '\n+\t\ttest -z \"$(cd / && git ls-files)\" &&\n+\t\tgit add /foo/foome &&\n+\t\tgit add /foo/bar/barme &&\n+\t\tgit add /me &&\n+\t\t( cd / && git ls-files --stage ) > result &&\n+\t\ttest_cmp /ls.expected result &&\n+\t\trm \"$(git rev-parse --git-dir)/index\"\n+\t'\n+}\n+\n+test_foobar_foobar() {\n+\ttest_expect_success 'add relative' '\n+\t\ttest -z \"$(cd / && git ls-files)\" &&\n+\t\tgit add ../foome &&\n+\t\tgit add barme &&\n+\t\tgit add ../../me &&\n+\t\t( cd / && git ls-files --stage ) > result &&\n+\t\ttest_cmp /ls.expected result &&\n+\t\trm \"$(git rev-parse --git-dir)/index\"\n+\t'\n+\n+\ttest_expect_success 'add absolute' '\n+\t\ttest -z \"$(cd / && git ls-files)\" &&\n+\t\tgit add /foo/foome &&\n+\t\tgit add /foo/bar/barme &&\n+\t\tgit add /me &&\n+\t\t( cd / && git ls-files --stage ) > result &&\n+\t\ttest_cmp /ls.expected result &&\n+\t\trm \"$(git rev-parse --git-dir)/index\"\n+\t'\n+}\n+\n+if ! test_have_prereq POSIXPERM || ! [ -w / ]; then\n+\tsay \"Dangerous test skipped. Read this test if you want to execute it\"\n+\ttest_done\n+fi\n+\n+if [ \"$IKNOWWHATIAMDOING\" != \"YES\" ]; then\n+\tsay \"You must set env var IKNOWWHATIAMDOING=YES in order to run this test\"\n+\ttest_done\n+fi\n+\n+ONE_SHA1=d00491fd7e5bb6fa28c517a0bb32b8b506539d4d\n+\n+test_expect_success 'setup' '\n+\trm -rf /foo\n+\tmkdir /foo &&\n+\tmkdir /foo/bar &&\n+\techo 1 > /foo/foome &&\n+\techo 1 > /foo/bar/barme &&\n+\techo 1 > /me\n+'\n+\n+say \"GIT_DIR absolute, GIT_WORK_TREE set\"\n+\n+test_expect_success 'go to /' 'cd /'\n+\n+cat >ls.expected <<EOF\n+100644 $ONE_SHA1 0\tfoo/bar/barme\n+100644 $ONE_SHA1 0\tfoo/foome\n+100644 $ONE_SHA1 0\tme\n+EOF\n+\n+export GIT_DIR=\"$TRASH_DIRECTORY/.git\"\n+export GIT_WORK_TREE=/\n+\n+test_vars 'abs gitdir, root' \"$GIT_DIR\" \"/\" \"\"\n+test_foobar_root\n+\n+test_expect_success 'go to /foo' 'cd /foo'\n+\n+test_vars 'abs gitdir, foo' \"$GIT_DIR\" \"/\" \"foo/\"\n+test_foobar_foo\n+\n+test_expect_success 'go to /foo/bar' 'cd /foo/bar'\n+\n+test_vars 'abs gitdir, foo/bar' \"$GIT_DIR\" \"/\" \"foo/bar/\"\n+test_foobar_foobar\n+\n+say \"GIT_DIR relative, GIT_WORK_TREE set\"\n+\n+test_expect_success 'go to /' 'cd /'\n+\n+export GIT_DIR=\"$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git\"\n+export GIT_WORK_TREE=/\n+\n+test_vars 'rel gitdir, root' \"$GIT_DIR\" \"/\" \"\"\n+test_foobar_root\n+\n+test_expect_success 'go to /foo' 'cd /foo'\n+\n+export GIT_DIR=\"../$TRASH_DIRECTORY/.git\"\n+export GIT_WORK_TREE=/\n+\n+test_vars 'rel gitdir, foo' \"$TRASH_DIRECTORY/.git\" \"/\" \"foo/\"\n+test_foobar_foo\n+\n+test_expect_success 'go to /foo/bar' 'cd /foo/bar'\n+\n+export GIT_DIR=\"../../$TRASH_DIRECTORY/.git\"\n+export GIT_WORK_TREE=/\n+\n+test_vars 'rel gitdir, foo/bar' \"$TRASH_DIRECTORY/.git\" \"/\" \"foo/bar/\"\n+test_foobar_foobar\n+\n+say \"GIT_DIR relative, GIT_WORK_TREE relative\"\n+\n+test_expect_success 'go to /' 'cd /'\n+\n+export GIT_DIR=\"$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git\"\n+export GIT_WORK_TREE=.\n+\n+test_vars 'rel gitdir, root' \"$GIT_DIR\" \"/\" \"\"\n+test_foobar_root\n+\n+test_expect_success 'go to /' 'cd /foo'\n+\n+export GIT_DIR=\"../$TRASH_DIRECTORY/.git\"\n+export GIT_WORK_TREE=..\n+\n+test_vars 'rel gitdir, foo' \"$TRASH_DIRECTORY/.git\" \"/\" \"foo/\"\n+test_foobar_foo\n+\n+test_expect_success 'go to /foo/bar' 'cd /foo/bar'\n+\n+export GIT_DIR=\"../../$TRASH_DIRECTORY/.git\"\n+export GIT_WORK_TREE=../..\n+\n+test_vars 'rel gitdir, foo/bar' \"$TRASH_DIRECTORY/.git\" \"/\" \"foo/bar/\"\n+test_foobar_foobar\n+\n+say \".git at root\"\n+\n+unset GIT_DIR\n+unset GIT_WORK_TREE\n+\n+test_expect_success 'go to /' 'cd /'\n+test_expect_success 'setup' '\n+\trm -rf /.git\n+\techo \"Initialized empty Git repository in /.git/\" > expected &&\n+\tgit init > result &&\n+\ttest_cmp expected result\n+'\n+\n+test_vars 'auto gitdir, root' \".git\" \"/\" \"\"\n+test_foobar_root\n+\n+test_expect_success 'go to /foo' 'cd /foo'\n+test_vars 'auto gitdir, foo' \"/.git\" \"/\" \"foo/\"\n+test_foobar_foo\n+\n+test_expect_success 'go to /foo/bar' 'cd /foo/bar'\n+test_vars 'auto gitdir, foo/bar' \"/.git\" \"/\" \"foo/bar/\"\n+test_foobar_foobar\n+\n+test_expect_success 'cleanup' 'rm -rf /.git'\n+\n+say \"auto bare gitdir\"\n+\n+# DESTROYYYYY!!!!!\n+test_expect_failure 'setup' '\n+\trm -rf /refs /objects /info /hooks\n+\trm /*\n+\tcd / &&\n+\techo \"Initialized empty Git repository in /\" > expected &&\n+\tgit init --bare > result &&\n+\ttest_cmp expected result\n+'\n+\n+test_vars 'auto gitdir, root' \".\" \"\" \"\"\n+\n+test_expect_success 'go to /foo' 'cd /foo'\n+\n+test_vars 'auto gitdir, root' \"/\" \"\" \"\"\n+\n+test_done\ndiff --git a/t/t1509/excludes b/t/t1509/excludes\nnew file mode 100644\nindex 0000000..d4d21d3\n--- /dev/null\n+++ b/t/t1509/excludes\n@@ -0,0 +1,14 @@\n+*.o\n+*~\n+*.bak\n+*.c\n+*.h\n+.git\n+contrib\n+Documentation\n+git-gui\n+gitk-git\n+gitweb\n+t/t4013\n+t/t5100\n+t/t5515\ndiff --git a/t/t1509/prepare-chroot.sh b/t/t1509/prepare-chroot.sh\nnew file mode 100755\nindex 0000000..407f2d2\n--- /dev/null\n+++ b/t/t1509/prepare-chroot.sh\n@@ -0,0 +1,38 @@\n+#!/bin/sh\n+\n+die() {\n+\techo >&2 \"$@\"\n+\texit 1\n+}\n+\n+xmkdir() {\n+\twhile [ -n \"$1\" ]; do\n+\t\t[ -d \"$1\" ] || mkdir \"$1\" || die \"Unable to mkdir $1\"\n+\t\tshift\n+\tdone\n+}\n+\n+R=\"$1\"\n+\n+[ -n \"$R\" ] || die \"Usage: prepare-chroot.sh <root>\"\n+[ -x git ] || die \"This script needs to be executed at git source code's top directory\"\n+[ -x /bin/busybox ] || die \"You need busybox\"\n+\n+xmkdir \"$R\" \"$R/bin\" \"$R/etc\" \"$R/lib\" \"$R/dev\"\n+[ -c \"$R/dev/null\" ] || die \"/dev/null is missing. Do mknod $R/dev/null c 1 3 && chmod 666 $R/dev/null\"\n+echo \"root:x:0:0:root:/:/bin/sh\" > \"$R/etc/passwd\"\n+echo \"$(id -nu):x:$(id -u):$(id -g)::$(pwd)/t:/bin/sh\" >> \"$R/etc/passwd\"\n+echo \"root::0:root\" > \"$R/etc/group\"\n+echo \"$(id -ng)::$(id -g):$(id -nu)\" >> \"$R/etc/group\"\n+\n+[ -x \"$R/bin/busybox\" ] || cp /bin/busybox \"$R/bin/busybox\"\n+[ -x \"$R/bin/sh\" ] || ln -s /bin/busybox \"$R/bin/sh\"\n+[ -x \"$R/bin/su\" ] || ln -s /bin/busybox \"$R/bin/su\"\n+\n+mkdir -p \"$R$(pwd)\"\n+rsync --exclude-from t/t1509/excludes -Ha . \"$R$(pwd)\"\n+ldd git | grep '=> /' | sed 's,.* => *\\([^ ]*\\) .*,\\1,' | while read i; do\n+\tmkdir -p \"$R$(dirname $i)\"\n+\tcp \"$i\" \"$R/$i\"\n+done\n+echo \"Execute this in root: 'chroot $R /bin/su - $(id -nu)'\"\n-- \n1.7.0.rc2.182.g3adef\n"},{"id":"134065","messageId":"201002092010.43910.j6t@kdbg.org","threadId":"22589","inReplyTo":"1265734950-15145-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 1/4] make_absolute_path(): Do not append redundant slash","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2010-02-09T19:10:43Z","receivedAt":"2010-02-09T19:10:43Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"On Dienstag, 9. Februar 2010, Nguyễn Thái Ngọc Duy wrote:\n> @@ -54,8 +54,9 @@ const char *make_absolute_path(const char *path)\n>  \t\t\tif (len + strlen(last_elem) + 2 > PATH_MAX)\n>  \t\t\t\tdie (\"Too long path name: '%s/%s'\",\n>  \t\t\t\t\t\tbuf, last_elem);\n> -\t\t\tbuf[len] = '/';\n> -\t\t\tstrcpy(buf + len + 1, last_elem);\n> +\t\t\tif (*buf != '/' || buf[1] != '\\0')\n> +\t\t\t\tbuf[len++] = '/';\n\nHuh? You are adding a slash unless buf is exactly \"/\". That is, when buf \nis \"/foo/\" you still add a slash? That's not exactly avoiding redundancy. \n(Disclaimer: I didn't analyze the rest of the function whether my claim is \ntrue.)\n\n> +\t\t\tstrcpy(buf + len, last_elem);\n>  \t\t\tfree(last_elem);\n>  \t\t\tlast_elem = NULL;\n>  \t\t}\n\n-- Hannes\n"},{"id":"134066","messageId":"201002092018.55951.j6t@kdbg.org","threadId":"22589","inReplyTo":"1265734950-15145-2-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 2/4] rev-parse: make --git-dir return /.git instead of //.git","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2010-02-09T19:18:55Z","receivedAt":"2010-02-09T19:18:55Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"On Dienstag, 9. Februar 2010, Nguyễn Thái Ngọc Duy wrote:\n> @@ -647,7 +647,7 @@ int cmd_rev_parse(int argc, const char **argv, const\n> char *prefix) }\n>  \t\t\t\tif (!getcwd(cwd, PATH_MAX))\n>  \t\t\t\t\tdie_errno(\"unable to get current working directory\");\n> -\t\t\t\tprintf(\"%s/.git\\n\", cwd);\n> +\t\t\t\tprintf(\"%s%s.git\\n\", cwd, *cwd == '/' && cwd[1] == '\\0' ? \"\" : \"/\");\n\nOn Windows, when you are in the root of a drive, then cwd is \"C:/\", i.e. there \nis a trailing slash just as in the Unix root directory. But you do not take \ncare of this situation. That is, you would print \"C://\".\n\nHow about:\n\nstatic inline int is_root_path(const char *path)\n{\n\tif (has_dos_drive_prefix(path))\n\t\tpath += 2;\n\twhile (is_dir_sep(*path))\n\t\tpath++;\n\treturn !*path;\n}\n\nand use it though-out your series?\n\n(Simplify the loop to 'return is_dir_sep(*path) && !path[1];' if you can \nassume that paths are nomalized.)\n\n-- Hannes\n"},{"id":"134069","messageId":"201002092019.45134.j6t@kdbg.org","threadId":"22589","inReplyTo":"1265734950-15145-3-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 3/4] Support working directory located at root","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2010-02-09T19:19:44Z","receivedAt":"2010-02-09T19:19:44Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"On Dienstag, 9. Februar 2010, Nguyễn Thái Ngọc Duy wrote:\n>  I said I would have code change for DOS drive too. But I take it back.\n>  Supporting GIT_DIR=C:\\.git might be easy, GIT_DIR=C:.git is not.\n\nOne does not set GIT_DIR=C:.git; it would be insane because it means \".git in \nan unpredictable directory somewhere on drive C\". It would be great to \nsupport GIT_DIR=C:/.git\n\n-- Hannes\n"},{"id":"134143","messageId":"4B72B035.9080603@jonny.eng.br","threadId":"22589","inReplyTo":"1265734950-15145-4-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 4/4] Add test for using Git at root of file system","fromName":"João Carlos Mendes Luís","fromEmail":"jonny@jonny.eng.br","sentAt":"2010-02-10T13:10:13Z","receivedAt":"2010-02-10T13:10:13Z","isPatch":true,"sender":{"key":"jonny@jonny.eng.br","avatar":"https://gravatar.com/avatar/08e8bcb8e66e4b12bd5d62d2ada030ff3bb15f4a4ca230cc47f90d6218121fbe?d=mp&s=160"},"body":"\n\nNguyễn Thái Ngọc Duy wrote:\n> This kind of test requires a throw-away root filesystem so that it can\n> play on. If you have such a system, go ahead, \"chmod 777 /\" and run\n> this test manually (\"make test\" with root permission won't work).\n>   \n\nI've seen you have a prepare-chroot.sh file in there.  Is it working or \nnot?  I mean, did you create a chrooted environment to test, or there \nwas any problem with that?\n"},{"id":"134212","messageId":"fcaeb9bf1002110200l89f8285k8c27ff916e295ac9@mail.gmail.com","threadId":"22589","inReplyTo":"201002092010.43910.j6t@kdbg.org","subject":"Re: [PATCH 1/4] make_absolute_path(): Do not append redundant slash","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-11T10:00:20Z","receivedAt":"2010-02-11T10:00:20Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Wed, Feb 10, 2010 at 2:10 AM, Johannes Sixt <j6t@kdbg.org> wrote:\n> On Dienstag, 9. Februar 2010, Nguyễn Thái Ngọc Duy wrote:\n>> @@ -54,8 +54,9 @@ const char *make_absolute_path(const char *path)\n>>                       if (len + strlen(last_elem) + 2 > PATH_MAX)\n>>                               die (\"Too long path name: '%s/%s'\",\n>>                                               buf, last_elem);\n>> -                     buf[len] = '/';\n>> -                     strcpy(buf + len + 1, last_elem);\n>> +                     if (*buf != '/' || buf[1] != '\\0')\n>> +                             buf[len++] = '/';\n>\n> Huh? You are adding a slash unless buf is exactly \"/\". That is, when buf\n> is \"/foo/\" you still add a slash? That's not exactly avoiding redundancy.\n> (Disclaimer: I didn't analyze the rest of the function whether my claim is\n> true.)\n\nbuf is set by getcwd() so it should never be \"/foo/\" but doing\n\nif (len && buf[len-1] != '/') buf[len++] = '/';\n\nis probably clearer (and works on Windows too).\n-- \nDuy\n"},{"id":"134213","messageId":"fcaeb9bf1002110201u44e7dbf4r8722152d5f63d51@mail.gmail.com","threadId":"22589","inReplyTo":"4B72B035.9080603@jonny.eng.br","subject":"Re: [PATCH 4/4] Add test for using Git at root of file system","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-11T10:01:53Z","receivedAt":"2010-02-11T10:01:53Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"2010/2/10 João Carlos Mendes Luís <jonny@jonny.eng.br>:\n>\n>\n> Nguyễn Thái Ngọc Duy wrote:\n>>\n>> This kind of test requires a throw-away root filesystem so that it can\n>> play on. If you have such a system, go ahead, \"chmod 777 /\" and run\n>> this test manually (\"make test\" with root permission won't work).\n>>\n>\n> I've seen you have a prepare-chroot.sh file in there.  Is it working or not?\n>  I mean, did you create a chrooted environment to test, or there was any\n> problem with that?\n\nThat means if you already have a chroot environment, use it. Or you\ncan use prepare-chroot.sh to create a new chroot environment. Yes I\nused prepare-chroot.sh for my testing.\n-- \nDuy\n"},{"id":"134214","messageId":"fcaeb9bf1002110207i54366c2doa5ca951d2e87876d@mail.gmail.com","threadId":"22589","inReplyTo":"201002092018.55951.j6t@kdbg.org","subject":"Re: [PATCH 2/4] rev-parse: make --git-dir return /.git instead of //.git","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-11T10:07:22Z","receivedAt":"2010-02-11T10:07:22Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Wed, Feb 10, 2010 at 2:18 AM, Johannes Sixt <j6t@kdbg.org> wrote:\n> On Dienstag, 9. Februar 2010, Nguyễn Thái Ngọc Duy wrote:\n>> @@ -647,7 +647,7 @@ int cmd_rev_parse(int argc, const char **argv, const\n>> char *prefix) }\n>>                               if (!getcwd(cwd, PATH_MAX))\n>>                                       die_errno(\"unable to get current working directory\");\n>> -                             printf(\"%s/.git\\n\", cwd);\n>> +                             printf(\"%s%s.git\\n\", cwd, *cwd == '/' && cwd[1] == '\\0' ? \"\" : \"/\");\n>\n> On Windows, when you are in the root of a drive, then cwd is \"C:/\", i.e. there\n> is a trailing slash just as in the Unix root directory. But you do not take\n> care of this situation. That is, you would print \"C://\".\n>\n> How about:\n>\n> static inline int is_root_path(const char *path)\n> {\n>        if (has_dos_drive_prefix(path))\n>                path += 2;\n>        while (is_dir_sep(*path))\n>                path++;\n>        return !*path;\n> }\n>\n> and use it though-out your series?\n>\n> (Simplify the loop to 'return is_dir_sep(*path) && !path[1];' if you can\n> assume that paths are nomalized.)\n\nAnd return the length of root_path, so that I can use this function in\nin setup_git_directory_gently() too. Yeah.\n-- \nDuy\n"},{"id":"134219","messageId":"fcaeb9bf1002110444v4ada90f5t8fd7d9163956c9f3@mail.gmail.com","threadId":"22589","inReplyTo":"201002092019.45134.j6t@kdbg.org","subject":"Re: [PATCH 3/4] Support working directory located at root","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-11T12:44:51Z","receivedAt":"2010-02-11T12:44:51Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On 2/10/10, Johannes Sixt <j6t@kdbg.org> wrote:\n> On Dienstag, 9. Februar 2010, Nguyễn Thái Ngọc Duy wrote:\n>  >  I said I would have code change for DOS drive too. But I take it back.\n>  >  Supporting GIT_DIR=C:\\.git might be easy, GIT_DIR=C:.git is not.\n>\n>\n> One does not set GIT_DIR=C:.git; it would be insane because it means \".git in\n>  an unpredictable directory somewhere on drive C\". It would be great to\n>  support GIT_DIR=C:/.git\n\nA bit off topic, but make_relative_path() may need more care for the\nWindows port. I thought of making relative path between C:/foo and\nD:/bar but it should work well for that case. //machine/share1/foo and\n//machine/share2/bar may fail though.\n-- \nDuy\n"}]}