Skip to content

Commit 74d4731

Browse files
stefanbellergitster
authored andcommitted
submodule--helper: replace connect-gitdir-workingtree by ensure-core-worktree
e983175 (submodule: ensure core.worktree is set after update, 2018-06-18) was overly aggressive in calling connect_work_tree_and_git_dir as that ensures both the 'core.worktree' configuration is set as well as setting up correct gitlink file pointing at the git directory. We do not need to check for the gitlink in this part of the cmd_update in git-submodule.sh, as the initial call to update-clone will have ensured that. So we can reduce the work to only (check and potentially) set the 'core.worktree' setting. While at it move the check from shell to C as that proves to be useful in a follow up patch, as we do not need the 'name' in shell now. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c94d9dc commit 74d4731

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

builtin/submodule--helper.c

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,6 +1964,45 @@ static int push_check(int argc, const char **argv, const char *prefix)
19641964
return 0;
19651965
}
19661966

1967+
static int ensure_core_worktree(int argc, const char **argv, const char *prefix)
1968+
{
1969+
const struct submodule *sub;
1970+
const char *path;
1971+
char *cw;
1972+
struct repository subrepo;
1973+
1974+
if (argc != 2)
1975+
BUG("submodule--helper connect-gitdir-workingtree <name> <path>");
1976+
1977+
path = argv[1];
1978+
1979+
sub = submodule_from_path(the_repository, &null_oid, path);
1980+
if (!sub)
1981+
BUG("We could get the submodule handle before?");
1982+
1983+
if (repo_submodule_init(&subrepo, the_repository, path))
1984+
die(_("could not get a repository handle for submodule '%s'"), path);
1985+
1986+
if (!repo_config_get_string(&subrepo, "core.worktree", &cw)) {
1987+
char *cfg_file, *abs_path;
1988+
const char *rel_path;
1989+
struct strbuf sb = STRBUF_INIT;
1990+
1991+
cfg_file = repo_git_path(&subrepo, "config");
1992+
1993+
abs_path = absolute_pathdup(path);
1994+
rel_path = relative_path(abs_path, subrepo.gitdir, &sb);
1995+
1996+
git_config_set_in_file(cfg_file, "core.worktree", rel_path);
1997+
1998+
free(cfg_file);
1999+
free(abs_path);
2000+
strbuf_release(&sb);
2001+
}
2002+
2003+
return 0;
2004+
}
2005+
19672006
static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
19682007
{
19692008
int i;
@@ -2029,29 +2068,6 @@ static int check_name(int argc, const char **argv, const char *prefix)
20292068
return 0;
20302069
}
20312070

2032-
static int connect_gitdir_workingtree(int argc, const char **argv, const char *prefix)
2033-
{
2034-
struct strbuf sb = STRBUF_INIT;
2035-
const char *name, *path;
2036-
char *sm_gitdir;
2037-
2038-
if (argc != 3)
2039-
BUG("submodule--helper connect-gitdir-workingtree <name> <path>");
2040-
2041-
name = argv[1];
2042-
path = argv[2];
2043-
2044-
strbuf_addf(&sb, "%s/modules/%s", get_git_dir(), name);
2045-
sm_gitdir = absolute_pathdup(sb.buf);
2046-
2047-
connect_work_tree_and_git_dir(path, sm_gitdir, 0);
2048-
2049-
strbuf_release(&sb);
2050-
free(sm_gitdir);
2051-
2052-
return 0;
2053-
}
2054-
20552071
#define SUPPORT_SUPER_PREFIX (1<<0)
20562072

20572073
struct cmd_struct {
@@ -2065,7 +2081,7 @@ static struct cmd_struct commands[] = {
20652081
{"name", module_name, 0},
20662082
{"clone", module_clone, 0},
20672083
{"update-clone", update_clone, 0},
2068-
{"connect-gitdir-workingtree", connect_gitdir_workingtree, 0},
2084+
{"ensure-core-worktree", ensure_core_worktree, 0},
20692085
{"relative-path", resolve_relative_path, 0},
20702086
{"resolve-relative-url", resolve_relative_url, 0},
20712087
{"resolve-relative-url-test", resolve_relative_url_test, 0},

git-submodule.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,8 @@ cmd_update()
535535
do
536536
die_if_unmatched "$quickabort" "$sha1"
537537

538+
git submodule--helper ensure-core-worktree "$sm_path"
539+
538540
name=$(git submodule--helper name "$sm_path") || exit
539541
if ! test -z "$update"
540542
then
@@ -577,11 +579,6 @@ cmd_update()
577579
die "$(eval_gettext "Unable to find current \${remote_name}/\${branch} revision in submodule path '\$sm_path'")"
578580
fi
579581

580-
if ! $(git config -f "$(git rev-parse --git-common-dir)/modules/$name/config" core.worktree) 2>/dev/null
581-
then
582-
git submodule--helper connect-gitdir-workingtree "$name" "$sm_path"
583-
fi
584-
585582
if test "$subsha1" != "$sha1" || test -n "$force"
586583
then
587584
subforce=$force

0 commit comments

Comments
 (0)