Skip to content

Commit 1012a5c

Browse files
chooglengitster
authored andcommitted
submodule--helper run-update-procedure: learn --remote
Teach run-update-procedure to handle --remote instead of parsing --remote in git-submodule.sh. As a result, "git submodule--helper [print-default-remote|remote-branch]" have no more callers, so remove them. Signed-off-by: Glen Choo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ed9c848 commit 1012a5c

File tree

2 files changed

+23
-63
lines changed

2 files changed

+23
-63
lines changed

builtin/submodule--helper.c

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,6 @@ static char *get_default_remote(void)
7272
return repo_get_default_remote(the_repository);
7373
}
7474

75-
static int print_default_remote(int argc, const char **argv, const char *prefix)
76-
{
77-
char *remote;
78-
79-
if (argc != 1)
80-
die(_("submodule--helper print-default-remote takes no arguments"));
81-
82-
remote = get_default_remote();
83-
if (remote)
84-
printf("%s\n", remote);
85-
86-
free(remote);
87-
return 0;
88-
}
89-
9075
static int starts_with_dot_slash(const char *str)
9176
{
9277
return str[0] == '.' && is_dir_sep(str[1]);
@@ -2027,6 +2012,7 @@ struct update_data {
20272012
unsigned int quiet;
20282013
unsigned int nofetch;
20292014
unsigned int just_cloned;
2015+
unsigned int remote;
20302016
};
20312017
#define UPDATE_DATA_INIT { .update_strategy = SUBMODULE_UPDATE_STRATEGY_INIT }
20322018

@@ -2603,6 +2589,8 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
26032589
OPT_CALLBACK_F(0, "oid", &update_data.oid, N_("sha1"),
26042590
N_("SHA1 expected by superproject"), PARSE_OPT_NONEG,
26052591
parse_opt_object_id),
2592+
OPT_BOOL(0, "remote", &update_data.remote,
2593+
N_("use SHA-1 of submodule's remote tracking branch")),
26062594
OPT_END()
26072595
};
26082596

@@ -2682,23 +2670,6 @@ static const char *remote_submodule_branch(const char *path)
26822670
return branch;
26832671
}
26842672

2685-
static int resolve_remote_submodule_branch(int argc, const char **argv,
2686-
const char *prefix)
2687-
{
2688-
const char *ret;
2689-
struct strbuf sb = STRBUF_INIT;
2690-
if (argc != 2)
2691-
die("submodule--helper remote-branch takes exactly one arguments, got %d", argc);
2692-
2693-
ret = remote_submodule_branch(argv[1]);
2694-
if (!ret)
2695-
die("submodule %s doesn't exist", argv[1]);
2696-
2697-
printf("%s", ret);
2698-
strbuf_release(&sb);
2699-
return 0;
2700-
}
2701-
27022673
static int push_check(int argc, const char **argv, const char *prefix)
27032674
{
27042675
struct remote *remote;
@@ -3040,6 +3011,25 @@ static int update_submodule2(struct update_data *update_data)
30403011
die(_("Unable to find current revision in submodule path '%s'"),
30413012
update_data->displaypath);
30423013

3014+
if (update_data->remote) {
3015+
char *remote_name = get_default_remote_submodule(update_data->sm_path);
3016+
const char *branch = remote_submodule_branch(update_data->sm_path);
3017+
char *remote_ref = xstrfmt("refs/remotes/%s/%s", remote_name, branch);
3018+
3019+
if (!update_data->nofetch) {
3020+
if (fetch_in_submodule(update_data->sm_path, update_data->depth,
3021+
0, NULL))
3022+
die(_("Unable to fetch in submodule path '%s'"),
3023+
update_data->sm_path);
3024+
}
3025+
3026+
if (resolve_gitlink_ref(update_data->sm_path, remote_ref, &update_data->oid))
3027+
die(_("Unable to find %s revision in submodule path '%s'"),
3028+
remote_ref, update_data->sm_path);
3029+
3030+
free(remote_ref);
3031+
}
3032+
30433033
if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force)
30443034
return do_run_update_procedure(update_data);
30453035

@@ -3439,11 +3429,9 @@ static struct cmd_struct commands[] = {
34393429
{"foreach", module_foreach, SUPPORT_SUPER_PREFIX},
34403430
{"init", module_init, SUPPORT_SUPER_PREFIX},
34413431
{"status", module_status, SUPPORT_SUPER_PREFIX},
3442-
{"print-default-remote", print_default_remote, 0},
34433432
{"sync", module_sync, SUPPORT_SUPER_PREFIX},
34443433
{"deinit", module_deinit, 0},
34453434
{"summary", module_summary, SUPPORT_SUPER_PREFIX},
3446-
{"remote-branch", resolve_remote_submodule_branch, 0},
34473435
{"push-check", push_check, 0},
34483436
{"absorb-git-dirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
34493437
{"is-active", is_active, 0},

git-submodule.sh

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -247,20 +247,6 @@ cmd_deinit()
247247
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${GIT_QUIET:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@"
248248
}
249249

250-
# usage: fetch_in_submodule <module_path> [<depth>] [<sha1>]
251-
# Because arguments are positional, use an empty string to omit <depth>
252-
# but include <sha1>.
253-
fetch_in_submodule () (
254-
sanitize_submodule_env &&
255-
cd "$1" &&
256-
if test $# -eq 3
257-
then
258-
echo "$3" | git fetch ${GIT_QUIET:+--quiet} --stdin ${2:+"$2"}
259-
else
260-
git fetch ${GIT_QUIET:+--quiet} ${2:+"$2"}
261-
fi
262-
)
263-
264250
#
265251
# Update each submodule path to correct revision, using clone and checkout as needed
266252
#
@@ -411,21 +397,6 @@ cmd_update()
411397
just_cloned=
412398
fi
413399

414-
if test -n "$remote"
415-
then
416-
branch=$(git submodule--helper remote-branch "$sm_path")
417-
if test -z "$nofetch"
418-
then
419-
# Fetch remote before determining tracking $sha1
420-
fetch_in_submodule "$sm_path" $depth ||
421-
die "fatal: $(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
422-
fi
423-
remote_name=$(sanitize_submodule_env; cd "$sm_path" && git submodule--helper print-default-remote)
424-
sha1=$(sanitize_submodule_env; cd "$sm_path" &&
425-
git rev-parse --verify "${remote_name}/${branch}") ||
426-
die "fatal: $(eval_gettext "Unable to find current \${remote_name}/\${branch} revision in submodule path '\$sm_path'")"
427-
fi
428-
429400
out=$(git submodule--helper run-update-procedure \
430401
${wt_prefix:+--prefix "$wt_prefix"} \
431402
${GIT_QUIET:+--quiet} \
@@ -436,6 +407,7 @@ cmd_update()
436407
${update:+--update "$update"} \
437408
${prefix:+--recursive-prefix "$prefix"} \
438409
${sha1:+--oid "$sha1"} \
410+
${remote:+--remote} \
439411
"--" \
440412
"$sm_path")
441413

0 commit comments

Comments
 (0)