summaryrefslogtreecommitdiff
path: root/path.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-10-15 15:43:31 -0700
committerJunio C Hamano <gitster@pobox.com>2015-10-15 15:43:32 -0700
commit1c630badacc2de43b03212bcca0f3a9ec99fba13 (patch)
tree7e11d8ed8359f7bdf82bb40039d5635841ef2572 /path.c
parentb27dacc1a80d1eca1994e6552d913e42d517f998 (diff)
parent11f9dd719104a960d3e2b478477d9055141d1dbc (diff)
downloadgit-1c630badacc2de43b03212bcca0f3a9ec99fba13.tar.gz
Merge branch 'mk/submodule-gitdir-path'
The submodule code has been taught to work better with separate work trees created via "git worktree add". * mk/submodule-gitdir-path: path: implement common_dir handling in git_pathdup_submodule() submodule refactor: use strbuf_git_path_submodule() in add_submodule_odb()
Diffstat (limited to 'path.c')
-rw-r--r--path.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/path.c b/path.c
index 65beb2dca3..5ec34905a3 100644
--- a/path.c
+++ b/path.c
@@ -335,12 +335,15 @@ static int check_common(const char *unmatched, void *value, void *baton)
return 0;
}
-static void update_common_dir(struct strbuf *buf, int git_dir_len)
+static void update_common_dir(struct strbuf *buf, int git_dir_len,
+ const char *common_dir)
{
char *base = buf->buf + git_dir_len;
init_common_trie();
+ if (!common_dir)
+ common_dir = get_git_common_dir();
if (trie_find(&common_trie, base, check_common, NULL) > 0)
- replace_dir(buf, git_dir_len, get_git_common_dir());
+ replace_dir(buf, git_dir_len, common_dir);
}
void report_linked_checkout_garbage(void)
@@ -377,7 +380,7 @@ static void adjust_git_path(struct strbuf *buf, int git_dir_len)
else if (git_db_env && dir_prefix(base, "objects"))
replace_dir(buf, git_dir_len + 7, get_object_directory());
else if (git_common_dir_env)
- update_common_dir(buf, git_dir_len);
+ update_common_dir(buf, git_dir_len, NULL);
}
static void do_git_path(struct strbuf *buf, const char *fmt, va_list args)
@@ -445,6 +448,8 @@ static void do_submodule_path(struct strbuf *buf, const char *path,
const char *fmt, va_list args)
{
const char *git_dir;
+ struct strbuf git_submodule_common_dir = STRBUF_INIT;
+ struct strbuf git_submodule_dir = STRBUF_INIT;
strbuf_addstr(buf, path);
if (buf->len && buf->buf[buf->len - 1] != '/')
@@ -457,9 +462,17 @@ static void do_submodule_path(struct strbuf *buf, const char *path,
strbuf_addstr(buf, git_dir);
}
strbuf_addch(buf, '/');
+ strbuf_addstr(&git_submodule_dir, buf->buf);
strbuf_vaddf(buf, fmt, args);
+
+ if (get_common_dir_noenv(&git_submodule_common_dir, git_submodule_dir.buf))
+ update_common_dir(buf, git_submodule_dir.len, git_submodule_common_dir.buf);
+
strbuf_cleanup_path(buf);
+
+ strbuf_release(&git_submodule_dir);
+ strbuf_release(&git_submodule_common_dir);
}
char *git_pathdup_submodule(const char *path, const char *fmt, ...)
@@ -648,7 +661,7 @@ const char *enter_repo(const char *path, int strict)
}
if (!suffix[i])
return NULL;
- gitfile = read_gitfile(used_path) ;
+ gitfile = read_gitfile(used_path);
if (gitfile)
strcpy(used_path, gitfile);
if (chdir(used_path))