{"thread":{"id":"22952","subject":"[PATCH 1/3] worktree setup: calculate prefix even if no worktree is found","startedAt":"2010-03-08T16:50:31Z","lastAt":"2010-03-08T16:50:33Z","messageCount":3,"participants":["Nguyễn Thái Ngọc Duy"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"136395","messageId":"1268067033-25199-1-git-send-email-pclouds@gmail.com","threadId":"22952","inReplyTo":null,"subject":"[PATCH 1/3] worktree setup: calculate prefix even if no worktree is found","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-03-08T16:50:31Z","receivedAt":"2010-03-08T16:50:31Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Commit a672ea6 (rehabilitate 'git index-pack' inside the object\nstore - 2008-10-20) worked around a fault in\nsetup_git_directory_gently(). When walking up from inside a git\nrepository, we will return NULL as prefix.  We should have returned a\ncorrect prefix anyway because cwd has been moved.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n I missed index-pack in my RUN_SETUP_GENTLY series. So three more patches\n on top.\n\n setup.c              |   19 ++++++++-----------\n t/t1500-rev-parse.sh |    2 +-\n t/t1501-worktree.sh  |    5 +++++\n 3 files changed, 14 insertions(+), 12 deletions(-)\n\ndiff --git a/setup.c b/setup.c\nindex bb3648c..8796c6f 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -392,13 +392,16 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)\n \toffset = len = strlen(cwd);\n \tfor (;;) {\n \t\tgitfile_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);\n-\t\tif (gitfile_dir) {\n-\t\t\tif (set_git_dir(gitfile_dir))\n+\t\tif (gitfile_dir || is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT)) {\n+\t\t\tif (gitfile_dir && set_git_dir(gitfile_dir))\n \t\t\t\tdie(\"Repository setup failed\");\n+\t\t\tinside_git_dir = 0;\n+\t\t\tif (!work_tree_env)\n+\t\t\t\tinside_work_tree = 1;\n+\t\t\troot_len = offset_1st_component(cwd);\n+\t\t\tgit_work_tree_cfg = xstrndup(cwd, offset > root_len ? offset : root_len);\n \t\t\tbreak;\n \t\t}\n-\t\tif (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT))\n-\t\t\tbreak;\n \t\tif (is_git_directory(\".\")) {\n \t\t\tinside_git_dir = 1;\n \t\t\tif (!work_tree_env)\n@@ -409,8 +412,7 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)\n \t\t\t\tset_git_dir(cwd);\n \t\t\t} else\n \t\t\t\tset_git_dir(\".\");\n-\t\t\tcheck_repository_format_gently(nongit_ok);\n-\t\t\treturn NULL;\n+\t\t\tbreak;\n \t\t}\n \t\twhile (--offset > ceil_offset && cwd[offset] != '/');\n \t\tif (offset <= ceil_offset) {\n@@ -426,11 +428,6 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)\n \t\t\tdie_errno(\"Cannot change to '%s/..'\", cwd);\n \t}\n \n-\tinside_git_dir = 0;\n-\tif (!work_tree_env)\n-\t\tinside_work_tree = 1;\n-\troot_len = offset_1st_component(cwd);\n-\tgit_work_tree_cfg = xstrndup(cwd, offset > root_len ? offset : root_len);\n \tif (check_repository_format_gently(nongit_ok))\n \t\treturn NULL;\n \tif (offset == len)\ndiff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh\nindex 48ee077..4ee92c7 100755\n--- a/t/t1500-rev-parse.sh\n+++ b/t/t1500-rev-parse.sh\n@@ -42,7 +42,7 @@ test_rev_parse toplevel false false true '' .git\n cd .git || exit 1\n test_rev_parse .git/ false true false '' .\n cd objects || exit 1\n-test_rev_parse .git/objects/ false true false '' \"$ROOT/.git\"\n+test_rev_parse .git/objects/ false true false 'objects/' \"$ROOT/.git\"\n cd ../.. || exit 1\n \n mkdir -p sub/dir || exit 1\ndiff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh\nindex 9df3012..c72b578 100755\n--- a/t/t1501-worktree.sh\n+++ b/t/t1501-worktree.sh\n@@ -28,6 +28,11 @@ test_rev_parse() {\n \t[ $# -eq 0 ] && return\n }\n \n+cd .git/objects || exit 1\n+say \"subdirectory inside .git\"\n+test_rev_parse 'inside'       false true false objects/\n+cd ../.. || exit 1\n+\n EMPTY_TREE=$(git write-tree)\n mkdir -p work/sub/dir || exit 1\n mv .git repo.git || exit 1\n-- \n1.7.0.1.384.g6abcaa\n"},{"id":"136396","messageId":"1268067033-25199-2-git-send-email-pclouds@gmail.com","threadId":"22952","inReplyTo":"1268067033-25199-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 2/3] index-pack: trust the prefix returned by setup_git_directory_gently()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-03-08T16:50:32Z","receivedAt":"2010-03-08T16:50:32Z","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/index-pack.c |   21 ++++++---------------\n 1 files changed, 6 insertions(+), 15 deletions(-)\n\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex b4cf8c5..2a6359d 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -879,29 +879,20 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)\n \tchar *index_name_buf = NULL, *keep_name_buf = NULL;\n \tstruct pack_idx_entry **idx_objects;\n \tunsigned char pack_sha1[20];\n+\tint nongit;\n \n \tif (argc == 2 && !strcmp(argv[1], \"-h\"))\n \t\tusage(index_pack_usage);\n \n \t/*\n-\t * We wish to read the repository's config file if any, and\n-\t * for that it is necessary to call setup_git_directory_gently().\n+\t * We wish to read the repository's config file if any.\n \t * However if the cwd was inside .git/objects/pack/ then we need\n \t * to go back there or all the pack name arguments will be wrong.\n-\t * And in that case we cannot rely on any prefix returned by\n-\t * setup_git_directory_gently() either.\n \t */\n-\t{\n-\t\tchar cwd[PATH_MAX+1];\n-\t\tint nongit;\n-\n-\t\tif (!getcwd(cwd, sizeof(cwd)-1))\n-\t\t\tdie(\"Unable to get current working directory\");\n-\t\tsetup_git_directory_gently(&nongit);\n-\t\tgit_config(git_index_pack_config, NULL);\n-\t\tif (chdir(cwd))\n-\t\t\tdie(\"Cannot come back to cwd\");\n-\t}\n+\tprefix = setup_git_directory_gently(&nongit);\n+\tgit_config(git_index_pack_config, NULL);\n+\tif (prefix && chdir(prefix))\n+\t\tdie(\"Cannot come back to cwd\");\n \n \tfor (i = 1; i < argc; i++) {\n \t\tconst char *arg = argv[i];\n-- \n1.7.0.1.384.g6abcaa\n"},{"id":"136397","messageId":"1268067033-25199-3-git-send-email-pclouds@gmail.com","threadId":"22952","inReplyTo":"1268067033-25199-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 3/3] index-pack: use RUN_SETUP_GENTLY","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-03-08T16:50:33Z","receivedAt":"2010-03-08T16:50:33Z","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/index-pack.c |    2 --\n git.c                |    2 +-\n 2 files changed, 1 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 2a6359d..9aa6a13 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -879,7 +879,6 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)\n \tchar *index_name_buf = NULL, *keep_name_buf = NULL;\n \tstruct pack_idx_entry **idx_objects;\n \tunsigned char pack_sha1[20];\n-\tint nongit;\n \n \tif (argc == 2 && !strcmp(argv[1], \"-h\"))\n \t\tusage(index_pack_usage);\n@@ -889,7 +888,6 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)\n \t * However if the cwd was inside .git/objects/pack/ then we need\n \t * to go back there or all the pack name arguments will be wrong.\n \t */\n-\tprefix = setup_git_directory_gently(&nongit);\n \tgit_config(git_index_pack_config, NULL);\n \tif (prefix && chdir(prefix))\n \t\tdie(\"Cannot come back to cwd\");\ndiff --git a/git.c b/git.c\nindex 88408c8..746470f 100644\n--- a/git.c\n+++ b/git.c\n@@ -332,7 +332,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"grep\", cmd_grep, RUN_SETUP_GENTLY | USE_PAGER },\n \t\t{ \"hash-object\", cmd_hash_object, RUN_SETUP_GENTLY },\n \t\t{ \"help\", cmd_help, RUN_SETUP_GENTLY },\n-\t\t{ \"index-pack\", cmd_index_pack },\n+\t\t{ \"index-pack\", cmd_index_pack, RUN_SETUP_GENTLY },\n \t\t{ \"init\", cmd_init_db },\n \t\t{ \"init-db\", cmd_init_db },\n \t\t{ \"log\", cmd_log, RUN_SETUP | USE_PAGER },\n-- \n1.7.0.1.384.g6abcaa\n"}]}