Merge branch 'gc/submodule-use-super-prefix'
Another step to rewrite more parts of "git submodule" in C. * gc/submodule-use-super-prefix: submodule--helper: remove display path helper submodule--helper update: use --super-prefix submodule--helper: remove unused SUPPORT_SUPER_PREFIX flags submodule--helper: use correct display path helper submodule--helper: don't recreate recursive prefix submodule--helper update: use display path helper submodule--helper tests: add missing "display path" coverage
This commit is contained in:
commit
6d003858e5
@ -118,10 +118,11 @@ static int resolve_relative_url_test(int argc, const char **argv, const char *pr
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *do_get_submodule_displaypath(const char *path,
|
/* the result should be freed by the caller. */
|
||||||
const char *prefix,
|
static char *get_submodule_displaypath(const char *path, const char *prefix)
|
||||||
const char *super_prefix)
|
|
||||||
{
|
{
|
||||||
|
const char *super_prefix = get_super_prefix();
|
||||||
|
|
||||||
if (prefix && super_prefix) {
|
if (prefix && super_prefix) {
|
||||||
BUG("cannot have prefix '%s' and superprefix '%s'",
|
BUG("cannot have prefix '%s' and superprefix '%s'",
|
||||||
prefix, super_prefix);
|
prefix, super_prefix);
|
||||||
@ -137,13 +138,6 @@ static char *do_get_submodule_displaypath(const char *path,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the result should be freed by the caller. */
|
|
||||||
static char *get_submodule_displaypath(const char *path, const char *prefix)
|
|
||||||
{
|
|
||||||
const char *super_prefix = get_super_prefix();
|
|
||||||
return do_get_submodule_displaypath(path, prefix, super_prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *compute_rev_name(const char *sub_path, const char* object_id)
|
static char *compute_rev_name(const char *sub_path, const char* object_id)
|
||||||
{
|
{
|
||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
@ -477,22 +471,18 @@ static int starts_with_dot_dot_slash(const char *const path)
|
|||||||
|
|
||||||
struct init_cb {
|
struct init_cb {
|
||||||
const char *prefix;
|
const char *prefix;
|
||||||
const char *superprefix;
|
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
};
|
};
|
||||||
#define INIT_CB_INIT { 0 }
|
#define INIT_CB_INIT { 0 }
|
||||||
|
|
||||||
static void init_submodule(const char *path, const char *prefix,
|
static void init_submodule(const char *path, const char *prefix,
|
||||||
const char *superprefix, unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
const struct submodule *sub;
|
const struct submodule *sub;
|
||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
char *upd = NULL, *url = NULL, *displaypath;
|
char *upd = NULL, *url = NULL, *displaypath;
|
||||||
|
|
||||||
/* try superprefix from the environment, if it is not passed explicitly */
|
displaypath = get_submodule_displaypath(path, prefix);
|
||||||
if (!superprefix)
|
|
||||||
superprefix = get_super_prefix();
|
|
||||||
displaypath = do_get_submodule_displaypath(path, prefix, superprefix);
|
|
||||||
|
|
||||||
sub = submodule_from_path(the_repository, null_oid(), path);
|
sub = submodule_from_path(the_repository, null_oid(), path);
|
||||||
|
|
||||||
@ -566,7 +556,7 @@ static void init_submodule(const char *path, const char *prefix,
|
|||||||
static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data)
|
static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data)
|
||||||
{
|
{
|
||||||
struct init_cb *info = cb_data;
|
struct init_cb *info = cb_data;
|
||||||
init_submodule(list_item->name, info->prefix, info->superprefix, info->flags);
|
init_submodule(list_item->name, info->prefix, info->flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int module_init(int argc, const char **argv, const char *prefix)
|
static int module_init(int argc, const char **argv, const char *prefix)
|
||||||
@ -1878,7 +1868,6 @@ struct submodule_update_clone {
|
|||||||
|
|
||||||
struct update_data {
|
struct update_data {
|
||||||
const char *prefix;
|
const char *prefix;
|
||||||
const char *recursive_prefix;
|
|
||||||
const char *displaypath;
|
const char *displaypath;
|
||||||
enum submodule_update_type update_default;
|
enum submodule_update_type update_default;
|
||||||
struct object_id suboid;
|
struct object_id suboid;
|
||||||
@ -1947,30 +1936,20 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
|
|||||||
const char *update_string;
|
const char *update_string;
|
||||||
enum submodule_update_type update_type;
|
enum submodule_update_type update_type;
|
||||||
char *key;
|
char *key;
|
||||||
struct strbuf displaypath_sb = STRBUF_INIT;
|
struct update_data *ud = suc->update_data;
|
||||||
|
char *displaypath = get_submodule_displaypath(ce->name, ud->prefix);
|
||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
const char *displaypath = NULL;
|
|
||||||
int needs_cloning = 0;
|
int needs_cloning = 0;
|
||||||
int need_free_url = 0;
|
int need_free_url = 0;
|
||||||
|
|
||||||
if (ce_stage(ce)) {
|
if (ce_stage(ce)) {
|
||||||
if (suc->update_data->recursive_prefix)
|
strbuf_addf(out, _("Skipping unmerged submodule %s"), displaypath);
|
||||||
strbuf_addf(&sb, "%s/%s", suc->update_data->recursive_prefix, ce->name);
|
|
||||||
else
|
|
||||||
strbuf_addstr(&sb, ce->name);
|
|
||||||
strbuf_addf(out, _("Skipping unmerged submodule %s"), sb.buf);
|
|
||||||
strbuf_addch(out, '\n');
|
strbuf_addch(out, '\n');
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub = submodule_from_path(the_repository, null_oid(), ce->name);
|
sub = submodule_from_path(the_repository, null_oid(), ce->name);
|
||||||
|
|
||||||
if (suc->update_data->recursive_prefix)
|
|
||||||
displaypath = relative_path(suc->update_data->recursive_prefix,
|
|
||||||
ce->name, &displaypath_sb);
|
|
||||||
else
|
|
||||||
displaypath = ce->name;
|
|
||||||
|
|
||||||
if (!sub) {
|
if (!sub) {
|
||||||
next_submodule_warn_missing(suc, out, displaypath);
|
next_submodule_warn_missing(suc, out, displaypath);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -2060,7 +2039,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
|
|||||||
"--no-single-branch");
|
"--no-single-branch");
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
strbuf_release(&displaypath_sb);
|
free(displaypath);
|
||||||
strbuf_release(&sb);
|
strbuf_release(&sb);
|
||||||
if (need_free_url)
|
if (need_free_url)
|
||||||
free((void*)url);
|
free((void*)url);
|
||||||
@ -2424,11 +2403,12 @@ static void update_data_to_args(struct update_data *update_data, struct strvec *
|
|||||||
{
|
{
|
||||||
enum submodule_update_type update_type = update_data->update_default;
|
enum submodule_update_type update_type = update_data->update_default;
|
||||||
|
|
||||||
|
if (update_data->displaypath) {
|
||||||
|
strvec_push(args, "--super-prefix");
|
||||||
|
strvec_pushf(args, "%s/", update_data->displaypath);
|
||||||
|
}
|
||||||
strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL);
|
strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL);
|
||||||
strvec_pushf(args, "--jobs=%d", update_data->max_jobs);
|
strvec_pushf(args, "--jobs=%d", update_data->max_jobs);
|
||||||
if (update_data->recursive_prefix)
|
|
||||||
strvec_pushl(args, "--recursive-prefix",
|
|
||||||
update_data->recursive_prefix, NULL);
|
|
||||||
if (update_data->quiet)
|
if (update_data->quiet)
|
||||||
strvec_push(args, "--quiet");
|
strvec_push(args, "--quiet");
|
||||||
if (update_data->force)
|
if (update_data->force)
|
||||||
@ -2472,19 +2452,10 @@ static void update_data_to_args(struct update_data *update_data, struct strvec *
|
|||||||
|
|
||||||
static int update_submodule(struct update_data *update_data)
|
static int update_submodule(struct update_data *update_data)
|
||||||
{
|
{
|
||||||
char *prefixed_path;
|
|
||||||
|
|
||||||
ensure_core_worktree(update_data->sm_path);
|
ensure_core_worktree(update_data->sm_path);
|
||||||
|
|
||||||
if (update_data->recursive_prefix)
|
update_data->displaypath = get_submodule_displaypath(
|
||||||
prefixed_path = xstrfmt("%s%s", update_data->recursive_prefix,
|
update_data->sm_path, update_data->prefix);
|
||||||
update_data->sm_path);
|
|
||||||
else
|
|
||||||
prefixed_path = xstrdup(update_data->sm_path);
|
|
||||||
|
|
||||||
update_data->displaypath = get_submodule_displaypath(prefixed_path,
|
|
||||||
update_data->prefix);
|
|
||||||
free(prefixed_path);
|
|
||||||
|
|
||||||
determine_submodule_update_strategy(the_repository, update_data->just_cloned,
|
determine_submodule_update_strategy(the_repository, update_data->just_cloned,
|
||||||
update_data->sm_path, update_data->update_default,
|
update_data->sm_path, update_data->update_default,
|
||||||
@ -2524,14 +2495,6 @@ static int update_submodule(struct update_data *update_data)
|
|||||||
struct update_data next = *update_data;
|
struct update_data next = *update_data;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
if (update_data->recursive_prefix)
|
|
||||||
prefixed_path = xstrfmt("%s%s/", update_data->recursive_prefix,
|
|
||||||
update_data->sm_path);
|
|
||||||
else
|
|
||||||
prefixed_path = xstrfmt("%s/", update_data->sm_path);
|
|
||||||
|
|
||||||
next.recursive_prefix = get_submodule_displaypath(prefixed_path,
|
|
||||||
update_data->prefix);
|
|
||||||
next.prefix = NULL;
|
next.prefix = NULL;
|
||||||
oidcpy(&next.oid, null_oid());
|
oidcpy(&next.oid, null_oid());
|
||||||
oidcpy(&next.suboid, null_oid());
|
oidcpy(&next.suboid, null_oid());
|
||||||
@ -2616,10 +2579,6 @@ static int module_update(int argc, const char **argv, const char *prefix)
|
|||||||
OPT_STRING(0, "prefix", &opt.prefix,
|
OPT_STRING(0, "prefix", &opt.prefix,
|
||||||
N_("path"),
|
N_("path"),
|
||||||
N_("path into the working tree")),
|
N_("path into the working tree")),
|
||||||
OPT_STRING(0, "recursive-prefix", &opt.recursive_prefix,
|
|
||||||
N_("path"),
|
|
||||||
N_("path into the working tree, across nested "
|
|
||||||
"submodule boundaries")),
|
|
||||||
OPT_SET_INT(0, "checkout", &opt.update_default,
|
OPT_SET_INT(0, "checkout", &opt.update_default,
|
||||||
N_("use the 'checkout' update strategy (default)"),
|
N_("use the 'checkout' update strategy (default)"),
|
||||||
SM_UPDATE_CHECKOUT),
|
SM_UPDATE_CHECKOUT),
|
||||||
@ -2705,7 +2664,6 @@ static int module_update(int argc, const char **argv, const char *prefix)
|
|||||||
module_list_active(&list);
|
module_list_active(&list);
|
||||||
|
|
||||||
info.prefix = opt.prefix;
|
info.prefix = opt.prefix;
|
||||||
info.superprefix = opt.recursive_prefix;
|
|
||||||
if (opt.quiet)
|
if (opt.quiet)
|
||||||
info.flags |= OPT_QUIET;
|
info.flags |= OPT_QUIET;
|
||||||
|
|
||||||
@ -3402,16 +3360,16 @@ struct cmd_struct {
|
|||||||
static struct cmd_struct commands[] = {
|
static struct cmd_struct commands[] = {
|
||||||
{"list", module_list, 0},
|
{"list", module_list, 0},
|
||||||
{"name", module_name, 0},
|
{"name", module_name, 0},
|
||||||
{"clone", module_clone, 0},
|
{"clone", module_clone, SUPPORT_SUPER_PREFIX},
|
||||||
{"add", module_add, SUPPORT_SUPER_PREFIX},
|
{"add", module_add, 0},
|
||||||
{"update", module_update, 0},
|
{"update", module_update, SUPPORT_SUPER_PREFIX},
|
||||||
{"resolve-relative-url-test", resolve_relative_url_test, 0},
|
{"resolve-relative-url-test", resolve_relative_url_test, 0},
|
||||||
{"foreach", module_foreach, SUPPORT_SUPER_PREFIX},
|
{"foreach", module_foreach, SUPPORT_SUPER_PREFIX},
|
||||||
{"init", module_init, SUPPORT_SUPER_PREFIX},
|
{"init", module_init, 0},
|
||||||
{"status", module_status, SUPPORT_SUPER_PREFIX},
|
{"status", module_status, SUPPORT_SUPER_PREFIX},
|
||||||
{"sync", module_sync, SUPPORT_SUPER_PREFIX},
|
{"sync", module_sync, SUPPORT_SUPER_PREFIX},
|
||||||
{"deinit", module_deinit, 0},
|
{"deinit", module_deinit, 0},
|
||||||
{"summary", module_summary, SUPPORT_SUPER_PREFIX},
|
{"summary", module_summary, 0},
|
||||||
{"push-check", push_check, 0},
|
{"push-check", push_check, 0},
|
||||||
{"absorbgitdirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
|
{"absorbgitdirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
|
||||||
{"is-active", is_active, 0},
|
{"is-active", is_active, 0},
|
||||||
|
@ -1116,4 +1116,66 @@ test_expect_success 'submodule update --filter sets partial clone settings' '
|
|||||||
test_cmp_config -C super-filter/submodule blob:none remote.origin.partialclonefilter
|
test_cmp_config -C super-filter/submodule blob:none remote.origin.partialclonefilter
|
||||||
'
|
'
|
||||||
|
|
||||||
|
# NEEDSWORK: Clean up the tests so that we can reuse the test setup.
|
||||||
|
# Don't reuse the existing repos because the earlier tests have
|
||||||
|
# intentionally disruptive configurations.
|
||||||
|
test_expect_success 'setup clean recursive superproject' '
|
||||||
|
git init bottom &&
|
||||||
|
test_commit -C bottom "bottom" &&
|
||||||
|
git init middle &&
|
||||||
|
git -C middle submodule add ../bottom bottom &&
|
||||||
|
git -C middle commit -m "middle" &&
|
||||||
|
git init top &&
|
||||||
|
git -C top submodule add ../middle middle &&
|
||||||
|
git -C top commit -m "top" &&
|
||||||
|
git clone --recurse-submodules top top-clean
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'submodule update should skip unmerged submodules' '
|
||||||
|
test_when_finished "rm -fr top-cloned" &&
|
||||||
|
cp -r top-clean top-cloned &&
|
||||||
|
|
||||||
|
# Create an upstream commit in each repo, starting with bottom
|
||||||
|
test_commit -C bottom upstream_commit &&
|
||||||
|
# Create middle commit
|
||||||
|
git -C middle/bottom fetch &&
|
||||||
|
git -C middle/bottom checkout -f FETCH_HEAD &&
|
||||||
|
git -C middle add bottom &&
|
||||||
|
git -C middle commit -m "upstream_commit" &&
|
||||||
|
# Create top commit
|
||||||
|
git -C top/middle fetch &&
|
||||||
|
git -C top/middle checkout -f FETCH_HEAD &&
|
||||||
|
git -C top add middle &&
|
||||||
|
git -C top commit -m "upstream_commit" &&
|
||||||
|
|
||||||
|
# Create a downstream conflict
|
||||||
|
test_commit -C top-cloned/middle/bottom downstream_commit &&
|
||||||
|
git -C top-cloned/middle add bottom &&
|
||||||
|
git -C top-cloned/middle commit -m "downstream_commit" &&
|
||||||
|
git -C top-cloned/middle fetch --recurse-submodules origin &&
|
||||||
|
test_must_fail git -C top-cloned/middle merge origin/main &&
|
||||||
|
|
||||||
|
# Make the update of "middle" a no-op, otherwise we error out
|
||||||
|
# because of its unmerged state
|
||||||
|
test_config -C top-cloned submodule.middle.update !true &&
|
||||||
|
git -C top-cloned submodule update --recursive 2>actual.err &&
|
||||||
|
cat >expect.err <<-\EOF &&
|
||||||
|
Skipping unmerged submodule middle/bottom
|
||||||
|
EOF
|
||||||
|
test_cmp expect.err actual.err
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'submodule update --recursive skip submodules with strategy=none' '
|
||||||
|
test_when_finished "rm -fr top-cloned" &&
|
||||||
|
cp -r top-clean top-cloned &&
|
||||||
|
|
||||||
|
test_commit -C top-cloned/middle/bottom downstream_commit &&
|
||||||
|
git -C top-cloned/middle config submodule.bottom.update none &&
|
||||||
|
git -C top-cloned submodule update --recursive 2>actual.err &&
|
||||||
|
cat >expect.err <<-\EOF &&
|
||||||
|
Skipping submodule '\''middle/bottom'\''
|
||||||
|
EOF
|
||||||
|
test_cmp expect.err actual.err
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user