{"thread":{"id":"12425","subject":"[PATCH 01/10] \"git read-tree -m\" and the like require worktree","startedAt":"2008-03-02T10:33:16Z","lastAt":"2008-03-11T16:21:57Z","messageCount":32,"participants":["Nguyễn Thái Ngọc Duy","Johannes Schindelin","Nguyen Thai Ngoc Duy","Jay Soffian"],"isPatch":true,"patchVersion":1,"patchTotal":10},"messages":[{"id":"70617","messageId":"20080302103316.GA8902@laptop","threadId":"12425","inReplyTo":"cover.1204453703.git.pclouds@gmail.com","subject":"[PATCH 01/10] \"git read-tree -m\" and the like require worktree","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-02T10:33:16Z","receivedAt":"2008-03-02T10:33:16Z","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-read-tree.c |    3 +++\n 1 files changed, 3 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-read-tree.c b/builtin-read-tree.c\nindex 0138f5a..a69bac4 100644\n--- a/builtin-read-tree.c\n+++ b/builtin-read-tree.c\n@@ -220,6 +220,9 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)\n \tif ((opts.dir && !opts.update))\n \t\tdie(\"--exclude-per-directory is meaningless unless -u\");\n \n+\tif (opts.merge && !opts.index_only)\n+\t\tsetup_work_tree();\n+\n \tif (opts.prefix) {\n \t\tint pfxlen = strlen(opts.prefix);\n \t\tint pos;\n-- \n1.5.4.2.281.g28d0e\n"},{"id":"70618","messageId":"20080302103333.GA8915@laptop","threadId":"12425","inReplyTo":"cover.1204453703.git.pclouds@gmail.com","subject":"[PATCH 02/10] Make sure setup_git_directory is called before accessing repository","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-02T10:33:33Z","receivedAt":"2008-03-02T10:33:33Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Right now setup_git_env is called automatically when needed and\nwill not die out if $GIT_DIR is invalid. The next patch no longer\nguarantee that, so make sure all commands have environment properly\nsetup before using.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n fast-import.c |    1 +\n hash-object.c |   10 +++++-----\n index-pack.c  |    2 ++\n 3 files changed, 8 insertions(+), 5 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex 0d3449f..7f197d5 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -2377,6 +2377,7 @@ int main(int argc, const char **argv)\n {\n \tunsigned int i, show_stats = 1;\n \n+\tsetup_git_directory();\n \tgit_config(git_pack_config);\n \tif (!pack_compression_seen && core_compression_seen)\n \t\tpack_compression_level = core_compression_level;\ndiff --git a/hash-object.c b/hash-object.c\nindex 61e7160..46d57ad 100644\n--- a/hash-object.c\n+++ b/hash-object.c\n@@ -42,7 +42,10 @@ int main(int argc, char **argv)\n \tint prefix_length = -1;\n \tint no_more_flags = 0;\n \tint hashstdin = 0;\n+\tint nongit = 0;\n \n+\tprefix = setup_git_directory_gently(&nongit);\n+\tprefix_length = prefix ? strlen(prefix) : 0;\n \tgit_config(git_default_config);\n \n \tfor (i = 1 ; i < argc; i++) {\n@@ -53,11 +56,8 @@ int main(int argc, char **argv)\n \t\t\t\ttype = argv[i];\n \t\t\t}\n \t\t\telse if (!strcmp(argv[i], \"-w\")) {\n-\t\t\t\tif (prefix_length < 0) {\n-\t\t\t\t\tprefix = setup_git_directory();\n-\t\t\t\t\tprefix_length =\n-\t\t\t\t\t\tprefix ? strlen(prefix) : 0;\n-\t\t\t\t}\n+\t\t\t\tif (nongit)\n+\t\t\t\t\tdie(\"Not a git repository\");\n \t\t\t\twrite_object = 1;\n \t\t\t}\n \t\t\telse if (!strcmp(argv[i], \"--\")) {\ndiff --git a/index-pack.c b/index-pack.c\nindex 9c0c278..1dbe88d 100644\n--- a/index-pack.c\n+++ b/index-pack.c\n@@ -785,7 +785,9 @@ int main(int argc, char **argv)\n \tchar *index_name_buf = NULL, *keep_name_buf = NULL;\n \tstruct pack_idx_entry **idx_objects;\n \tunsigned char sha1[20];\n+\tint nongit = 0;\n \n+\tsetup_git_directory_gently(&nongit);\n \tgit_config(git_index_pack_config);\n \n \tfor (i = 1; i < argc; i++) {\n-- \n1.5.4.2.281.g28d0e\n"},{"id":"70619","messageId":"20080302103348.GA8929@laptop","threadId":"12425","inReplyTo":"cover.1204453703.git.pclouds@gmail.com","subject":"[PATCH 03/10] Make get_git_dir() and 'git rev-parse --git-dir' absolute path","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-02T10:33:48Z","receivedAt":"2008-03-02T10:33:48Z","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    |   14 +-------------\n environment.c          |    1 +\n t/t1300-repo-config.sh |    2 +-\n t/t1400-update-ref.sh  |    4 ++--\n t/t9300-fast-import.sh |    2 +-\n 5 files changed, 6 insertions(+), 17 deletions(-)\n\ndiff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\nindex 90dbb9d..13412b4 100644\n--- a/builtin-rev-parse.c\n+++ b/builtin-rev-parse.c\n@@ -496,19 +496,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--git-dir\")) {\n-\t\t\t\tconst char *gitdir = getenv(GIT_DIR_ENVIRONMENT);\n-\t\t\t\tstatic char cwd[PATH_MAX];\n-\t\t\t\tif (gitdir) {\n-\t\t\t\t\tputs(gitdir);\n-\t\t\t\t\tcontinue;\n-\t\t\t\t}\n-\t\t\t\tif (!prefix) {\n-\t\t\t\t\tputs(\".git\");\n-\t\t\t\t\tcontinue;\n-\t\t\t\t}\n-\t\t\t\tif (!getcwd(cwd, PATH_MAX))\n-\t\t\t\t\tdie(\"unable to get current working directory\");\n-\t\t\t\tprintf(\"%s/.git\\n\", cwd);\n+\t\t\t\tputs(get_git_dir());\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--is-inside-git-dir\")) {\ndiff --git a/environment.c b/environment.c\nindex 6739a3f..ab7e54c 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -51,6 +51,7 @@ static void setup_git_env(void)\n \tgit_dir = getenv(GIT_DIR_ENVIRONMENT);\n \tif (!git_dir)\n \t\tgit_dir = DEFAULT_GIT_DIR_ENVIRONMENT;\n+\tgit_dir = xstrdup(make_absolute_path(git_dir));\n \tgit_object_dir = getenv(DB_ENVIRONMENT);\n \tif (!git_object_dir) {\n \t\tgit_object_dir = xmalloc(strlen(git_dir) + 9);\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex 4928a57..45b26d5 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -497,7 +497,7 @@ test_expect_success numbers '\n '\n \n cat > expect <<EOF\n-fatal: bad config value for 'aninvalid.unit' in .git/config\n+fatal: bad config value for 'aninvalid.unit' in $(pwd)/.git/config\n EOF\n \n test_expect_success 'invalid unit' '\ndiff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh\nindex 78cd412..4099c66 100755\n--- a/t/t1400-update-ref.sh\n+++ b/t/t1400-update-ref.sh\n@@ -169,7 +169,7 @@ test_expect_success \\\n \t'rm -f o e\n \t git rev-parse --verify \"master@{2005-05-26 23:33:01}\" >o 2>e &&\n \t test '\"$B\"' = $(cat o) &&\n-\t test \"warning: Log .git/logs/'\"$m has gap after $gd\"'.\" = \"$(cat e)\"'\n+\t test \"warning: Log '\"$(pwd)\"'/.git/logs/'\"$m has gap after $gd\"'.\" = \"$(cat e)\"'\n test_expect_success \\\n \t'Query \"master@{2005-05-26 23:38:00}\" (middle of history)' \\\n \t'rm -f o e\n@@ -187,7 +187,7 @@ test_expect_success \\\n \t'rm -f o e\n \t git rev-parse --verify \"master@{2005-05-28}\" >o 2>e &&\n \t test '\"$D\"' = $(cat o) &&\n-\t test \"warning: Log .git/logs/'\"$m unexpectedly ended on $ld\"'.\" = \"$(cat e)\"'\n+\t test \"warning: Log '\"$(pwd)\"'/.git/logs/'\"$m unexpectedly ended on $ld\"'.\" = \"$(cat e)\"'\n \n \n rm -f .git/$m .git/logs/$m expect\ndiff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh\nindex cceedbb..98a0cdf 100755\n--- a/t/t9300-fast-import.sh\n+++ b/t/t9300-fast-import.sh\n@@ -510,7 +510,7 @@ test_expect_success \\\n     'git-fast-import --export-pack-edges=edges.list <input'\n \n cat >expect <<EOF\n-.git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`\n+$(pwd)/.git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`\n EOF\n test_expect_success \\\n \t'I: verify edge list' \\\n-- \n1.5.4.2.281.g28d0e\n"},{"id":"70620","messageId":"20080302103405.GA8942@laptop","threadId":"12425","inReplyTo":"cover.1204453703.git.pclouds@gmail.com","subject":"[PATCH 04/10] Make setup_work_tree() return new prefix","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-02T10:34:05Z","receivedAt":"2008-03-02T10:34:05Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"worktree setup inside setup_git_directory*() is not perfect. It does\nnot take core.worktree into account. So when you do setup_work_tree(),\nthe real work tree may be not the one setup_git_directory*() gives you.\nYou need a new prefix in that case.\n\nThis also effectively reverts dd5c8af (Fix\nsetup_git_directory_gently() with relative GIT_DIR & GIT_WORK_TREE).\nThe problem is IMHO that git-diff does not setup worktree when it\nneeds it, so setting up worktree from setup_git_directory_gently() is\na fix in a wrong place.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-blame.c      |    4 +-\n builtin-diff-files.c |    4 ++-\n builtin-diff.c       |    4 ++-\n builtin-ls-files.c   |    8 ++--\n builtin-read-tree.c  |    2 +-\n builtin-rev-parse.c  |    2 +\n builtin-rm.c         |    2 +-\n cache.h              |    2 +-\n git.c                |    2 +-\n setup.c              |   84 ++++++++++++++++----------------------------------\n 10 files changed, 45 insertions(+), 69 deletions(-)\n\ndiff --git a/builtin-blame.c b/builtin-blame.c\nindex bfd562d..f5a878b 100644\n--- a/builtin-blame.c\n+++ b/builtin-blame.c\n@@ -2291,6 +2291,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \t\t\t/* (3) */\n \t\t\tif (argc <= i)\n \t\t\t\tusage(blame_usage);\n+\t\t\tprefix = setup_work_tree(prefix);\n \t\t\tpath = add_prefix(prefix, argv[i]);\n \t\t\tif (i + 1 == argc - 1) {\n \t\t\t\tfinal_commit_name = argv[i + 1];\n@@ -2306,7 +2307,6 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \t\t\telse if (i != argc - 1)\n \t\t\t\tusage(blame_usage); /* garbage at end */\n \n-\t\t\tsetup_work_tree();\n \t\t\tif (!has_path_in_work_tree(path))\n \t\t\t\tdie(\"cannot stat path %s: %s\",\n \t\t\t\t    path, strerror(errno));\n@@ -2354,7 +2354,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \t\t * do not default to HEAD, but use the working tree\n \t\t * or \"--contents\".\n \t\t */\n-\t\tsetup_work_tree();\n+\t\tsetup_work_tree(prefix);\n \t\tsb.final = fake_working_tree_commit(path, contents_from);\n \t\tadd_pending_object(&revs, &(sb.final->object), \":\");\n \t}\ndiff --git a/builtin-diff-files.c b/builtin-diff-files.c\nindex 4abe3c2..11671a8 100644\n--- a/builtin-diff-files.c\n+++ b/builtin-diff-files.c\n@@ -26,8 +26,10 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)\n \n \tif (!setup_diff_no_index(&rev, argc, argv, nongit, prefix))\n \t\targc = 0;\n-\telse\n+\telse {\n+\t\trev.prefix = setup_work_tree(prefix);\n \t\targc = setup_revisions(argc, argv, &rev, NULL);\n+\t}\n \tif (!rev.diffopt.output_format)\n \t\trev.diffopt.output_format = DIFF_FORMAT_RAW;\n \tresult = run_diff_files_cmd(&rev, argc, argv);\ndiff --git a/builtin-diff.c b/builtin-diff.c\nindex 444ff2f..254e5a0 100644\n--- a/builtin-diff.c\n+++ b/builtin-diff.c\n@@ -244,8 +244,10 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \n \tif (!setup_diff_no_index(&rev, argc, argv, nongit, prefix))\n \t\targc = 0;\n-\telse\n+\telse {\n+\t\trev.prefix = setup_work_tree(prefix);\n \t\targc = setup_revisions(argc, argv, &rev, NULL);\n+\t}\n \tif (!rev.diffopt.output_format) {\n \t\trev.diffopt.output_format = DIFF_FORMAT_PATCH;\n \t\tif (diff_setup_done(&rev.diffopt) < 0)\ndiff --git a/builtin-ls-files.c b/builtin-ls-files.c\nindex 25dbfb4..cf4c492 100644\n--- a/builtin-ls-files.c\n+++ b/builtin-ls-files.c\n@@ -23,7 +23,7 @@ static int show_valid_bit;\n static int line_terminator = '\\n';\n \n static int prefix_len;\n-static int prefix_offset;\n+static int prefix_offset = -1;\n static const char **pathspec;\n static int error_unmatch;\n static char *ps_matched;\n@@ -435,8 +435,6 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n \tstruct dir_struct dir;\n \n \tmemset(&dir, 0, sizeof(dir));\n-\tif (prefix)\n-\t\tprefix_offset = strlen(prefix);\n \tgit_config(git_default_config);\n \n \tfor (i = 1; i < argc; i++) {\n@@ -569,7 +567,9 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n \t}\n \n \tif (require_work_tree && !is_inside_work_tree())\n-\t\tsetup_work_tree();\n+\t\tprefix = setup_work_tree(prefix);\n+\tif (prefix_offset == -1)\n+\t\tprefix_offset = prefix ? strlen(prefix) : 0;\n \n \tpathspec = get_pathspec(prefix, argv + i);\n \ndiff --git a/builtin-read-tree.c b/builtin-read-tree.c\nindex a69bac4..851f24d 100644\n--- a/builtin-read-tree.c\n+++ b/builtin-read-tree.c\n@@ -221,7 +221,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)\n \t\tdie(\"--exclude-per-directory is meaningless unless -u\");\n \n \tif (opts.merge && !opts.index_only)\n-\t\tsetup_work_tree();\n+\t\tsetup_work_tree(NULL);\n \n \tif (opts.prefix) {\n \t\tint pfxlen = strlen(opts.prefix);\ndiff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\nindex 13412b4..3d3a309 100644\n--- a/builtin-rev-parse.c\n+++ b/builtin-rev-parse.c\n@@ -472,6 +472,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--show-prefix\")) {\n+\t\t\t\tif (is_inside_work_tree())\n+\t\t\t\t\tprefix = setup_work_tree(prefix);\n \t\t\t\tif (prefix)\n \t\t\t\t\tputs(prefix);\n \t\t\t\tcontinue;\ndiff --git a/builtin-rm.c b/builtin-rm.c\nindex c0a8bb6..2c15d66 100644\n--- a/builtin-rm.c\n+++ b/builtin-rm.c\n@@ -156,7 +156,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \t\tusage_with_options(builtin_rm_usage, builtin_rm_options);\n \n \tif (!index_only)\n-\t\tsetup_work_tree();\n+\t\tprefix = setup_work_tree(prefix);\n \n \tpathspec = get_pathspec(prefix, argv);\n \tseen = NULL;\ndiff --git a/cache.h b/cache.h\nindex bdefcc9..b98f7e8 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -315,7 +315,7 @@ extern const char *get_git_work_tree(void);\n #define ALTERNATE_DB_ENVIRONMENT \"GIT_ALTERNATE_OBJECT_DIRECTORIES\"\n \n extern const char **get_pathspec(const char *prefix, const char **pathspec);\n-extern void setup_work_tree(void);\n+extern const char *setup_work_tree(const char *prefix);\n extern const char *setup_git_directory_gently(int *);\n extern const char *setup_git_directory(void);\n extern const char *prefix_path(const char *prefix, int len, const char *path);\ndiff --git a/git.c b/git.c\nindex 1e3eb10..9e53a2e 100644\n--- a/git.c\n+++ b/git.c\n@@ -241,7 +241,7 @@ static int run_command(struct cmd_struct *p, int argc, const char **argv)\n \tif (p->option & USE_PAGER)\n \t\tsetup_pager();\n \tif (p->option & NEED_WORK_TREE)\n-\t\tsetup_work_tree();\n+\t\tprefix = setup_work_tree(prefix);\n \n \ttrace_argv_printf(argv, \"trace: built-in: git\");\n \ndiff --git a/setup.c b/setup.c\nindex 89c81e5..6c908a5 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -262,38 +262,23 @@ int is_inside_work_tree(void)\n \treturn inside_work_tree;\n }\n \n-/*\n- * set_work_tree() is only ever called if you set GIT_DIR explicitely.\n- * The old behaviour (which we retain here) is to set the work tree root\n- * to the cwd, unless overridden by the config, the command line, or\n- * GIT_WORK_TREE.\n- */\n-static const char *set_work_tree(const char *dir)\n-{\n-\tchar buffer[PATH_MAX + 1];\n-\n-\tif (!getcwd(buffer, sizeof(buffer)))\n-\t\tdie (\"Could not get the current working directory\");\n-\tgit_work_tree_cfg = xstrdup(buffer);\n-\tinside_work_tree = 1;\n-\n-\treturn NULL;\n-}\n-\n-void setup_work_tree(void)\n+const char *setup_work_tree(const char *prefix)\n {\n-\tconst char *work_tree, *git_dir;\n-\tstatic int initialized = 0;\n+\tconst char *work_tree;\n+\tstatic char buffer[PATH_MAX + 1];\n+\tchar *rel;\n \n-\tif (initialized)\n-\t\treturn;\n+\tget_git_dir(); /* ensure git_dir has been initialized as cwd will change */\n \twork_tree = get_git_work_tree();\n-\tgit_dir = get_git_dir();\n-\tif (!is_absolute_path(git_dir))\n-\t\tset_git_dir(make_absolute_path(git_dir));\n-\tif (!work_tree || chdir(work_tree))\n+\tif (!work_tree)\n \t\tdie(\"This operation must be run in a work tree\");\n-\tinitialized = 1;\n+\tif (prefix && chdir(prefix))\n+\t\tdie (\"Could not jump back into original cwd\");\n+\trel = get_relative_cwd(buffer, PATH_MAX, work_tree);\n+\ttrace_printf(\"test: worktree = %s\\n\", rel ? rel : \"NULL\");\n+\tif (chdir(work_tree))\n+\t\tdie(\"This operation must be run in a work tree\");\n+\treturn rel && *rel ? strcat(rel, \"/\") : NULL;\n }\n \n static int check_repository_format_gently(int *nongit_ok)\n@@ -336,24 +321,21 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \t\t\tstatic char buffer[1024 + 1];\n \t\t\tconst char *retval;\n \n+\t\t\t/*\n+\t\t\t * The old behaviour (which we retain here) is to set\n+\t\t\t * the work tree root to the cwd, unless overridden by\n+\t\t\t * the config, the command line, or GIT_WORK_TREE.\n+\t\t\t */\n \t\t\tif (!work_tree_env) {\n-\t\t\t\tretval = set_work_tree(gitdirenv);\n-\t\t\t\t/* config may override worktree */\n-\t\t\t\tif (check_repository_format_gently(nongit_ok))\n-\t\t\t\t\treturn NULL;\n-\t\t\t\treturn retval;\n+\t\t\t\tchar buffer[PATH_MAX + 1];\n+\n+\t\t\t\tif (!getcwd(buffer, sizeof(buffer)))\n+\t\t\t\t\tdie (\"Could not get the current working directory\");\n+\t\t\t\tgit_work_tree_cfg = xstrdup(buffer);\n+\t\t\t\tinside_work_tree = 1;\n \t\t\t}\n-\t\t\tif (check_repository_format_gently(nongit_ok))\n-\t\t\t\treturn NULL;\n-\t\t\tretval = get_relative_cwd(buffer, sizeof(buffer) - 1,\n-\t\t\t\t\tget_git_work_tree());\n-\t\t\tif (!retval || !*retval)\n-\t\t\t\treturn NULL;\n-\t\t\tset_git_dir(make_absolute_path(gitdirenv));\n-\t\t\tif (chdir(work_tree_env) < 0)\n-\t\t\t\tdie (\"Could not chdir to %s\", work_tree_env);\n-\t\t\tstrcat(buffer, \"/\");\n-\t\t\treturn retval;\n+\t\t\tcheck_repository_format_gently(nongit_ok);\n+\t\t\treturn NULL;\n \t\t}\n \t\tif (nongit_ok) {\n \t\t\t*nongit_ok = 1;\n@@ -462,17 +444,5 @@ int check_repository_format(void)\n \n const char *setup_git_directory(void)\n {\n-\tconst char *retval = setup_git_directory_gently(NULL);\n-\n-\t/* If the work tree is not the default one, recompute prefix */\n-\tif (inside_work_tree < 0) {\n-\t\tstatic char buffer[PATH_MAX + 1];\n-\t\tchar *rel;\n-\t\tif (retval && chdir(retval))\n-\t\t\tdie (\"Could not jump back into original cwd\");\n-\t\trel = get_relative_cwd(buffer, PATH_MAX, get_git_work_tree());\n-\t\treturn rel && *rel ? strcat(rel, \"/\") : NULL;\n-\t}\n"},{"id":"70621","messageId":"20080302103419.GA8957@laptop","threadId":"12425","inReplyTo":"cover.1204453703.git.pclouds@gmail.com","subject":"[PATCH 05/10] http-push: Avoid calling setup_git_directory() twice","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-02T10:34:19Z","receivedAt":"2008-03-02T10:34:19Z","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 http-push.c |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/http-push.c b/http-push.c\nindex 5b23038..c4b28f2 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -2175,7 +2175,7 @@ int main(int argc, char **argv)\n \tstruct ref *ref;\n \tchar *rewritten_url = NULL;\n \n-\tsetup_git_directory();\n+\tconst char *prefix = setup_git_directory();\n \n \tremote = xcalloc(sizeof(*remote), 1);\n \n@@ -2382,7 +2382,7 @@ int main(int argc, char **argv)\n \t\t\tcommit_argv[3] = old_sha1_hex;\n \t\t\tcommit_argc++;\n \t\t}\n-\t\tinit_revisions(&revs, setup_git_directory());\n+\t\tinit_revisions(&revs, prefix);\n \t\tsetup_revisions(commit_argc, commit_argv, &revs, NULL);\n \t\tfree(new_sha1_hex);\n \t\tif (old_sha1_hex) {\n-- \n1.5.4.2.281.g28d0e\n"},{"id":"70622","messageId":"20080302103433.GA8970@laptop","threadId":"12425","inReplyTo":"cover.1204453703.git.pclouds@gmail.com","subject":"[PATCH 06/10] Completely move out worktree setup from setup_git_directory_gently()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-02T10:34:33Z","receivedAt":"2008-03-02T10:34:33Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This was impossible earlier because git_dir can be relative. Now that\ngit_dir is absolute, I see no reason for worktree setup inside\nsetup_git_directory_gently(). The semantic is now clearer: if you need\nworktree, call setup_work_tree yourself (well, I will clean up\nsetup_git_directory() part later)\n\nThis patch will free some commands from prefix handling if they don't\never need worktree.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-apply.c          |    7 +++++--\n builtin-bundle.c         |    9 ++-------\n builtin-config.c         |   15 +++++----------\n builtin-diff-files.c     |   11 ++++++-----\n builtin-diff.c           |   11 ++++++-----\n builtin-upload-archive.c |    4 ++--\n cache.h                  |    2 +-\n git.c                    |    6 +-----\n hash-object.c            |    8 +-------\n setup.c                  |   34 +++++++++++++++++-----------------\n 10 files changed, 46 insertions(+), 61 deletions(-)\n\ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex a3f075d..b77e84e 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -2998,8 +2998,11 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)\n \n \tconst char *whitespace_option = NULL;\n \n-\tprefix = setup_git_directory_gently(&is_not_gitdir);\n-\tprefix_length = prefix ? strlen(prefix) : 0;\n+\tsetup_git_directory_gently(&is_not_gitdir);\n+\tif (!is_not_gitdir && is_inside_work_tree()) {\n+\t\tprefix = setup_work_tree(NULL);\n+\t\tprefix_length = prefix ? strlen(prefix) : 0;\n+\t}\n \tgit_config(git_apply_config);\n \tif (apply_default_whitespace)\n \t\tparse_whitespace_option(apply_default_whitespace);\ndiff --git a/builtin-bundle.c b/builtin-bundle.c\nindex 9f38e21..2a7687e 100644\n--- a/builtin-bundle.c\n+++ b/builtin-bundle.c\n@@ -11,7 +11,7 @@\n \n static const char *bundle_usage=\"git-bundle (create <bundle> <git-rev-list args> | verify <bundle> | list-heads <bundle> [refname]... | unbundle <bundle> [refname]... )\";\n \n-int cmd_bundle(int argc, const char **argv, const char *prefix)\n+int cmd_bundle(int argc, const char **argv, const char *unused_prefix)\n {\n \tstruct bundle_header header;\n \tint nongit = 0;\n@@ -27,12 +27,7 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)\n \targc -= 2;\n \targv += 2;\n \n-\tprefix = setup_git_directory_gently(&nongit);\n-\tif (prefix && bundle_file[0] != '/') {\n-\t\tsnprintf(buffer, sizeof(buffer), \"%s/%s\", prefix, bundle_file);\n-\t\tbundle_file = buffer;\n-\t}\n-\n+\tsetup_git_directory_gently(&nongit);\n \tmemset(&header, 0, sizeof(header));\n \tif (strcmp(cmd, \"create\") && (bundle_fd =\n \t\t\t\tread_bundle_header(bundle_file, &header)) < 0)\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 2b9a426..ae6be9b 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -262,11 +262,11 @@ static int get_colorbool(int argc, const char **argv)\n \t}\n }\n \n-int cmd_config(int argc, const char **argv, const char *prefix)\n+int cmd_config(int argc, const char **argv, const char *unused_prefix)\n {\n \tint nongit = 0;\n \tchar* value;\n-\tconst char *file = setup_git_directory_gently(&nongit);\n+\tsetup_git_directory_gently(&nongit);\n \n \twhile (1 < argc) {\n \t\tif (!strcmp(argv[1], \"--int\"))\n@@ -276,8 +276,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\telse if (!strcmp(argv[1], \"--list\") || !strcmp(argv[1], \"-l\")) {\n \t\t\tif (argc != 2)\n \t\t\t\tusage(git_config_set_usage);\n-\t\t\tif (git_config(show_all_config) < 0 && file && errno)\n-\t\t\t\tdie(\"unable to read config file %s: %s\", file,\n+\t\t\tif (git_config(show_all_config) < 0 && errno)\n+\t\t\t\tdie(\"unable to read config file: %s\",\n \t\t\t\t    strerror(errno));\n \t\t\treturn 0;\n \t\t}\n@@ -296,12 +296,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\telse if (!strcmp(argv[1], \"--file\") || !strcmp(argv[1], \"-f\")) {\n \t\t\tif (argc < 3)\n \t\t\t\tusage(git_config_set_usage);\n-\t\t\tif (!is_absolute_path(argv[2]) && file)\n-\t\t\t\tfile = prefix_filename(file, strlen(file),\n-\t\t\t\t\t\t       argv[2]);\n-\t\t\telse\n-\t\t\t\tfile = argv[2];\n-\t\t\tsetenv(CONFIG_ENVIRONMENT, file, 1);\n+\t\t\tsetenv(CONFIG_ENVIRONMENT, argv[2], 1);\n \t\t\targc--;\n \t\t\targv++;\n \t\t}\ndiff --git a/builtin-diff-files.c b/builtin-diff-files.c\nindex 11671a8..826f052 100644\n--- a/builtin-diff-files.c\n+++ b/builtin-diff-files.c\n@@ -13,21 +13,22 @@ static const char diff_files_usage[] =\n \"git-diff-files [-q] [-0/-1/2/3 |-c|--cc|--no-index] [<common diff options>] [<path>...]\"\n COMMON_DIFF_OPTIONS_HELP;\n \n-int cmd_diff_files(int argc, const char **argv, const char *prefix)\n+int cmd_diff_files(int argc, const char **argv, const char *unused_prefix)\n {\n \tstruct rev_info rev;\n \tint nongit = 0;\n \tint result;\n \n-\tprefix = setup_git_directory_gently(&nongit);\n-\tinit_revisions(&rev, prefix);\n+\tsetup_git_directory_gently(&nongit);\n+\tinit_revisions(&rev, NULL);\n \tgit_config(git_diff_basic_config); /* no \"diff\" UI options */\n \trev.abbrev = 0;\n \n-\tif (!setup_diff_no_index(&rev, argc, argv, nongit, prefix))\n+\tif (!setup_diff_no_index(&rev, argc, argv, nongit, NULL))\n \t\targc = 0;\n \telse {\n-\t\trev.prefix = setup_work_tree(prefix);\n+\t\tinit_revisions(&rev, setup_work_tree(NULL));\n+\t\trev.abbrev = 0;\n \t\targc = setup_revisions(argc, argv, &rev, NULL);\n \t}\n \tif (!rev.diffopt.output_format)\ndiff --git a/builtin-diff.c b/builtin-diff.c\nindex 254e5a0..a92ab0e 100644\n--- a/builtin-diff.c\n+++ b/builtin-diff.c\n@@ -202,7 +202,7 @@ static void refresh_index_quietly(void)\n \trollback_lock_file(lock_file);\n }\n \n-int cmd_diff(int argc, const char **argv, const char *prefix)\n+int cmd_diff(int argc, const char **argv, const char *unused_prefix)\n {\n \tint i;\n \tstruct rev_info rev;\n@@ -233,19 +233,20 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \t * Other cases are errors.\n \t */\n \n-\tprefix = setup_git_directory_gently(&nongit);\n+\tsetup_git_directory_gently(&nongit);\n \tgit_config(git_diff_ui_config);\n \n \tif (diff_use_color_default == -1)\n \t\tdiff_use_color_default = git_use_color_default;\n \n-\tinit_revisions(&rev, prefix);\n+\tinit_revisions(&rev, NULL);\n \trev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;\n \n-\tif (!setup_diff_no_index(&rev, argc, argv, nongit, prefix))\n+\tif (!setup_diff_no_index(&rev, argc, argv, nongit, NULL))\n \t\targc = 0;\n \telse {\n-\t\trev.prefix = setup_work_tree(prefix);\n+\t\tinit_revisions(&rev, setup_work_tree(NULL));\n+\t\trev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;\n \t\targc = setup_revisions(argc, argv, &rev, NULL);\n \t}\n \tif (!rev.diffopt.output_format) {\ndiff --git a/builtin-upload-archive.c b/builtin-upload-archive.c\nindex 48ae09e..4f7fa35 100644\n--- a/builtin-upload-archive.c\n+++ b/builtin-upload-archive.c\n@@ -17,7 +17,7 @@ static const char lostchild[] =\n \"git-upload-archive: archiver process was lost\";\n \n \n-static int run_upload_archive(int argc, const char **argv, const char *prefix)\n+static int run_upload_archive(int argc, const char **argv, const char *unused_prefix)\n {\n \tstruct archiver ar;\n \tconst char *sent_argv[MAX_ARGS];\n@@ -67,7 +67,7 @@ static int run_upload_archive(int argc, const char **argv, const char *prefix)\n \t/* parse all options sent by the client */\n \ttreeish_idx = parse_archive_args(sent_argc, sent_argv, &ar);\n \n-\tparse_treeish_arg(sent_argv + treeish_idx, &ar.args, prefix);\n+\tparse_treeish_arg(sent_argv + treeish_idx, &ar.args, NULL);\n \tparse_pathspec_arg(sent_argv + treeish_idx + 1, &ar.args);\n \n \treturn ar.write_archive(&ar.args);\ndiff --git a/cache.h b/cache.h\nindex b98f7e8..33dcfb1 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -316,7 +316,7 @@ extern const char *get_git_work_tree(void);\n \n extern const char **get_pathspec(const char *prefix, const char **pathspec);\n extern const char *setup_work_tree(const char *prefix);\n-extern const char *setup_git_directory_gently(int *);\n+extern void setup_git_directory_gently(int *);\n extern const char *setup_git_directory(void);\n extern const char *prefix_path(const char *prefix, int len, const char *path);\n extern const char *prefix_filename(const char *prefix, int len, const char *path);\ndiff --git a/git.c b/git.c\nindex 9e53a2e..d87c33e 100644\n--- a/git.c\n+++ b/git.c\n@@ -143,13 +143,12 @@ static int split_cmdline(char *cmdline, const char ***argv)\n static int handle_alias(int *argcp, const char ***argv)\n {\n \tint nongit = 0, envchanged = 0, ret = 0, saved_errno = errno;\n-\tconst char *subdir;\n \tint count, option_count;\n \tconst char** new_argv;\n \tconst char *alias_command;\n \tchar *alias_string;\n \n-\tsubdir = setup_git_directory_gently(&nongit);\n+\tsetup_git_directory_gently(&nongit);\n \n \talias_command = (*argv)[0];\n \talias_string = alias_lookup(alias_command);\n@@ -205,9 +204,6 @@ static int handle_alias(int *argcp, const char ***argv)\n \t\tret = 1;\n \t}\n \n-\tif (subdir)\n-\t\tchdir(subdir);\n-\n \terrno = saved_errno;\n \n \treturn ret;\ndiff --git a/hash-object.c b/hash-object.c\nindex 46d57ad..5986701 100644\n--- a/hash-object.c\n+++ b/hash-object.c\n@@ -38,14 +38,11 @@ int main(int argc, char **argv)\n \tint i;\n \tconst char *type = blob_type;\n \tint write_object = 0;\n-\tconst char *prefix = NULL;\n-\tint prefix_length = -1;\n \tint no_more_flags = 0;\n \tint hashstdin = 0;\n \tint nongit = 0;\n \n-\tprefix = setup_git_directory_gently(&nongit);\n-\tprefix_length = prefix ? strlen(prefix) : 0;\n+\tsetup_git_directory_gently(&nongit);\n \tgit_config(git_default_config);\n \n \tfor (i = 1 ; i < argc; i++) {\n@@ -80,9 +77,6 @@ int main(int argc, char **argv)\n \t\t\t\thash_stdin(type, write_object);\n \t\t\t\thashstdin = 0;\n \t\t\t}\n-\t\t\tif (0 <= prefix_length)\n-\t\t\t\targ = prefix_filename(prefix, prefix_length,\n-\t\t\t\t\t\t      arg);\n \t\t\thash_object(arg, type_from_string(type), write_object);\n \t\t\tno_more_flags = 1;\n \t\t}\ndiff --git a/setup.c b/setup.c\nindex 6c908a5..78ae2f9 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -301,7 +301,7 @@ static int check_repository_format_gently(int *nongit_ok)\n  * We cannot decide in this function whether we are in the work tree or\n  * not, since the config can only be read _after_ this function was called.\n  */\n-const char *setup_git_directory_gently(int *nongit_ok)\n+void setup_git_directory_gently(int *nongit_ok)\n {\n \tconst char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);\n \tstatic char cwd[PATH_MAX+1];\n@@ -335,11 +335,11 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \t\t\t\tinside_work_tree = 1;\n \t\t\t}\n \t\t\tcheck_repository_format_gently(nongit_ok);\n-\t\t\treturn NULL;\n+\t\t\treturn;\n \t\t}\n \t\tif (nongit_ok) {\n \t\t\t*nongit_ok = 1;\n-\t\t\treturn NULL;\n+\t\t\treturn;\n \t\t}\n \t\tdie(\"Not a git repository: '%s'\", gitdirenv);\n \t}\n@@ -364,9 +364,12 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \t\t\tinside_git_dir = 1;\n \t\t\tif (!work_tree_env)\n \t\t\t\tinside_work_tree = 0;\n-\t\t\tsetenv(GIT_DIR_ENVIRONMENT, \".\", 1);\n+\t\t\tif (chdir(cwd))\n+\t\t\t\tdie(\"Cannot come back to cwd\");\n+\t\t\tcwd[offset] = '\\0';\n+\t\t\tsetenv(GIT_DIR_ENVIRONMENT, cwd, 1);\n \t\t\tcheck_repository_format_gently(nongit_ok);\n-\t\t\treturn NULL;\n+\t\t\treturn;\n \t\t}\n \t\tchdir(\"..\");\n \t\tdo {\n@@ -375,27 +378,23 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \t\t\t\t\tif (chdir(cwd))\n \t\t\t\t\t\tdie(\"Cannot come back to cwd\");\n \t\t\t\t\t*nongit_ok = 1;\n-\t\t\t\t\treturn NULL;\n+\t\t\t\t\treturn;\n \t\t\t\t}\n \t\t\t\tdie(\"Not a git repository\");\n \t\t\t}\n \t\t} while (cwd[--offset] != '/');\n \t}\n \n+\tif (chdir(cwd))\n+\t\tdie(\"Cannot come back to cwd\");\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-\tif (check_repository_format_gently(nongit_ok))\n-\t\treturn NULL;\n-\tif (offset == len)\n-\t\treturn NULL;\n"},{"id":"70623","messageId":"20080302103446.GA8983@laptop","threadId":"12425","inReplyTo":"cover.1204453703.git.pclouds@gmail.com","subject":"[PATCH 07/10] builtin-archive: mark unused prefix \"unused_prefix\"","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-02T10:34:46Z","receivedAt":"2008-03-02T10:34:46Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"cmd_archive() is registered without RUN_SETUP so its prefix\nwill be NULL forever. Let's make that clear.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-archive.c |    6 +++---\n 1 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin-archive.c b/builtin-archive.c\nindex c2e0c1e..84405df 100644\n--- a/builtin-archive.c\n+++ b/builtin-archive.c\n@@ -236,11 +236,12 @@ static const char *extract_remote_arg(int *ac, const char **av)\n \treturn remote;\n }\n \n-int cmd_archive(int argc, const char **argv, const char *prefix)\n+int cmd_archive(int argc, const char **argv, const char *unused_prefix)\n {\n \tstruct archiver ar;\n \tint tree_idx;\n \tconst char *remote = NULL;\n+\tconst char *prefix;\n \n \tremote = extract_remote_arg(&argc, argv);\n \tif (remote)\n@@ -250,9 +251,8 @@ int cmd_archive(int argc, const char **argv, const char *prefix)\n \n \tmemset(&ar, 0, sizeof(ar));\n \ttree_idx = parse_archive_args(argc, argv, &ar);\n-\tif (prefix == NULL)\n-\t\tprefix = setup_git_directory();\n \n+\tprefix = setup_git_directory();\n \targv += tree_idx;\n \tparse_treeish_arg(argv, &ar.args, prefix);\n \tparse_pathspec_arg(argv + 1, &ar.args);\n-- \n1.5.4.2.281.g28d0e\n"},{"id":"70624","messageId":"20080302103501.GA8996@laptop","threadId":"12425","inReplyTo":"cover.1204453703.git.pclouds@gmail.com","subject":"[PATCH 08/10] Make setup_git_directory() auto-setup worktree if found","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-02T10:35:01Z","receivedAt":"2008-03-02T10:35:01Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"The semantic is simpler: if worktree is found, use it or die.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-ls-files.c  |    4 ++--\n builtin-rev-parse.c |    7 +++++--\n builtin-rm.c        |    5 ++---\n setup.c             |    2 +-\n 4 files changed, 10 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin-ls-files.c b/builtin-ls-files.c\nindex cf4c492..a53881d 100644\n--- a/builtin-ls-files.c\n+++ b/builtin-ls-files.c\n@@ -566,8 +566,8 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n \t\tbreak;\n \t}\n \n-\tif (require_work_tree && !is_inside_work_tree())\n-\t\tprefix = setup_work_tree(prefix);\n+\tif (require_work_tree && !get_git_work_tree())\n+\t\tdie(\"This operation must be run in a work tree\");\n \tif (prefix_offset == -1)\n \t\tprefix_offset = prefix ? strlen(prefix) : 0;\n \ndiff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\nindex 3d3a309..5016890 100644\n--- a/builtin-rev-parse.c\n+++ b/builtin-rev-parse.c\n@@ -359,15 +359,16 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n \n-int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n+int cmd_rev_parse(int argc, const char **argv, const char *unused_prefix)\n {\n \tint i, as_is = 0, verify = 0;\n \tunsigned char sha1[20];\n+\tconst char *prefix = NULL;\n \n \tif (argc > 1 && !strcmp(\"--parseopt\", argv[1]))\n \t\treturn cmd_parseopt(argc - 1, argv + 1, prefix);\n \n-\tprefix = setup_git_directory();\n+\tsetup_git_directory_gently(NULL);\n \tgit_config(git_default_config);\n \tfor (i = 1; i < argc; i++) {\n \t\tconst char *arg = argv[i];\n@@ -487,6 +488,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\t\t\tprintf(\"%s\\n\", work_tree);\n \t\t\t\t\tcontinue;\n \t\t\t\t}\n+\t\t\t\telse\n+\t\t\t\t\tpfx = prefix = setup_work_tree(prefix);\n \t\t\t\twhile (pfx) {\n \t\t\t\t\tpfx = strchr(pfx, '/');\n \t\t\t\t\tif (pfx) {\ndiff --git a/builtin-rm.c b/builtin-rm.c\nindex 2c15d66..dedef9f 100644\n--- a/builtin-rm.c\n+++ b/builtin-rm.c\n@@ -155,10 +155,9 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \tif (!argc)\n \t\tusage_with_options(builtin_rm_usage, builtin_rm_options);\n \n-\tif (!index_only)\n-\t\tprefix = setup_work_tree(prefix);\n"},{"id":"70626","messageId":"20080302103519.GA9011@laptop","threadId":"12425","inReplyTo":"cover.1204453703.git.pclouds@gmail.com","subject":"[PATCH 09/10] Documentation: update api-builtin and api-setup","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-02T10:35:19Z","receivedAt":"2008-03-02T10:35:19Z","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 Documentation/technical/api-builtin.txt |   10 ++++\n Documentation/technical/api-setup.txt   |   91 ++++++++++++++++++++++++++++---\n 2 files changed, 93 insertions(+), 8 deletions(-)\n\ndiff --git a/Documentation/technical/api-builtin.txt b/Documentation/technical/api-builtin.txt\nindex 52cdb4c..f0d988b 100644\n--- a/Documentation/technical/api-builtin.txt\n+++ b/Documentation/technical/api-builtin.txt\n@@ -33,6 +33,10 @@ git:\n \tIf the standard output is connected to a tty, spawn a pager and\n \tfeed our output to it.\n \n+`NEED_WORK_TREE`::\n+\n+\tMake sure there is a work tree to work on.\n+\n . Add `builtin-foo.o` to `BUILTIN_OBJS` in `Makefile`.\n \n Additionally, if `foo` is a new command, there are 3 more things to do:\n@@ -59,5 +63,11 @@ to the subdirectory the command started from.  This allows you to\n convert a user-supplied pathname (typically relative to that directory)\n to a pathname relative to the top of the work tree.\n \n+`NEED_WORK_TREE` also set `prefix` like `RUN_SETUP`. But it will `die()`\n+if there is no work tree.\n+\n+If neither `NEED_WORK_TREE` nor `RUN_SETUP` is set, `prefix` is always `NULL`.\n+No chdir(2) will be done.\n+\n The return value from `cmd_foo()` becomes the exit status of the\n command.\ndiff --git a/Documentation/technical/api-setup.txt b/Documentation/technical/api-setup.txt\nindex 4f63a04..6f2defa 100644\n--- a/Documentation/technical/api-setup.txt\n+++ b/Documentation/technical/api-setup.txt\n@@ -1,13 +1,88 @@\n setup API\n =========\n \n-Talk about\n+End-user point-of-view how the setup works\n+------------------------------------------\n \n-* setup_git_directory()\n-* setup_git_directory_gently()\n-* is_inside_git_dir()\n-* is_inside_work_tree()\n-* setup_work_tree()\n-* get_pathspec()\n+. If you have `GIT_DIR` exported, then no discovery is attempted.\n+  We use the `GIT_DIR` you set it, and the repository lives\n+  there.  `$GIT_DIR/config` is the repository config.\n \n-(Dscho)\n+. Otherwise we do the usual discovery going up to find the\n+  repository.\n+\n+. If you have `GIT_WORK_TREE` exported, or otherwise if the\n+  config has `core.worktree`, that's where your worktree is.\n+  If these variables point to an invalid place, you have no worktree.\n+\n+. Otherwise, if you have `GIT_DIR` exported, you do not have a\n+  worktree.  Else one level above your `$GIT_DIR` is the toplevel\n+  of your worktree.\n+\n+Repository setup\n+----------------\n+\n+At startup:\n+\n+. If the command always need a repository, call\n+  `setup_git_directory()`. It will ensure you have a valid\n+  repository. It will `die()` otherwise. If a worktree is detected,\n+  it will be setup automatically. Note that `setup_git_directory()`\n+  can only be called once.\n+\n+. If the command can optionally run in a repository, use\n+  `setup_git_directory_gently(&nongit_ok)`,which is similar\n+  to `setup_git_directory()` except it won't `die()`\n+  but sets `nongit_ok` to true if run outside a repository.\n+  No chdir(2) is done.\n+\n+. If you don't want worktree setup at all, but always need a git repository,\n+  you can use `setup_git_directory_gently(NULL)`.\n+\n+Do not access git repository (even indirectly like `git_config()`) before\n+calling one of these functions. Otherwise you may encounter `die()` if git\n+fails to automatically find/setup a repository.\n+\n+Working directory setup\n+-----------------------\n+\n+If `setup_git_directory()` is used, worktree can be optionally setup already.\n+To check if work tree has been setup, use `get_git_work_tree()`. The return\n+value is `NULL` if no work tree is setup or work tree directory otherwise.\n+\n+If you need a working directory, use `setup_work_tree()`. It will\n+move current directory to top-level working directory and return\n+a prefix. It will `die()` if unable to setup working directory.\n+\n+Miscellanous functions\n+----------------------\n+\n+To know where `$GIT_DIR` is, use `get_git_dir()`. It will always return\n+an absolute path. To know where `$GIT_WORK_TREE` is, use\n+`get_git_work_tree()`. To check if you are inside a worktree or a git\n+repository, use `is_inside_work_tree()` or `is_inside_git_dir()` respectively.\n+There functions may be not valid until `setup_git_directory*()` is called.\n+\n+When working with pathspecs and prefix, you can use `get_pathspec()`\n+to auto prepend a given prefix to pathspecs. Other helpful functions\n+are `prefix_path()`, `prefix_filename()`\n+\n+Shell-based setup\n+-----------------\n+\n+At startup, you need to `source git-sh-setup`. If your command does not always\n+require a repository, set variable `NONGIT_OK` before sourcing git-sh-setup.\n+\n+If the command requires worktree, call `require_work_tree` (after\n+git-sh-setup).\n+\n+Two variables `USAGE` and `LONG_USAGE` can be optionally set before sourcing\n+git-sh-setup. They will be printed as help usage.\n+\n+To check if a repository is a bare repository, `is_bare_repository` can be\n+used.\n+\n+There are several `git rev-parse` options to help shell scripts initialize\n+their environment. Those are `--show-prefix`, `--show-cdup`, `--git-dir`,\n+`--is-inside-git-dir`, `--is-inside-work-tree`, `--is-bare-repository` and\n+`--parseopt`. Please refer to `git rev-parse` man page for more information.\n-- \n1.5.4.2.281.g28d0e\n"},{"id":"70627","messageId":"20080302103543.GA9028@laptop","threadId":"12425","inReplyTo":"cover.1204453703.git.pclouds@gmail.com","subject":"[PATCH 10/10] Additional tests to capture worktree special cases","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-02T10:35:43Z","receivedAt":"2008-03-02T10:35:43Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Most of them are for setup_git_directory_gently() commands\nas those are likely to break.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n t/t1501-worktree.sh |   57 +++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 55 insertions(+), 2 deletions(-)\n\ndiff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh\nindex 7ee3820..a53c1f5 100755\n--- a/t/t1501-worktree.sh\n+++ b/t/t1501-worktree.sh\n@@ -47,7 +47,19 @@ export GIT_CONFIG=\"$(pwd)\"/$GIT_DIR/config\n test_rev_parse 'subdirectory' false false true sub/dir/\n cd ../../.. || exit 1\n \n-say \"core.worktree = absolute path\"\n+say \"core.worktree = absolute path with GIT_DIR unset\"\n+mkdir -p $(pwd)/repo.git/work/sub/dir || exit 1\n+unset GIT_DIR\n+export GIT_CONFIG=$(pwd)/repo.git/config\n+git config core.worktree \"$(pwd)/repo.git/work\"\n+test_rev_parse 'outside'      false false false\n+cd repo.git/work || exit 1\n+test_rev_parse 'inside'       false true true ''\n+cd sub/dir || exit 1\n+test_rev_parse 'subdirectory' false true true sub/dir/\n+cd ../../../.. || exit 1\n+\n+say \"core.worktree = absolute path with GIT_DIR set\"\n export GIT_DIR=$(pwd)/repo.git\n export GIT_CONFIG=$GIT_DIR/config\n git config core.worktree \"$(pwd)/work\"\n@@ -58,6 +70,47 @@ cd sub/dir || exit 1\n test_rev_parse 'subdirectory' false false true sub/dir/\n cd ../../.. || exit 1\n \n+test_expect_success '\"git ls-files -o\" gets correct prefix' '\n+\t(cd work/sub && touch untracked &&\n+\ttest \"$(git ls-files -o)\" = untracked)'\n+\n+rm work/sub/untracked || exit 1\n+\n+cat <<EOF >expected\n+:100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M\tsub/tracked\n+EOF\n+\n+cat <<EOF >expected2\n+:100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M\ttracked\n+EOF\n+\n+test_expect_success '\"git diff-files\" gets correct prefix' '\n+\t(cd work/sub  && touch tracked &&\n+\tgit add tracked && echo modified > tracked &&\n+\tgit diff-files > ../../result &&\n+\tgit diff-files --relative > ../../result2 &&\n+\tgit rm -f tracked) &&\n+\tcmp result expected &&\n+\tcmp result2 expected2'\n+\n+cat <<EOF >expected\n+:100644 100644 e69de29... 0000000... M\tsub/tracked\n+EOF\n+\n+cat <<EOF >expected2\n+:100644 100644 e69de29... 0000000... M\ttracked\n+EOF\n+\n+\n+test_expect_success '\"git diff\" gets correct prefix' '\n+\t(cd work/sub  && touch tracked &&\n+\tgit add tracked && echo modified > tracked &&\n+\tgit diff --raw > ../../result &&\n+\tgit diff --raw --relative > ../../result2 &&\n+\tgit rm -f tracked) &&\n+\tcmp result expected &&\n+\tcmp result2 expected2'\n+\n say \"GIT_WORK_TREE=relative path (override core.worktree)\"\n export GIT_DIR=$(pwd)/repo.git\n export GIT_CONFIG=$GIT_DIR/config\n@@ -103,7 +156,7 @@ test_expect_success 'repo finds its work tree from work tree, too' '\n \t test sub/dir/tracked = \"$(git ls-files)\")\n '\n \n-test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' '\n+test_expect_success '\"git diff\" setup worktree properly' '\n \tcd repo.git/work/sub/dir &&\n \tGIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \\\n \t\tgit diff --exit-code tracked &&\n-- \n1.5.4.2.281.g28d0e\n"},{"id":"71694","messageId":"alpine.LSU.1.00.0803111400430.3873@racer.site","threadId":"12425","inReplyTo":"20080302103316.GA8902@laptop","subject":"Re: [PATCH 01/10] \"git read-tree -m\" and the like require worktree","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-11T13:02:02Z","receivedAt":"2008-03-11T13:02:02Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nHow about\n\n\tgit read-tree -m without -i requires work tree\n\nHmm?\n\nOther than that, it looks like an obvious bugfix which is independent of \nthe rest.\n\nCiao,\nDscho\n"},{"id":"71696","messageId":"alpine.LSU.1.00.0803111420080.3873@racer.site","threadId":"12425","inReplyTo":"20080302103348.GA8929@laptop","subject":"Re: [PATCH 03/10] Make get_git_dir() and 'git rev-parse --git-dir' absolute path","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-11T13:20:37Z","receivedAt":"2008-03-11T13:20:37Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 2 Mar 2008, Nguyễn Thái Ngọc Duy wrote:\n\n> \n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n\nI do not like this change.  It is IMO completely unnecessary, and might \nbreak assumptions.\n\nCiao,\nDscho\n"},{"id":"71698","messageId":"alpine.LSU.1.00.0803111426521.3873@racer.site","threadId":"12425","inReplyTo":"20080302103405.GA8942@laptop","subject":"Re: [PATCH 04/10] Make setup_work_tree() return new prefix","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-11T13:27:21Z","receivedAt":"2008-03-11T13:27:21Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 2 Mar 2008, Nguyễn Thái Ngọc Duy wrote:\n\n> worktree setup inside setup_git_directory*() is not perfect. It does not \n> take core.worktree into account. So when you do setup_work_tree(), the \n> real work tree may be not the one setup_git_directory*() gives you. You \n> need a new prefix in that case.\n\nProbably the real fix would be to setup_git_directory(), no?\n\nCiao,\nDscho\n"},{"id":"71699","messageId":"alpine.LSU.1.00.0803111427400.3873@racer.site","threadId":"12425","inReplyTo":"20080302103419.GA8957@laptop","subject":"Re: [PATCH 05/10] http-push: Avoid calling setup_git_directory() twice","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-11T13:28:05Z","receivedAt":"2008-03-11T13:28:05Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 2 Mar 2008, Nguyễn Thái Ngọc Duy wrote:\n\n> \n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n\nThis fix is completely independent of the rest of your series.\n\nCiao,\nDscho"},{"id":"71700","messageId":"alpine.LSU.1.00.0803111429380.3873@racer.site","threadId":"12425","inReplyTo":"20080302103433.GA8970@laptop","subject":"Re: [PATCH 06/10] Completely move out worktree setup from setup_git_directory_gently()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-11T13:31:48Z","receivedAt":"2008-03-11T13:31:48Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 2 Mar 2008, Nguyễn Thái Ngọc Duy wrote:\n\n> This was impossible earlier because git_dir can be relative. Now that\n> git_dir is absolute, I see no reason for worktree setup inside\n> setup_git_directory_gently(). The semantic is now clearer: if you need\n> worktree, call setup_work_tree yourself (well, I will clean up\n> setup_git_directory() part later)\n\nAs I said earlier, the work for getting the prefix as most likely be done \nalready in the search for .git/.  I mean, it _is_ the common case to have \na working tree with a .git/ in it, and that's it.\n\nSo I am quite certain that it is not worth the complicated and intrusive \npatch to separate the logic.\n\nParticularly since working tree has a bad reputation already, as Junio \npointed out: whenever we touch it, we get burnt.\n\nCiao,\nDscho"},{"id":"71701","messageId":"alpine.LSU.1.00.0803111432370.3873@racer.site","threadId":"12425","inReplyTo":"20080302103446.GA8983@laptop","subject":"Re: [PATCH 07/10] builtin-archive: mark unused prefix \"unused_prefix\"","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-11T13:33:03Z","receivedAt":"2008-03-11T13:33:03Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 2 Mar 2008, Nguyễn Thái Ngọc Duy wrote:\n\n> cmd_archive() is registered without RUN_SETUP so its prefix\n> will be NULL forever. Let's make that clear.\n> \n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n\nAFAICT this patch is -- like two others -- an independent fix, and should \nbe submitted as such.\n\nCiao,\nDscho"},{"id":"71712","messageId":"fcaeb9bf0803110750rd70a303r3fc522b326ea93b@mail.gmail.com","threadId":"12425","inReplyTo":"alpine.LSU.1.00.0803111432370.3873@racer.site","subject":"Re: [PATCH 07/10] builtin-archive: mark unused prefix \"unused_prefix\"","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-11T14:50:24Z","receivedAt":"2008-03-11T14:50:24Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Mar 11, 2008 at 8:33 PM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n>\n>  On Sun, 2 Mar 2008, Nguyễn Thái Ngọc Duy wrote:\n>\n>  > cmd_archive() is registered without RUN_SETUP so its prefix\n>  > will be NULL forever. Let's make that clear.\n>  >\n>  > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n>  > ---\n>\n>  AFAICT this patch is -- like two others -- an independent fix, and should\n>  be submitted as such.\n\nIt's not really independent. Before the series, setup_dir_gently()\n_can_ change the prefix. After the series it does not (semantics\nchange). The first patch of the series (\"git read-tree -m\") is\nindependent and can be cherry picked if necessary.\n-- \nDuy\n"},{"id":"71714","messageId":"fcaeb9bf0803110754v7191d8fckbde0e1313e6a69ec@mail.gmail.com","threadId":"12425","inReplyTo":"alpine.LSU.1.00.0803111427400.3873@racer.site","subject":"Re: [PATCH 05/10] http-push: Avoid calling setup_git_directory() twice","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-11T14:54:44Z","receivedAt":"2008-03-11T14:54:44Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Mar 11, 2008 at 8:28 PM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n>\n>  On Sun, 2 Mar 2008, Nguyễn Thái Ngọc Duy wrote:\n>\n>  >\n>  > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n>\n>  This fix is completely independent of the rest of your series.\n\nNot really. It would have no impact (good or bad) if sent separately.\nBut it is required by the series (otherwise it would die() under\ncertain condition because prefix cannot be recomputed properly).\n-- \nDuy\n"},{"id":"71715","messageId":"fcaeb9bf0803110757i5f31c6b9w3b0e65af401e3ca0@mail.gmail.com","threadId":"12425","inReplyTo":"alpine.LSU.1.00.0803111400430.3873@racer.site","subject":"Re: [PATCH 01/10] \"git read-tree -m\" and the like require worktree","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-11T14:57:53Z","receivedAt":"2008-03-11T14:57:53Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Mar 11, 2008 at 8:02 PM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n>  How about\n>\n>         git read-tree -m without -i requires work tree\n>\n>  Hmm?\n\nI thought that was the patch was about. Did I write the patch so bad? :(\n\n>\n>  Other than that, it looks like an obvious bugfix which is independent of\n>  the rest.\n\nAgreed completely. As said in the other mail, this patch can be cherry\npicked well without the rest of the series (should I resend it?).\n\n>\n>  Ciao,\n>  Dscho\n>\n>\n\n\n\n-- \nDuy\n"},{"id":"71719","messageId":"fcaeb9bf0803110806u43fbd8b8v3ec2adf84fa1cd5e@mail.gmail.com","threadId":"12425","inReplyTo":"alpine.LSU.1.00.0803111420080.3873@racer.site","subject":"Re: [PATCH 03/10] Make get_git_dir() and 'git rev-parse --git-dir' absolute path","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-11T15:06:23Z","receivedAt":"2008-03-11T15:06:23Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Mar 11, 2008 at 8:20 PM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n>\n>  On Sun, 2 Mar 2008, Nguyễn Thái Ngọc Duy wrote:\n>\n>  >\n>  > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n>\n>  I do not like this change.  It is IMO completely unnecessary, and might\n>  break assumptions.\n\nIt could. And I tried my best to make sure it did not break anything.\nIt is also documented (if not clearly, I can correct the document).\nWhile it's not really necessary, it would be IMHO a good change as you\nwould not have to rely on `cwd` anymore (that would mean whether\nmoving cwd by prefix or not would no longer matter).\n\n>  Ciao,\n>  Dscho\n>\n-- \nDuy\n"},{"id":"71717","messageId":"alpine.LSU.1.00.0803111605530.3873@racer.site","threadId":"12425","inReplyTo":"fcaeb9bf0803110757i5f31c6b9w3b0e65af401e3ca0@mail.gmail.com","subject":"Re: [PATCH 01/10] \"git read-tree -m\" and the like require worktree","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-11T15:06:42Z","receivedAt":"2008-03-11T15:06:42Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 11 Mar 2008, Nguyen Thai Ngoc Duy wrote:\n\n> On Tue, Mar 11, 2008 at 8:02 PM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n>\n> >  How about\n> >\n> >         git read-tree -m without -i requires work tree\n> >\n> >  Hmm?\n> \n> I thought that was the patch was about. Did I write the patch so bad? :(\n\nI meant as a replacement for your commit subject (which I found pretty \nhard to understand, harder than the patch itself).\n\nCiao,\nDscho\n"},{"id":"71718","messageId":"alpine.LSU.1.00.0803111604240.3873@racer.site","threadId":"12425","inReplyTo":"fcaeb9bf0803110754v7191d8fckbde0e1313e6a69ec@mail.gmail.com","subject":"Re: [PATCH 05/10] http-push: Avoid calling setup_git_directory() twice","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-11T15:08:07Z","receivedAt":"2008-03-11T15:08:07Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 11 Mar 2008, Nguyen Thai Ngoc Duy wrote:\n\n> On Tue, Mar 11, 2008 at 8:28 PM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n>\n> >  On Sun, 2 Mar 2008, Nguy�n Th�i Ng�c Duy wrote:\n> >\n> >  > Signed-off-by: Nguy�n Th�i Ng�c Duy <pclouds@gmail.com>\n> >\n> >  This fix is completely independent of the rest of your series.\n> \n> Not really. It would have no impact (good or bad) if sent separately. \n> But it is required by the series (otherwise it would die() under certain \n> condition because prefix cannot be recomputed properly).\n\nWell, it _is_ independent.  Either you say \"we want to have this as an \nexample where you can call setup_git_directory() twice\" (which I would not \nfind all that bad), or you say \"this was calling setup_git_directory() \ntwice, fix that\".\n\nIn any case, it should be separate from this series.\n\nBack to the subject of this series: as I stated already, I do not like the \nseparation of work-tree and git directory, and I especially do not like \nhow much you had to work outside setup.c.  I think changing the semantics \nfor all callers was not necessary, and in fact, not desirable.\n\nCiao,\nDscho\n"},{"id":"71721","messageId":"fcaeb9bf0803110818t6c009b29k5afb4f8b3833d475@mail.gmail.com","threadId":"12425","inReplyTo":"alpine.LSU.1.00.0803111426521.3873@racer.site","subject":"Re: [PATCH 04/10] Make setup_work_tree() return new prefix","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-11T15:18:03Z","receivedAt":"2008-03-11T15:18:03Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Mar 11, 2008 at 8:27 PM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n>\n>  On Sun, 2 Mar 2008, Nguyễn Thái Ngọc Duy wrote:\n>\n>  > worktree setup inside setup_git_directory*() is not perfect. It does not\n>  > take core.worktree into account. So when you do setup_work_tree(), the\n>  > real work tree may be not the one setup_git_directory*() gives you. You\n>  > need a new prefix in that case.\n>\n>  Probably the real fix would be to setup_git_directory(), no?\n\nsetup_work_tree() does the job fine. Why duplicate the code one more?\nIn the old days, setup_git_directory() was just a simple wrapper\naround setup_git_dir_gently(). I wanted to move it back to those days.\nAnd setup_git_directory() is fixed  in \"Completely move out worktree\nsetup from setup_git_directory_gently()\" so setup_git_directory() does\ncontain the real fix in the end.\n\n>  Ciao,\n>  Dscho\n-- \nDuy\n"},{"id":"71722","messageId":"alpine.LSU.1.00.0803111616050.3873@racer.site","threadId":"12425","inReplyTo":"fcaeb9bf0803110806u43fbd8b8v3ec2adf84fa1cd5e@mail.gmail.com","subject":"Re: [PATCH 03/10] Make get_git_dir() and 'git rev-parse --git-dir' absolute path","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-11T15:18:08Z","receivedAt":"2008-03-11T15:18:08Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 11 Mar 2008, Nguyen Thai Ngoc Duy wrote:\n\n> On Tue, Mar 11, 2008 at 8:20 PM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n>\n> >  On Sun, 2 Mar 2008, Nguyễn Thái Ngọc Duy wrote:\n> >\n> >  > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> >\n> >  I do not like this change.  It is IMO completely unnecessary, and \n> >  might break assumptions.\n> \n> It could. And I tried my best to make sure it did not break anything.\n\nThat is contradicting.  I think that whatever you tried, once you let \nrev-parse --git-dir return only absolute paths, you already risked \nbreakage.\n\nBesides, I remember that Junio specifically requested that I would _not_ \ndo something like that (this was for --show-cdup, but I think it really \napplies here, too).\n\n> While it's not really necessary, it would be IMHO a good change as you \n> would not have to rely on `cwd` anymore (that would mean whether moving \n> cwd by prefix or not would no longer matter).\n\nI do not see the problem.  And therefore I do not see that this patch \nsolves anything.\n\nCiao,\nDscho\n"},{"id":"71723","messageId":"fcaeb9bf0803110828u3087ccdeqead5f2c433e08597@mail.gmail.com","threadId":"12425","inReplyTo":"alpine.LSU.1.00.0803111429380.3873@racer.site","subject":"Re: [PATCH 06/10] Completely move out worktree setup from setup_git_directory_gently()","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-11T15:28:53Z","receivedAt":"2008-03-11T15:28:53Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Mar 11, 2008 at 8:31 PM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n>\n>  On Sun, 2 Mar 2008, Nguyễn Thái Ngọc Duy wrote:\n>\n>  > This was impossible earlier because git_dir can be relative. Now that\n>  > git_dir is absolute, I see no reason for worktree setup inside\n>  > setup_git_directory_gently(). The semantic is now clearer: if you need\n>  > worktree, call setup_work_tree yourself (well, I will clean up\n>  > setup_git_directory() part later)\n>\n>  As I said earlier, the work for getting the prefix as most likely be done\n>  already in the search for .git/.  I mean, it _is_ the common case to have\n>  a working tree with a .git/ in it, and that's it.\n>\n>  So I am quite certain that it is not worth the complicated and intrusive\n>  patch to separate the logic.\n\nIt does for two purposes:\n\n - Leave a chance for commands that does not care about worktree at\nall. Those commands won't have to care about prefix anymore.\n - Clean up the code. Now only setup_work_tree() does worktree setup\nthings (like chdir())\n\n>  Particularly since working tree has a bad reputation already, as Junio\n>  pointed out: whenever we touch it, we get burnt.\n\nI'd rather get burnt now than later (which might be probably worse) :)\nIn case we are to be burnt, we should not have it in 1.5.5 :D\n\n>  Ciao,\n>  Dscho\n\n\n\n-- \nDuy\n"},{"id":"71724","messageId":"76718490803110838p1cdc30a8vb9792d81ddf62a0d@mail.gmail.com","threadId":"12425","inReplyTo":"fcaeb9bf0803110750rd70a303r3fc522b326ea93b@mail.gmail.com","subject":"Re: [PATCH 07/10] builtin-archive: mark unused prefix \"unused_prefix\"","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-03-11T15:38:09Z","receivedAt":"2008-03-11T15:38:09Z","isPatch":true,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"I hate to make this request, but Gmail seems unable to decode messages\nwhich are \"Content-Disposition: inline\" + \"Content-Transfer-Encoding:\nbase64\". The message body shows up completely blank in the Gmail web\ninterface. (I wonder if it is due to the footer that Majordomo appends?)\n\nI've reported this is a bug to Gmail, but since I imagine I'm not the\nonly one using Gmail to read this list, and since so far your messages\nseem to be the only ones sent this way, can I ask that you configure\nyour MUA to not send messages this way, if possible?\n\nMuch appreciated,\n\nj.\n"},{"id":"71725","messageId":"fcaeb9bf0803110839m582bed5cr5b3e198712e0fe8e@mail.gmail.com","threadId":"12425","inReplyTo":"alpine.LSU.1.00.0803111616050.3873@racer.site","subject":"Re: [PATCH 03/10] Make get_git_dir() and 'git rev-parse --git-dir' absolute path","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-11T15:39:02Z","receivedAt":"2008-03-11T15:39:02Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Mar 11, 2008 at 10:18 PM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n>\n>  On Tue, 11 Mar 2008, Nguyen Thai Ngoc Duy wrote:\n>\n>  > On Tue, Mar 11, 2008 at 8:20 PM, Johannes Schindelin\n>  > <Johannes.Schindelin@gmx.de> wrote:\n>  >\n>\n> > >  On Sun, 2 Mar 2008, Nguyễn Thái Ngọc Duy wrote:\n>  > >\n>  > >  > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n>  > >\n>  > >  I do not like this change.  It is IMO completely unnecessary, and\n>  > >  might break assumptions.\n>  >\n>  > It could. And I tried my best to make sure it did not break anything.\n>\n>  That is contradicting.  I think that whatever you tried, once you let\n>  rev-parse --git-dir return only absolute paths, you already risked\n>  breakage.\n>\n>  Besides, I remember that Junio specifically requested that I would _not_\n>  do something like that (this was for --show-cdup, but I think it really\n>  applies here, too).\n\nI might have lost track. Could you provide me the link for reference? Thanks.\n\n>  > While it's not really necessary, it would be IMHO a good change as you\n>  > would not have to rely on `cwd` anymore (that would mean whether moving\n>  > cwd by prefix or not would no longer matter).\n>\n>  I do not see the problem.  And therefore I do not see that this patch\n>  solves anything.\n\nIt can simplify things (in other patches, such as builtin-config.c\nchanges). Though without it things just run fine (with a little more\ncomplication in prefix handling). Recent mails about git-am running in\nsubdirectory (Message-ID:\n20080301062255.GA27538@coredump.intra.peff.net) made me think there\nwas room for this.\n\nIt is also prerequisite for later changes in the series (IIRC,\nremoving prefix from setup*_gently() needs it).\n\n>  Ciao,\n>  Dscho\n>\n\n\n\n-- \nDuy\n"},{"id":"71726","messageId":"fcaeb9bf0803110841h54899919kba1bfa15ccc06843@mail.gmail.com","threadId":"12425","inReplyTo":"alpine.LSU.1.00.0803111605530.3873@racer.site","subject":"Re: [PATCH 01/10] \"git read-tree -m\" and the like require worktree","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-11T15:41:23Z","receivedAt":"2008-03-11T15:41:23Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Mar 11, 2008 at 10:06 PM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n>\n>  On Tue, 11 Mar 2008, Nguyen Thai Ngoc Duy wrote:\n>\n>  > On Tue, Mar 11, 2008 at 8:02 PM, Johannes Schindelin\n>  > <Johannes.Schindelin@gmx.de> wrote:\n>  >\n>\n> > >  How about\n>  > >\n>  > >         git read-tree -m without -i requires work tree\n>  > >\n>  > >  Hmm?\n>  >\n>  > I thought that was the patch was about. Did I write the patch so bad? :(\n>\n>  I meant as a replacement for your commit subject (which I found pretty\n>  hard to understand, harder than the patch itself).\n\nYes it is absolutely a better subject. Thanks.\n-- \nDuy\n"},{"id":"71729","messageId":"fcaeb9bf0803110912n480d8f42kde0956609519de83@mail.gmail.com","threadId":"12425","inReplyTo":"alpine.LSU.1.00.0803111604240.3873@racer.site","subject":"Re: [PATCH 05/10] http-push: Avoid calling setup_git_directory() twice","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-11T16:12:38Z","receivedAt":"2008-03-11T16:12:38Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Mar 11, 2008 at 10:08 PM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n>\n>  On Tue, 11 Mar 2008, Nguyen Thai Ngoc Duy wrote:\n>\n>  > On Tue, Mar 11, 2008 at 8:28 PM, Johannes Schindelin\n>  > <Johannes.Schindelin@gmx.de> wrote:\n>  >\n>  > >  On Sun, 2 Mar 2008, Nguy­n Thái Ng÷c Duy wrote:\n>  > >\n>  > >  > Signed-off-by: Nguy­n Thái Ng÷c Duy <pclouds@gmail.com>\n>\n> > >\n>  > >  This fix is completely independent of the rest of your series.\n>  >\n>  > Not really. It would have no impact (good or bad) if sent separately.\n>  > But it is required by the series (otherwise it would die() under certain\n>  > condition because prefix cannot be recomputed properly).\n>\n>  Well, it _is_ independent.  Either you say \"we want to have this as an\n>  example where you can call setup_git_directory() twice\" (which I would not\n>  find all that bad), or you say \"this was calling setup_git_directory()\n>  twice, fix that\".\n>\n>  In any case, it should be separate from this series.\n\nMy point stands still. It is merely cleanup without harm or goodness\nif seperated from the series. This patch does not fix the real\nproblem.\n\n>  Back to the subject of this series: as I stated already, I do not like the\n>  separation of work-tree and git directory, and I especially do not like\n>  how much you had to work outside setup.c.  I think changing the semantics\n>  for all callers was not necessary, and in fact, not desirable.\n\nFor one, setup_work_tree() prototype change is necessary to deal with\n(gitdir autodetection + core.worktree + setup_work_tree()).\n\nFor setup_*gently() changes, I think I can make\nsetup_git_directory_gently() retain its current semantics by removing\n06/10 and 07/10. But I do think it's nice to have setup_*_gently()\ndoes things gently _and_ easily-predictable (current _gently() setups\nworktree under certain conditions and not otherwise, which I consider\nuneasily-predictable). Patch 06 and 07 are mainly cleanup as a result\nfrom _gently() changes. Are those most intrusive to you?\n\n>  Ciao,\n>  Dscho\n>\n-- \nDuy\n"},{"id":"71731","messageId":"alpine.LSU.1.00.0803111716500.3873@racer.site","threadId":"12425","inReplyTo":"fcaeb9bf0803110839m582bed5cr5b3e198712e0fe8e@mail.gmail.com","subject":"Re: [PATCH 03/10] Make get_git_dir() and 'git rev-parse --git-dir' absolute path","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-11T16:20:07Z","receivedAt":"2008-03-11T16:20:07Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 11 Mar 2008, Nguyen Thai Ngoc Duy wrote:\n\n> On Tue, Mar 11, 2008 at 10:18 PM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> >  Besides, I remember that Junio specifically requested that I would \n> >  _not_ do something like that (this was for --show-cdup, but I think \n> >  it really applies here, too).\n> \n> I might have lost track. Could you provide me the link for reference? \n> Thanks.\n\nhttp://article.gmane.org/gmane.comp.version-control.git/53993/match=show+cdup\n\nThis is how you can find it yourself next time (and how I found it):\n\nGo to gmane, search for \"show-cdup\", then select Junio as writer.  It is \nalready the second hit, which was obvious by the email's title.\n\n> >  I do not see the problem.  And therefore I do not see that this patch \n> >  solves anything.\n> \n> It can simplify things (in other patches, such as builtin-config.c \n> changes). Though without it things just run fine (with a little more \n> complication in prefix handling). Recent mails about git-am running in \n> subdirectory (Message-ID: \n> 20080301062255.GA27538@coredump.intra.peff.net) made me think there was \n> room for this.\n\nOkay, I see that you want to simplify things.  However, I am not at all \nconvinced that your patch series does that.\n\nHowever, instead of continuing this thread, I will try to find some time \nlater this week to look into simplifying the work-tree logic again.\n\nIf I find things, I will discuss them on the list.\n\nCiao,\nDscho\n"},{"id":"71732","messageId":"alpine.LSU.1.00.0803111720501.3873@racer.site","threadId":"12425","inReplyTo":"fcaeb9bf0803110828u3087ccdeqead5f2c433e08597@mail.gmail.com","subject":"Re: [PATCH 06/10] Completely move out worktree setup from setup_git_directory_gently()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-11T16:21:29Z","receivedAt":"2008-03-11T16:21:29Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 11 Mar 2008, Nguyen Thai Ngoc Duy wrote:\n\n> On Tue, Mar 11, 2008 at 8:31 PM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> >  Particularly since working tree has a bad reputation already, as \n> >  Junio pointed out: whenever we touch it, we get burnt.\n> \n> I'd rather get burnt now than later (which might be probably worse) :) \n> In case we are to be burnt, we should not have it in 1.5.5 :D\n\nI'd rather be not burnt at all.  That's why I am opposed to this huge \n(relative to what it accomplishes) patch series.\n\nCiao,\nDscho\n"},{"id":"71733","messageId":"fcaeb9bf0803110921g754dfa54w517cad490476e59e@mail.gmail.com","threadId":"12425","inReplyTo":"76718490803110838p1cdc30a8vb9792d81ddf62a0d@mail.gmail.com","subject":"Re: [PATCH 07/10] builtin-archive: mark unused prefix \"unused_prefix\"","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-03-11T16:21:57Z","receivedAt":"2008-03-11T16:21:57Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Mar 11, 2008 at 10:38 PM, Jay Soffian <jaysoffian@gmail.com> wrote:\n> I hate to make this request, but Gmail seems unable to decode messages\n>  which are \"Content-Disposition: inline\" + \"Content-Transfer-Encoding:\n>  base64\". The message body shows up completely blank in the Gmail web\n>  interface. (I wonder if it is due to the footer that Majordomo appends?)\n\nFunny that meesage was created by gmail.\n\n>  I've reported this is a bug to Gmail, but since I imagine I'm not the\n>  only one using Gmail to read this list, and since so far your messages\n>  seem to be the only ones sent this way, can I ask that you configure\n>  your MUA to not send messages this way, if possible?\n\nIf I does not misunderstand it, non-ascii characters make gmail encode\nmessages base64. I'll be careful next time removing all non-ascii (or\nswitch back to mutt).\n\n>  Much appreciated,\n>\n>  j.\n>\n-- \nDuy\n"}]}