{"thread":{"id":"38148","subject":"[PATCH v3 0/3] Multiple worktrees vs. submodules fixes","startedAt":"2014-12-09T04:44:40Z","lastAt":"2014-12-09T05:04:35Z","messageCount":5,"participants":["Max Kirillov"],"isPatch":true,"patchVersion":3,"patchTotal":3},"messages":[{"id":"253398","messageId":"1418100283-8995-1-git-send-email-max@max630.net","threadId":"38148","inReplyTo":null,"subject":"[PATCH v3 0/3] Multiple worktrees vs. submodules fixes","fromName":"Max Kirillov","fromEmail":"max@max630.net","sentAt":"2014-12-09T04:44:40Z","receivedAt":"2014-12-09T04:44:40Z","isPatch":true,"sender":{"key":"max@max630.net","avatar":"https://avatars.githubusercontent.com/u/381560?v=4"},"body":"After discussions I came to basically same as v1.\n\n* Resubmitting the 2 patches which have not been taken to worktrees reroll -\n  they fix visible issue. Mostly unchanged except small cleanup in test.\n* Added GIT_COMMON_DIR to local_repo_env. While it is obviously a right\n  thing, I wasn't able to observe any change in behavior.\n\nMax Kirillov (3):\n  submodule refactor: use git_path_submodule() in add_submodule_odb()\n  path: implement common_dir handling in git_path_submodule()\n  Add GIT_COMMON_DIR to local_repo_env\n\n cache.h                          |  1 +\n environment.c                    |  1 +\n path.c                           | 24 ++++++++++++++++++++----\n setup.c                          | 17 ++++++++++++-----\n submodule.c                      | 28 ++++++++++------------------\n t/t7410-submodule-checkout-to.sh | 10 ++++++++++\n 6 files changed, 54 insertions(+), 27 deletions(-)\n\n-- \n2.2.0.50.gb2b6831\n"},{"id":"253399","messageId":"1418100283-8995-2-git-send-email-max@max630.net","threadId":"38148","inReplyTo":"1418100283-8995-1-git-send-email-max@max630.net","subject":"[PATCH v3 1/3] submodule refactor: use git_path_submodule() in add_submodule_odb()","fromName":"Max Kirillov","fromEmail":"max@max630.net","sentAt":"2014-12-09T04:44:41Z","receivedAt":"2014-12-09T04:44:41Z","isPatch":true,"sender":{"key":"max@max630.net","avatar":"https://avatars.githubusercontent.com/u/381560?v=4"},"body":"Signed-off-by: Max Kirillov <max@max630.net>\n---\n submodule.c | 28 ++++++++++------------------\n 1 file changed, 10 insertions(+), 18 deletions(-)\n\ndiff --git a/submodule.c b/submodule.c\nindex 34094f5..4aad3d4 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -122,43 +122,35 @@ void stage_updated_gitmodules(void)\n \n static int add_submodule_odb(const char *path)\n {\n-\tstruct strbuf objects_directory = STRBUF_INIT;\n \tstruct alternate_object_database *alt_odb;\n+\tconst char* objects_directory;\n \tint ret = 0;\n-\tconst char *git_dir;\n \n-\tstrbuf_addf(&objects_directory, \"%s/.git\", path);\n-\tgit_dir = read_gitfile(objects_directory.buf);\n-\tif (git_dir) {\n-\t\tstrbuf_reset(&objects_directory);\n-\t\tstrbuf_addstr(&objects_directory, git_dir);\n-\t}\n-\tstrbuf_addstr(&objects_directory, \"/objects/\");\n-\tif (!is_directory(objects_directory.buf)) {\n+\tobjects_directory = git_path_submodule(path, \"objects/\");\n+\tif (!is_directory(objects_directory)) {\n \t\tret = -1;\n \t\tgoto done;\n \t}\n+\n \t/* avoid adding it twice */\n \tfor (alt_odb = alt_odb_list; alt_odb; alt_odb = alt_odb->next)\n-\t\tif (alt_odb->name - alt_odb->base == objects_directory.len &&\n-\t\t\t\t!strncmp(alt_odb->base, objects_directory.buf,\n-\t\t\t\t\tobjects_directory.len))\n+\t\tif (alt_odb->name - alt_odb->base == strlen(objects_directory) &&\n+\t\t\t\t!strcmp(alt_odb->base, objects_directory))\n \t\t\tgoto done;\n \n-\talt_odb = xmalloc(objects_directory.len + 42 + sizeof(*alt_odb));\n+\talt_odb = xmalloc(strlen(objects_directory) + 42 + sizeof(*alt_odb));\n \talt_odb->next = alt_odb_list;\n-\tstrcpy(alt_odb->base, objects_directory.buf);\n-\talt_odb->name = alt_odb->base + objects_directory.len;\n+\tstrcpy(alt_odb->base, objects_directory);\n+\talt_odb->name = alt_odb->base + strlen(objects_directory);\n \talt_odb->name[2] = '/';\n \talt_odb->name[40] = '\\0';\n \talt_odb->name[41] = '\\0';\n \talt_odb_list = alt_odb;\n \n \t/* add possible alternates from the submodule */\n-\tread_info_alternates(objects_directory.buf, 0);\n+\tread_info_alternates(objects_directory, 0);\n \tprepare_alt_odb();\n done:\n-\tstrbuf_release(&objects_directory);\n \treturn ret;\n }\n \n-- \n2.2.0.50.gb2b6831\n"},{"id":"253400","messageId":"1418100283-8995-3-git-send-email-max@max630.net","threadId":"38148","inReplyTo":"1418100283-8995-1-git-send-email-max@max630.net","subject":"[PATCH v3 2/3] path: implement common_dir handling in git_path_submodule()","fromName":"Max Kirillov","fromEmail":"max@max630.net","sentAt":"2014-12-09T04:44:42Z","receivedAt":"2014-12-09T04:44:42Z","isPatch":true,"sender":{"key":"max@max630.net","avatar":"https://avatars.githubusercontent.com/u/381560?v=4"},"body":"This allows making submodules a linked workdirs.\n\nSame as for .git, but ignores the GIT_COMMON_DIR environment variable,\nbecause it would mean common directory for the parent repository and\ndoes not make sense for submodule.\n\nAlso add test for functionality which uses this call.\n\nSigned-off-by: Max Kirillov <max@max630.net>\n---\n cache.h                          |  1 +\n path.c                           | 24 ++++++++++++++++++++----\n setup.c                          | 17 ++++++++++++-----\n t/t7410-submodule-checkout-to.sh | 10 ++++++++++\n 4 files changed, 43 insertions(+), 9 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 3f60a11..e8f465a 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -437,6 +437,7 @@ extern char *get_object_directory(void);\n extern char *get_index_file(void);\n extern char *get_graft_file(void);\n extern int set_git_dir(const char *path);\n+extern int get_common_dir_noenv(struct strbuf *sb, const char *gitdir);\n extern int get_common_dir(struct strbuf *sb, const char *gitdir);\n extern const char *get_git_namespace(void);\n extern const char *strip_namespace(const char *namespaced_ref);\ndiff --git a/path.c b/path.c\nindex a5c51a3..78f718f 100644\n--- a/path.c\n+++ b/path.c\n@@ -98,7 +98,7 @@ static const char *common_list[] = {\n \tNULL\n };\n \n-static void update_common_dir(struct strbuf *buf, int git_dir_len)\n+static void update_common_dir(struct strbuf *buf, int git_dir_len, const char* common_dir)\n {\n \tchar *base = buf->buf + git_dir_len;\n \tconst char **p;\n@@ -115,12 +115,17 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len)\n \t\t\tpath++;\n \t\t\tis_dir = 1;\n \t\t}\n+\n+\t\tif (!common_dir) {\n+\t\t\tcommon_dir = get_git_common_dir();\n+\t\t}\n+\n \t\tif (is_dir && dir_prefix(base, path)) {\n-\t\t\treplace_dir(buf, git_dir_len, get_git_common_dir());\n+\t\t\treplace_dir(buf, git_dir_len, common_dir);\n \t\t\treturn;\n \t\t}\n \t\tif (!is_dir && !strcmp(base, path)) {\n-\t\t\treplace_dir(buf, git_dir_len, get_git_common_dir());\n+\t\t\treplace_dir(buf, git_dir_len, common_dir);\n \t\t\treturn;\n \t\t}\n \t}\n@@ -160,7 +165,7 @@ static void adjust_git_path(struct strbuf *buf, int git_dir_len)\n \telse if (git_db_env && dir_prefix(base, \"objects\"))\n \t\treplace_dir(buf, git_dir_len + 7, get_object_directory());\n \telse if (git_common_dir_env)\n-\t\tupdate_common_dir(buf, git_dir_len);\n+\t\tupdate_common_dir(buf, git_dir_len, NULL);\n }\n \n static void do_git_path(struct strbuf *buf, const char *fmt, va_list args)\n@@ -256,6 +261,8 @@ const char *git_path_submodule(const char *path, const char *fmt, ...)\n {\n \tstruct strbuf *buf = get_pathname();\n \tconst char *git_dir;\n+\tstruct strbuf git_submodule_common_dir = STRBUF_INIT;\n+\tstruct strbuf git_submodule_dir = STRBUF_INIT;\n \tva_list args;\n \n \tstrbuf_addstr(buf, path);\n@@ -269,11 +276,20 @@ const char *git_path_submodule(const char *path, const char *fmt, ...)\n \t\tstrbuf_addstr(buf, git_dir);\n \t}\n \tstrbuf_addch(buf, '/');\n+\tstrbuf_addstr(&git_submodule_dir, buf->buf);\n \n \tva_start(args, fmt);\n \tstrbuf_vaddf(buf, fmt, args);\n \tva_end(args);\n+\n+\tif (get_common_dir_noenv(&git_submodule_common_dir, git_submodule_dir.buf)) {\n+\t\tupdate_common_dir(buf, git_submodule_dir.len, git_submodule_common_dir.buf);\n+\t}\n+\n \tstrbuf_cleanup_path(buf);\n+\n+\tstrbuf_release(&git_submodule_dir);\n+\tstrbuf_release(&git_submodule_common_dir);\n \treturn buf->buf;\n }\n \ndiff --git a/setup.c b/setup.c\nindex 05a8955..45e90c4 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -226,14 +226,21 @@ void verify_non_filename(const char *prefix, const char *arg)\n \n int get_common_dir(struct strbuf *sb, const char *gitdir)\n {\n+\tconst char *git_env_common_dir = getenv(GIT_COMMON_DIR_ENVIRONMENT);\n+\tif (git_env_common_dir) {\n+\t\tstrbuf_addstr(sb, git_env_common_dir);\n+\t\treturn 1;\n+\t} else {\n+\t\treturn get_common_dir_noenv(sb, gitdir);\n+\t}\n+}\n+\n+int get_common_dir_noenv(struct strbuf *sb, const char *gitdir)\n+{\n \tstruct strbuf data = STRBUF_INIT;\n \tstruct strbuf path = STRBUF_INIT;\n-\tconst char *git_common_dir = getenv(GIT_COMMON_DIR_ENVIRONMENT);\n \tint ret = 0;\n-\tif (git_common_dir) {\n-\t\tstrbuf_addstr(sb, git_common_dir);\n-\t\treturn 1;\n-\t}\n+\n \tstrbuf_addf(&path, \"%s/commondir\", gitdir);\n \tif (file_exists(path.buf)) {\n \t\tif (strbuf_read_file(&data, path.buf, 0) <= 0)\ndiff --git a/t/t7410-submodule-checkout-to.sh b/t/t7410-submodule-checkout-to.sh\nindex 8f30aed..b43391a 100755\n--- a/t/t7410-submodule-checkout-to.sh\n+++ b/t/t7410-submodule-checkout-to.sh\n@@ -47,4 +47,14 @@ test_expect_success 'checkout main and initialize independed clones' \\\n test_expect_success 'can see submodule diffs after independed cloning' \\\n     '(cd fully_cloned_submodule/main && git diff --submodule master\"^!\" | grep \"file1 updated\")'\n \n+test_expect_success 'checkout sub manually' \\\n+    'mkdir linked_submodule &&\n+    (cd clone/main &&\n+\tgit checkout --to \"$base_path/linked_submodule/main\" \"$rev1_hash_main\") &&\n+    (cd clone/main/sub &&\n+\tgit checkout --to \"$base_path/linked_submodule/main/sub\" \"$rev1_hash_sub\")'\n+\n+test_expect_success 'can see submodule diffs after manual checkout of linked submodule' \\\n+    '(cd linked_submodule/main && git diff --submodule master\"^!\" | grep \"file1 updated\")'\n+\n test_done\n-- \n2.2.0.50.gb2b6831\n"},{"id":"253401","messageId":"1418100283-8995-4-git-send-email-max@max630.net","threadId":"38148","inReplyTo":"1418100283-8995-1-git-send-email-max@max630.net","subject":"[PATCH v3 3/3] Add GIT_COMMON_DIR to local_repo_env","fromName":"Max Kirillov","fromEmail":"max@max630.net","sentAt":"2014-12-09T04:44:43Z","receivedAt":"2014-12-09T04:44:43Z","isPatch":true,"sender":{"key":"max@max630.net","avatar":"https://avatars.githubusercontent.com/u/381560?v=4"},"body":"This is obviously right thing to do, because submodule repository does\nnot use common directory of super repository.\n\nSuggested-by: Jens Lehmann <Jens.Lehmann@web.de>\nSigned-off-by: Max Kirillov <max@max630.net>\n---\n environment.c | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/environment.c b/environment.c\nindex 8351007..85ce3c4 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -94,6 +94,7 @@ const char * const local_repo_env[] = {\n \tCONFIG_DATA_ENVIRONMENT,\n \tDB_ENVIRONMENT,\n \tGIT_DIR_ENVIRONMENT,\n+\tGIT_COMMON_DIR_ENVIRONMENT,\n \tGIT_WORK_TREE_ENVIRONMENT,\n \tGIT_IMPLICIT_WORK_TREE_ENVIRONMENT,\n \tGRAFT_ENVIRONMENT,\n-- \n2.2.0.50.gb2b6831\n"},{"id":"253402","messageId":"20141209050435.GA9140@wheezy.local","threadId":"38148","inReplyTo":"1418100283-8995-1-git-send-email-max@max630.net","subject":"Re: [PATCH v3 0/3] Multiple worktrees vs. submodules fixes","fromName":"Max Kirillov","fromEmail":"max@max630.net","sentAt":"2014-12-09T05:04:35Z","receivedAt":"2014-12-09T05:04:35Z","isPatch":true,"sender":{"key":"max@max630.net","avatar":"https://avatars.githubusercontent.com/u/381560?v=4"},"body":"On Tue, Dec 09, 2014 at 06:44:40AM +0200, Max Kirillov wrote:\n> After discussions I came to basically same as v1.\n> \n> * Resubmitting the 2 patches which have not been taken to worktrees reroll -\n>   they fix visible issue. Mostly unchanged except small cleanup in test.\n> * Added GIT_COMMON_DIR to local_repo_env. While it is obviously a right\n>   thing, I wasn't able to observe any change in behavior.\n> \n> Max Kirillov (3):\n>   submodule refactor: use git_path_submodule() in add_submodule_odb()\n>   path: implement common_dir handling in git_path_submodule()\n>   Add GIT_COMMON_DIR to local_repo_env\n> \n>  cache.h                          |  1 +\n>  environment.c                    |  1 +\n>  path.c                           | 24 ++++++++++++++++++++----\n>  setup.c                          | 17 ++++++++++++-----\n>  submodule.c                      | 28 ++++++++++------------------\n>  t/t7410-submodule-checkout-to.sh | 10 ++++++++++\n>  6 files changed, 54 insertions(+), 27 deletions(-)\n> \n> -- \n> 2.2.0.50.gb2b6831\n>\n\nShould be applied on top of\nhttp://thread.gmane.org/gmane.comp.version-control.git/260387\nwith _all_ patches included, currently it's df56607dff\n\n-- \nMax\n"}]}