Skip to content

Commit 3c548de

Browse files
committed
Merge branch 'sb/submodule-blanket-recursive'
Many commands learned to pay attention to submodule.recurse configuration. * sb/submodule-blanket-recursive: builtin/fetch.c: respect 'submodule.recurse' option builtin/push.c: respect 'submodule.recurse' option builtin/grep.c: respect 'submodule.recurse' option Introduce 'submodule.recurse' option for worktree manipulators submodule loading: separate code path for .gitmodules and config overlay reset/checkout/read-tree: unify config callback for submodule recursion submodule test invocation: only pass additional arguments submodule recursing: do not write a config variable twice
2 parents 93dd544 + 58f4203 commit 3c548de

16 files changed

+179
-98
lines changed

Documentation/config.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,6 +3091,11 @@ submodule.active::
30913091
submodule's path to determine if the submodule is of interest to git
30923092
commands.
30933093

3094+
submodule.recurse::
3095+
Specifies if commands recurse into submodules by default. This
3096+
applies to all commands that have a `--recurse-submodules` option.
3097+
Defaults to false.
3098+
30943099
submodule.fetchJobs::
30953100
Specifies how many submodules are fetched/cloned at the same time.
30963101
A positive integer allows up to that number of submodules fetched

builtin/checkout.c

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,12 @@
2121
#include "submodule-config.h"
2222
#include "submodule.h"
2323

24-
static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
25-
2624
static const char * const checkout_usage[] = {
2725
N_("git checkout [<options>] <branch>"),
2826
N_("git checkout [<options>] [<branch>] -- <file>..."),
2927
NULL,
3028
};
3129

32-
static int option_parse_recurse_submodules(const struct option *opt,
33-
const char *arg, int unset)
34-
{
35-
if (unset) {
36-
recurse_submodules = RECURSE_SUBMODULES_OFF;
37-
return 0;
38-
}
39-
if (arg)
40-
recurse_submodules =
41-
parse_update_recurse_submodules_arg(opt->long_name,
42-
arg);
43-
else
44-
recurse_submodules = RECURSE_SUBMODULES_ON;
45-
46-
return 0;
47-
}
48-
4930
struct checkout_opts {
5031
int patch_mode;
5132
int quiet;
@@ -876,7 +857,7 @@ static int git_checkout_config(const char *var, const char *value, void *cb)
876857
}
877858

878859
if (starts_with(var, "submodule."))
879-
return parse_submodule_config_option(var, value);
860+
return submodule_config(var, value, NULL);
880861

881862
return git_xmerge_config(var, value, NULL);
882863
}
@@ -1184,9 +1165,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
11841165
N_("second guess 'git checkout <no-such-branch>'")),
11851166
OPT_BOOL(0, "ignore-other-worktrees", &opts.ignore_other_worktrees,
11861167
N_("do not check if another worktree is holding the given ref")),
1187-
{ OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules,
1168+
{ OPTION_CALLBACK, 0, "recurse-submodules", NULL,
11881169
"checkout", "control recursive updating of submodules",
1189-
PARSE_OPT_OPTARG, option_parse_recurse_submodules },
1170+
PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater },
11901171
OPT_BOOL(0, "progress", &opts.show_progress, N_("force progress reporting")),
11911172
OPT_END(),
11921173
};
@@ -1217,12 +1198,6 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
12171198
git_xmerge_config("merge.conflictstyle", conflict_style, NULL);
12181199
}
12191200

1220-
if (recurse_submodules != RECURSE_SUBMODULES_OFF) {
1221-
git_config(submodule_config, NULL);
1222-
if (recurse_submodules != RECURSE_SUBMODULES_DEFAULT)
1223-
set_config_update_recurse_submodules(recurse_submodules);
1224-
}
1225-
12261201
if ((!!opts.new_branch + !!opts.new_branch_force + !!opts.new_orphan_branch) > 1)
12271202
die(_("-b, -B and --orphan are mutually exclusive"));
12281203

builtin/fetch.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
7373
fetch_prune_config = git_config_bool(k, v);
7474
return 0;
7575
}
76+
77+
if (!strcmp(k, "submodule.recurse")) {
78+
int r = git_config_bool(k, v) ?
79+
RECURSE_SUBMODULES_ON : RECURSE_SUBMODULES_OFF;
80+
recurse_submodules = r;
81+
}
82+
7683
return git_default_config(k, v, cb);
7784
}
7885

builtin/grep.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ static int grep_cmd_config(const char *var, const char *value, void *cb)
302302
#endif
303303
}
304304

305+
if (!strcmp(var, "submodule.recurse"))
306+
recurse_submodules = git_config_bool(var, value);
307+
305308
return st;
306309
}
307310

builtin/push.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ static int git_push_config(const char *k, const char *v, void *cb)
498498
const char *value;
499499
if (!git_config_get_value("push.recursesubmodules", &value))
500500
recurse_submodules = parse_push_recurse_submodules_arg(k, value);
501+
} else if (!strcmp(k, "submodule.recurse")) {
502+
int val = git_config_bool(k, v) ?
503+
RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF;
504+
recurse_submodules = val;
501505
}
502506

503507
return git_default_config(k, v, NULL);

builtin/read-tree.c

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
static int nr_trees;
2222
static int read_empty;
2323
static struct tree *trees[MAX_UNPACK_TREES];
24-
static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
2524

2625
static int list_tree(struct object_id *oid)
2726
{
@@ -99,21 +98,12 @@ static int debug_merge(const struct cache_entry * const *stages,
9998
return 0;
10099
}
101100

102-
static int option_parse_recurse_submodules(const struct option *opt,
103-
const char *arg, int unset)
101+
static int git_read_tree_config(const char *var, const char *value, void *cb)
104102
{
105-
if (unset) {
106-
recurse_submodules = RECURSE_SUBMODULES_OFF;
107-
return 0;
108-
}
109-
if (arg)
110-
recurse_submodules =
111-
parse_update_recurse_submodules_arg(opt->long_name,
112-
arg);
113-
else
114-
recurse_submodules = RECURSE_SUBMODULES_ON;
103+
if (!strcmp(var, "submodule.recurse"))
104+
return git_default_submodule_config(var, value, cb);
115105

116-
return 0;
106+
return git_default_config(var, value, cb);
117107
}
118108

119109
static struct lock_file lock_file;
@@ -157,9 +147,9 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
157147
N_("skip applying sparse checkout filter")),
158148
OPT_BOOL(0, "debug-unpack", &opts.debug_unpack,
159149
N_("debug unpack-trees")),
160-
{ OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules,
150+
{ OPTION_CALLBACK, 0, "recurse-submodules", NULL,
161151
"checkout", "control recursive updating of submodules",
162-
PARSE_OPT_OPTARG, option_parse_recurse_submodules },
152+
PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater },
163153
OPT_END()
164154
};
165155

@@ -168,18 +158,14 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
168158
opts.src_index = &the_index;
169159
opts.dst_index = &the_index;
170160

171-
git_config(git_default_config, NULL);
161+
git_config(git_read_tree_config, NULL);
172162

173163
argc = parse_options(argc, argv, unused_prefix, read_tree_options,
174164
read_tree_usage, 0);
175165

176-
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
166+
load_submodule_cache();
177167

178-
if (recurse_submodules != RECURSE_SUBMODULES_DEFAULT) {
179-
gitmodules_config();
180-
git_config(submodule_config, NULL);
181-
set_config_update_recurse_submodules(RECURSE_SUBMODULES_ON);
182-
}
168+
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
183169

184170
prefix_set = opts.prefix ? 1 : 0;
185171
if (1 < opts.merge + opts.reset + prefix_set)

builtin/reset.c

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,6 @@
2424
#include "submodule.h"
2525
#include "submodule-config.h"
2626

27-
static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
28-
29-
static int option_parse_recurse_submodules(const struct option *opt,
30-
const char *arg, int unset)
31-
{
32-
if (unset) {
33-
recurse_submodules = RECURSE_SUBMODULES_OFF;
34-
return 0;
35-
}
36-
if (arg)
37-
recurse_submodules =
38-
parse_update_recurse_submodules_arg(opt->long_name,
39-
arg);
40-
else
41-
recurse_submodules = RECURSE_SUBMODULES_ON;
42-
43-
return 0;
44-
}
45-
4627
static const char * const git_reset_usage[] = {
4728
N_("git reset [--mixed | --soft | --hard | --merge | --keep] [-q] [<commit>]"),
4829
N_("git reset [-q] [<tree-ish>] [--] <paths>..."),
@@ -284,6 +265,14 @@ static int reset_refs(const char *rev, const struct object_id *oid)
284265
return update_ref_status;
285266
}
286267

268+
static int git_reset_config(const char *var, const char *value, void *cb)
269+
{
270+
if (!strcmp(var, "submodule.recurse"))
271+
return git_default_submodule_config(var, value, cb);
272+
273+
return git_default_config(var, value, cb);
274+
}
275+
287276
int cmd_reset(int argc, const char **argv, const char *prefix)
288277
{
289278
int reset_type = NONE, update_ref_status = 0, quiet = 0;
@@ -303,26 +292,22 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
303292
N_("reset HEAD, index and working tree"), MERGE),
304293
OPT_SET_INT(0, "keep", &reset_type,
305294
N_("reset HEAD but keep local changes"), KEEP),
306-
{ OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules,
295+
{ OPTION_CALLBACK, 0, "recurse-submodules", NULL,
307296
"reset", "control recursive updating of submodules",
308-
PARSE_OPT_OPTARG, option_parse_recurse_submodules },
297+
PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater },
309298
OPT_BOOL('p', "patch", &patch_mode, N_("select hunks interactively")),
310299
OPT_BOOL('N', "intent-to-add", &intent_to_add,
311300
N_("record only the fact that removed paths will be added later")),
312301
OPT_END()
313302
};
314303

315-
git_config(git_default_config, NULL);
304+
git_config(git_reset_config, NULL);
316305

317306
argc = parse_options(argc, argv, prefix, options, git_reset_usage,
318307
PARSE_OPT_KEEP_DASHDASH);
319308
parse_args(&pathspec, argv, prefix, patch_mode, &rev);
320309

321-
if (recurse_submodules != RECURSE_SUBMODULES_DEFAULT) {
322-
gitmodules_config();
323-
git_config(submodule_config, NULL);
324-
set_config_update_recurse_submodules(RECURSE_SUBMODULES_ON);
325-
}
310+
load_submodule_cache();
326311

327312
unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", oid.hash);
328313
if (unborn) {

submodule.c

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
#include "quote.h"
1717
#include "remote.h"
1818
#include "worktree.h"
19+
#include "parse-options.h"
1920

2021
static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
21-
static int config_update_recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
22+
static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF;
2223
static int parallel_jobs = 1;
2324
static struct string_list changed_submodule_paths = STRING_LIST_INIT_DUP;
2425
static int initialized_fetch_ref_tips;
@@ -153,7 +154,8 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
153154
}
154155
}
155156

156-
int submodule_config(const char *var, const char *value, void *cb)
157+
/* For loading from the .gitmodules file. */
158+
static int git_modules_config(const char *var, const char *value, void *cb)
157159
{
158160
if (!strcmp(var, "submodule.fetchjobs")) {
159161
parallel_jobs = git_config_int(var, value);
@@ -169,6 +171,56 @@ int submodule_config(const char *var, const char *value, void *cb)
169171
return 0;
170172
}
171173

174+
/* Loads all submodule settings from the config. */
175+
int submodule_config(const char *var, const char *value, void *cb)
176+
{
177+
if (!strcmp(var, "submodule.recurse")) {
178+
int v = git_config_bool(var, value) ?
179+
RECURSE_SUBMODULES_ON : RECURSE_SUBMODULES_OFF;
180+
config_update_recurse_submodules = v;
181+
return 0;
182+
} else {
183+
return git_modules_config(var, value, cb);
184+
}
185+
}
186+
187+
/* Cheap function that only determines if we're interested in submodules at all */
188+
int git_default_submodule_config(const char *var, const char *value, void *cb)
189+
{
190+
if (!strcmp(var, "submodule.recurse")) {
191+
int v = git_config_bool(var, value) ?
192+
RECURSE_SUBMODULES_ON : RECURSE_SUBMODULES_OFF;
193+
config_update_recurse_submodules = v;
194+
}
195+
return 0;
196+
}
197+
198+
int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
199+
const char *arg, int unset)
200+
{
201+
if (unset) {
202+
config_update_recurse_submodules = RECURSE_SUBMODULES_OFF;
203+
return 0;
204+
}
205+
if (arg)
206+
config_update_recurse_submodules =
207+
parse_update_recurse_submodules_arg(opt->long_name,
208+
arg);
209+
else
210+
config_update_recurse_submodules = RECURSE_SUBMODULES_ON;
211+
212+
return 0;
213+
}
214+
215+
void load_submodule_cache(void)
216+
{
217+
if (config_update_recurse_submodules == RECURSE_SUBMODULES_OFF)
218+
return;
219+
220+
gitmodules_config();
221+
git_config(submodule_config, NULL);
222+
}
223+
172224
void gitmodules_config(void)
173225
{
174226
const char *work_tree = get_git_work_tree();
@@ -196,7 +248,8 @@ void gitmodules_config(void)
196248
}
197249

198250
if (!gitmodules_is_unmerged)
199-
git_config_from_file(submodule_config, gitmodules_path.buf, NULL);
251+
git_config_from_file(git_modules_config,
252+
gitmodules_path.buf, NULL);
200253
strbuf_release(&gitmodules_path);
201254
}
202255
}
@@ -207,7 +260,7 @@ void gitmodules_config_sha1(const unsigned char *commit_sha1)
207260
unsigned char sha1[20];
208261

209262
if (gitmodule_sha1_from_commit(commit_sha1, sha1, &rev)) {
210-
git_config_from_blob_sha1(submodule_config, rev.buf,
263+
git_config_from_blob_sha1(git_modules_config, rev.buf,
211264
sha1, NULL);
212265
}
213266
strbuf_release(&rev);
@@ -660,11 +713,6 @@ void set_config_fetch_recurse_submodules(int value)
660713
config_fetch_recurse_submodules = value;
661714
}
662715

663-
void set_config_update_recurse_submodules(int value)
664-
{
665-
config_update_recurse_submodules = value;
666-
}
667-
668716
int should_update_submodules(void)
669717
{
670718
return config_update_recurse_submodules == RECURSE_SUBMODULES_ON;

submodule.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ extern void stage_updated_gitmodules(void);
3939
extern void set_diffopt_flags_from_submodule_config(struct diff_options *,
4040
const char *path);
4141
extern int submodule_config(const char *var, const char *value, void *cb);
42+
extern int git_default_submodule_config(const char *var, const char *value, void *cb);
43+
44+
struct option;
45+
int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
46+
const char *arg, int unset);
47+
void load_submodule_cache(void);
4248
extern void gitmodules_config(void);
4349
extern void gitmodules_config_sha1(const unsigned char *commit_sha1);
4450
extern int is_submodule_initialized(const char *path);
@@ -69,7 +75,6 @@ extern void show_submodule_inline_diff(FILE *f, const char *path,
6975
const char *del, const char *add, const char *reset,
7076
const struct diff_options *opt);
7177
extern void set_config_fetch_recurse_submodules(int value);
72-
extern void set_config_update_recurse_submodules(int value);
7378
/* Check if we want to update any submodule.*/
7479
extern int should_update_submodules(void);
7580
/*

0 commit comments

Comments
 (0)