Skip to content

Commit 88457a6

Browse files
committed
Merge branch 'ps/submodule-ref-format'
Support to specify ref backend for submodules has been enhanced. * ps/submodule-ref-format: object: fix leaking packfiles when closing object store submodule: fix leaking seen submodule names submodule: fix leaking fetch tasks builtin/submodule: allow "add" to use different ref storage format refs: fix ref storage format for submodule ref stores builtin/clone: propagate ref storage format to submodules builtin/submodule: allow cloning with different ref storage format git-submodule.sh: break overly long command lines
2 parents 6891103 + 6f1e939 commit 88457a6

10 files changed

+298
-25
lines changed

Documentation/git-submodule.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ COMMANDS
3434
With no arguments, shows the status of existing submodules. Several
3535
subcommands are available to perform operations on the submodules.
3636

37-
add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--depth <depth>] [--] <repository> [<path>]::
37+
add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--ref-format <format>] [--depth <depth>] [--] <repository> [<path>]::
3838
Add the given repository as a submodule at the given path
3939
to the changeset to be committed next to the current
4040
project: the current project is termed the "superproject".
@@ -71,6 +71,9 @@ submodule repositories will be kept together in the same relative
7171
location, and only the superproject's URL needs to be provided.
7272
git-submodule will correctly locate the submodule using the relative
7373
URL in `.gitmodules`.
74+
+
75+
If `--ref-format <format>` is specified, the ref storage format of newly
76+
cloned submodules will be set accordingly.
7477

7578
status [--cached] [--recursive] [--] [<path>...]::
7679
Show the status of the submodules. This will print the SHA-1 of the
@@ -136,7 +139,7 @@ If you really want to remove a submodule from the repository and commit
136139
that use linkgit:git-rm[1] instead. See linkgit:gitsubmodules[7] for removal
137140
options.
138141

139-
update [--init] [--remote] [-N|--no-fetch] [--[no-]recommend-shallow] [-f|--force] [--checkout|--rebase|--merge] [--reference <repository>] [--depth <depth>] [--recursive] [--jobs <n>] [--[no-]single-branch] [--filter <filter-spec>] [--] [<path>...]::
142+
update [--init] [--remote] [-N|--no-fetch] [--[no-]recommend-shallow] [-f|--force] [--checkout|--rebase|--merge] [--reference <repository>] [--ref-format <format>] [--depth <depth>] [--recursive] [--jobs <n>] [--[no-]single-branch] [--filter <filter-spec>] [--] [<path>...]::
140143
+
141144
--
142145
Update the registered submodules to match what the superproject
@@ -185,6 +188,9 @@ submodule with the `--init` option.
185188
If `--recursive` is specified, this command will recurse into the
186189
registered submodules, and update any nested submodules within.
187190

191+
If `--ref-format <format>` is specified, the ref storage format of newly
192+
cloned submodules will be set accordingly.
193+
188194
If `--filter <filter-spec>` is specified, the given partial clone filter will be
189195
applied to the submodule. See linkgit:git-rev-list[1] for details on filter
190196
specifications.

builtin/clone.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,8 @@ static int git_sparse_checkout_init(const char *repo)
729729
return result;
730730
}
731731

732-
static int checkout(int submodule_progress, int filter_submodules)
732+
static int checkout(int submodule_progress, int filter_submodules,
733+
enum ref_storage_format ref_storage_format)
733734
{
734735
struct object_id oid;
735736
char *head;
@@ -813,6 +814,10 @@ static int checkout(int submodule_progress, int filter_submodules)
813814
strvec_push(&cmd.args, "--no-fetch");
814815
}
815816

817+
if (ref_storage_format != REF_STORAGE_FORMAT_UNKNOWN)
818+
strvec_pushf(&cmd.args, "--ref-format=%s",
819+
ref_storage_format_to_name(ref_storage_format));
820+
816821
if (filter_submodules && filter_options.choice)
817822
strvec_pushf(&cmd.args, "--filter=%s",
818823
expand_list_objects_filter_spec(&filter_options));
@@ -1536,7 +1541,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
15361541
return 1;
15371542

15381543
junk_mode = JUNK_LEAVE_REPO;
1539-
err = checkout(submodule_progress, filter_submodules);
1544+
err = checkout(submodule_progress, filter_submodules,
1545+
ref_storage_format);
15401546

15411547
free(remote_name);
15421548
strbuf_release(&reflog_msg);

builtin/submodule--helper.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,7 @@ struct module_clone_data {
15321532
const char *url;
15331533
int depth;
15341534
struct list_objects_filter_options *filter_options;
1535+
enum ref_storage_format ref_storage_format;
15351536
unsigned int quiet: 1;
15361537
unsigned int progress: 1;
15371538
unsigned int dissociate: 1;
@@ -1540,6 +1541,7 @@ struct module_clone_data {
15401541
};
15411542
#define MODULE_CLONE_DATA_INIT { \
15421543
.single_branch = -1, \
1544+
.ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN, \
15431545
}
15441546

15451547
struct submodule_alternate_setup {
@@ -1738,6 +1740,9 @@ static int clone_submodule(const struct module_clone_data *clone_data,
17381740
strvec_pushl(&cp.args, "--reference",
17391741
item->string, NULL);
17401742
}
1743+
if (clone_data->ref_storage_format != REF_STORAGE_FORMAT_UNKNOWN)
1744+
strvec_pushf(&cp.args, "--ref-format=%s",
1745+
ref_storage_format_to_name(clone_data->ref_storage_format));
17411746
if (clone_data->dissociate)
17421747
strvec_push(&cp.args, "--dissociate");
17431748
if (sm_gitdir && *sm_gitdir)
@@ -1832,6 +1837,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
18321837
struct string_list reference = STRING_LIST_INIT_NODUP;
18331838
struct list_objects_filter_options filter_options =
18341839
LIST_OBJECTS_FILTER_INIT;
1840+
const char *ref_storage_format = NULL;
18351841

18361842
struct option module_clone_options[] = {
18371843
OPT_STRING(0, "prefix", &clone_data.prefix,
@@ -1849,6 +1855,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)
18491855
OPT_STRING_LIST(0, "reference", &reference,
18501856
N_("repo"),
18511857
N_("reference repository")),
1858+
OPT_STRING(0, "ref-format", &ref_storage_format, N_("format"),
1859+
N_("specify the reference format to use")),
18521860
OPT_BOOL(0, "dissociate", &dissociate,
18531861
N_("use --reference only while cloning")),
18541862
OPT_INTEGER(0, "depth", &clone_data.depth,
@@ -1874,6 +1882,11 @@ static int module_clone(int argc, const char **argv, const char *prefix)
18741882
argc = parse_options(argc, argv, prefix, module_clone_options,
18751883
git_submodule_helper_usage, 0);
18761884

1885+
if (ref_storage_format) {
1886+
clone_data.ref_storage_format = ref_storage_format_by_name(ref_storage_format);
1887+
if (clone_data.ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
1888+
die(_("unknown ref storage format '%s'"), ref_storage_format);
1889+
}
18771890
clone_data.dissociate = !!dissociate;
18781891
clone_data.quiet = !!quiet;
18791892
clone_data.progress = !!progress;
@@ -1973,6 +1986,7 @@ struct update_data {
19731986
struct submodule_update_strategy update_strategy;
19741987
struct list_objects_filter_options *filter_options;
19751988
struct module_list list;
1989+
enum ref_storage_format ref_storage_format;
19761990
int depth;
19771991
int max_jobs;
19781992
int single_branch;
@@ -1996,6 +2010,7 @@ struct update_data {
19962010
#define UPDATE_DATA_INIT { \
19972011
.update_strategy = SUBMODULE_UPDATE_STRATEGY_INIT, \
19982012
.list = MODULE_LIST_INIT, \
2013+
.ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN, \
19992014
.recommend_shallow = -1, \
20002015
.references = STRING_LIST_INIT_DUP, \
20012016
.single_branch = -1, \
@@ -2131,6 +2146,9 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
21312146
expand_list_objects_filter_spec(suc->update_data->filter_options));
21322147
if (suc->update_data->require_init)
21332148
strvec_push(&child->args, "--require-init");
2149+
if (suc->update_data->ref_storage_format != REF_STORAGE_FORMAT_UNKNOWN)
2150+
strvec_pushf(&child->args, "--ref-format=%s",
2151+
ref_storage_format_to_name(suc->update_data->ref_storage_format));
21342152
strvec_pushl(&child->args, "--path", sub->path, NULL);
21352153
strvec_pushl(&child->args, "--name", sub->name, NULL);
21362154
strvec_pushl(&child->args, "--url", url, NULL);
@@ -2565,6 +2583,9 @@ static void update_data_to_args(const struct update_data *update_data,
25652583
for_each_string_list_item(item, &update_data->references)
25662584
strvec_pushl(args, "--reference", item->string, NULL);
25672585
}
2586+
if (update_data->ref_storage_format != REF_STORAGE_FORMAT_UNKNOWN)
2587+
strvec_pushf(args, "--ref-format=%s",
2588+
ref_storage_format_to_name(update_data->ref_storage_format));
25682589
if (update_data->filter_options && update_data->filter_options->choice)
25692590
strvec_pushf(args, "--filter=%s",
25702591
expand_list_objects_filter_spec(
@@ -2740,6 +2761,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
27402761
struct update_data opt = UPDATE_DATA_INIT;
27412762
struct list_objects_filter_options filter_options =
27422763
LIST_OBJECTS_FILTER_INIT;
2764+
const char *ref_storage_format = NULL;
27432765
int ret;
27442766
struct option module_update_options[] = {
27452767
OPT__SUPER_PREFIX(&opt.super_prefix),
@@ -2763,6 +2785,8 @@ static int module_update(int argc, const char **argv, const char *prefix)
27632785
SM_UPDATE_REBASE),
27642786
OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"),
27652787
N_("reference repository")),
2788+
OPT_STRING(0, "ref-format", &ref_storage_format, N_("format"),
2789+
N_("specify the reference format to use")),
27662790
OPT_BOOL(0, "dissociate", &opt.dissociate,
27672791
N_("use --reference only while cloning")),
27682792
OPT_INTEGER(0, "depth", &opt.depth,
@@ -2806,6 +2830,12 @@ static int module_update(int argc, const char **argv, const char *prefix)
28062830
module_update_options);
28072831
}
28082832

2833+
if (ref_storage_format) {
2834+
opt.ref_storage_format = ref_storage_format_by_name(ref_storage_format);
2835+
if (opt.ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
2836+
die(_("unknown ref storage format '%s'"), ref_storage_format);
2837+
}
2838+
28092839
opt.filter_options = &filter_options;
28102840
opt.prefix = prefix;
28112841

@@ -3101,13 +3131,17 @@ struct add_data {
31013131
const char *sm_name;
31023132
const char *repo;
31033133
const char *realrepo;
3134+
enum ref_storage_format ref_storage_format;
31043135
int depth;
31053136
unsigned int force: 1;
31063137
unsigned int quiet: 1;
31073138
unsigned int progress: 1;
31083139
unsigned int dissociate: 1;
31093140
};
3110-
#define ADD_DATA_INIT { .depth = -1 }
3141+
#define ADD_DATA_INIT { \
3142+
.depth = -1, \
3143+
.ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN, \
3144+
}
31113145

31123146
static void append_fetch_remotes(struct strbuf *msg, const char *git_dir_path)
31133147
{
@@ -3201,6 +3235,7 @@ static int add_submodule(const struct add_data *add_data)
32013235

32023236
string_list_append(&reference, p)->util = p;
32033237
}
3238+
clone_data.ref_storage_format = add_data->ref_storage_format;
32043239
clone_data.dissociate = add_data->dissociate;
32053240
if (add_data->depth >= 0)
32063241
clone_data.depth = add_data->depth;
@@ -3366,6 +3401,7 @@ static int module_add(int argc, const char **argv, const char *prefix)
33663401
{
33673402
int force = 0, quiet = 0, progress = 0, dissociate = 0;
33683403
struct add_data add_data = ADD_DATA_INIT;
3404+
const char *ref_storage_format = NULL;
33693405
char *to_free = NULL;
33703406
struct option options[] = {
33713407
OPT_STRING('b', "branch", &add_data.branch, N_("branch"),
@@ -3376,6 +3412,8 @@ static int module_add(int argc, const char **argv, const char *prefix)
33763412
OPT_BOOL(0, "progress", &progress, N_("force cloning progress")),
33773413
OPT_STRING(0, "reference", &add_data.reference_path, N_("repository"),
33783414
N_("reference repository")),
3415+
OPT_STRING(0, "ref-format", &ref_storage_format, N_("format"),
3416+
N_("specify the reference format to use")),
33793417
OPT_BOOL(0, "dissociate", &dissociate, N_("borrow the objects from reference repositories")),
33803418
OPT_STRING(0, "name", &add_data.sm_name, N_("name"),
33813419
N_("sets the submodule's name to the given string "
@@ -3402,6 +3440,12 @@ static int module_add(int argc, const char **argv, const char *prefix)
34023440
if (argc == 0 || argc > 2)
34033441
usage_with_options(usage, options);
34043442

3443+
if (ref_storage_format) {
3444+
add_data.ref_storage_format = ref_storage_format_by_name(ref_storage_format);
3445+
if (add_data.ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
3446+
die(_("unknown ref storage format '%s'"), ref_storage_format);
3447+
}
3448+
34053449
add_data.repo = argv[0];
34063450
if (argc == 1)
34073451
add_data.sm_path = git_url_basename(add_data.repo, 0, 0);

0 commit comments

Comments
 (0)