4 #include "repository.h"
6 #include "submodule-config.h"
9 #include "object-store.h"
10 #include "parse-options.h"
11 #include "tree-walk.h"
14 * submodule cache lookup structure
15 * There is one shared set of 'struct submodule' entries which can be
16 * looked up by their sha1 blob id of the .gitmodules file and either
17 * using path or name as key.
18 * for_path stores submodule entries with path as key
19 * for_name stores submodule entries with name as key
21 struct submodule_cache
{
22 struct hashmap for_path
;
23 struct hashmap for_name
;
24 unsigned initialized
:1;
25 unsigned gitmodules_read
:1;
29 * thin wrapper struct needed to insert 'struct submodule' entries to
32 struct submodule_entry
{
33 struct hashmap_entry ent
;
34 struct submodule
*config
;
42 static int config_path_cmp(const void *cmp_data UNUSED
,
43 const struct hashmap_entry
*eptr
,
44 const struct hashmap_entry
*entry_or_key
,
45 const void *keydata UNUSED
)
47 const struct submodule_entry
*a
, *b
;
49 a
= container_of(eptr
, const struct submodule_entry
, ent
);
50 b
= container_of(entry_or_key
, const struct submodule_entry
, ent
);
52 return strcmp(a
->config
->path
, b
->config
->path
) ||
53 !oideq(&a
->config
->gitmodules_oid
, &b
->config
->gitmodules_oid
);
56 static int config_name_cmp(const void *cmp_data UNUSED
,
57 const struct hashmap_entry
*eptr
,
58 const struct hashmap_entry
*entry_or_key
,
59 const void *keydata UNUSED
)
61 const struct submodule_entry
*a
, *b
;
63 a
= container_of(eptr
, const struct submodule_entry
, ent
);
64 b
= container_of(entry_or_key
, const struct submodule_entry
, ent
);
66 return strcmp(a
->config
->name
, b
->config
->name
) ||
67 !oideq(&a
->config
->gitmodules_oid
, &b
->config
->gitmodules_oid
);
70 static struct submodule_cache
*submodule_cache_alloc(void)
72 return xcalloc(1, sizeof(struct submodule_cache
));
75 static void submodule_cache_init(struct submodule_cache
*cache
)
77 hashmap_init(&cache
->for_path
, config_path_cmp
, NULL
, 0);
78 hashmap_init(&cache
->for_name
, config_name_cmp
, NULL
, 0);
79 cache
->initialized
= 1;
82 static void free_one_config(struct submodule_entry
*entry
)
84 free((void *) entry
->config
->path
);
85 free((void *) entry
->config
->name
);
86 free((void *) entry
->config
->branch
);
87 free((void *) entry
->config
->update_strategy
.command
);
91 static void submodule_cache_clear(struct submodule_cache
*cache
)
93 struct hashmap_iter iter
;
94 struct submodule_entry
*entry
;
96 if (!cache
->initialized
)
100 * We iterate over the name hash here to be symmetric with the
101 * allocation of struct submodule entries. Each is allocated by
102 * their .gitmodules blob sha1 and submodule name.
104 hashmap_for_each_entry(&cache
->for_name
, &iter
, entry
,
105 ent
/* member name */)
106 free_one_config(entry
);
108 hashmap_clear_and_free(&cache
->for_path
, struct submodule_entry
, ent
);
109 hashmap_clear_and_free(&cache
->for_name
, struct submodule_entry
, ent
);
110 cache
->initialized
= 0;
111 cache
->gitmodules_read
= 0;
114 void submodule_cache_free(struct submodule_cache
*cache
)
116 submodule_cache_clear(cache
);
120 static unsigned int hash_oid_string(const struct object_id
*oid
,
123 return memhash(oid
->hash
, the_hash_algo
->rawsz
) + strhash(string
);
126 static void cache_put_path(struct submodule_cache
*cache
,
127 struct submodule
*submodule
)
129 unsigned int hash
= hash_oid_string(&submodule
->gitmodules_oid
,
131 struct submodule_entry
*e
= xmalloc(sizeof(*e
));
132 hashmap_entry_init(&e
->ent
, hash
);
133 e
->config
= submodule
;
134 hashmap_put(&cache
->for_path
, &e
->ent
);
137 static void cache_remove_path(struct submodule_cache
*cache
,
138 struct submodule
*submodule
)
140 unsigned int hash
= hash_oid_string(&submodule
->gitmodules_oid
,
142 struct submodule_entry e
;
143 struct submodule_entry
*removed
;
144 hashmap_entry_init(&e
.ent
, hash
);
145 e
.config
= submodule
;
146 removed
= hashmap_remove_entry(&cache
->for_path
, &e
, ent
, NULL
);
150 static void cache_add(struct submodule_cache
*cache
,
151 struct submodule
*submodule
)
153 unsigned int hash
= hash_oid_string(&submodule
->gitmodules_oid
,
155 struct submodule_entry
*e
= xmalloc(sizeof(*e
));
156 hashmap_entry_init(&e
->ent
, hash
);
157 e
->config
= submodule
;
158 hashmap_add(&cache
->for_name
, &e
->ent
);
161 static const struct submodule
*cache_lookup_path(struct submodule_cache
*cache
,
162 const struct object_id
*gitmodules_oid
, const char *path
)
164 struct submodule_entry
*entry
;
165 unsigned int hash
= hash_oid_string(gitmodules_oid
, path
);
166 struct submodule_entry key
;
167 struct submodule key_config
;
169 oidcpy(&key_config
.gitmodules_oid
, gitmodules_oid
);
170 key_config
.path
= path
;
172 hashmap_entry_init(&key
.ent
, hash
);
173 key
.config
= &key_config
;
175 entry
= hashmap_get_entry(&cache
->for_path
, &key
, ent
, NULL
);
177 return entry
->config
;
181 static struct submodule
*cache_lookup_name(struct submodule_cache
*cache
,
182 const struct object_id
*gitmodules_oid
, const char *name
)
184 struct submodule_entry
*entry
;
185 unsigned int hash
= hash_oid_string(gitmodules_oid
, name
);
186 struct submodule_entry key
;
187 struct submodule key_config
;
189 oidcpy(&key_config
.gitmodules_oid
, gitmodules_oid
);
190 key_config
.name
= name
;
192 hashmap_entry_init(&key
.ent
, hash
);
193 key
.config
= &key_config
;
195 entry
= hashmap_get_entry(&cache
->for_name
, &key
, ent
, NULL
);
197 return entry
->config
;
201 int check_submodule_name(const char *name
)
203 /* Disallow empty names */
208 * Look for '..' as a path component. Check is_xplatform_dir_sep() as
209 * separators rather than is_dir_sep(), because we want the name rules
210 * to be consistent across platforms.
212 goto in_component
; /* always start inside component */
215 if (is_xplatform_dir_sep(c
)) {
217 if (name
[0] == '.' && name
[1] == '.' &&
218 (!name
[2] || is_xplatform_dir_sep(name
[2])))
226 static int name_and_item_from_var(const char *var
, struct strbuf
*name
,
229 const char *subsection
, *key
;
230 size_t subsection_len
;
232 parse
= parse_config_key(var
, "submodule", &subsection
,
233 &subsection_len
, &key
);
234 if (parse
< 0 || !subsection
)
237 strbuf_add(name
, subsection
, subsection_len
);
238 if (check_submodule_name(name
->buf
) < 0) {
239 warning(_("ignoring suspicious submodule name: %s"), name
->buf
);
240 strbuf_release(name
);
244 strbuf_addstr(item
, key
);
249 static struct submodule
*lookup_or_create_by_name(struct submodule_cache
*cache
,
250 const struct object_id
*gitmodules_oid
, const char *name
)
252 struct submodule
*submodule
;
253 struct strbuf name_buf
= STRBUF_INIT
;
255 submodule
= cache_lookup_name(cache
, gitmodules_oid
, name
);
259 submodule
= xmalloc(sizeof(*submodule
));
261 strbuf_addstr(&name_buf
, name
);
262 submodule
->name
= strbuf_detach(&name_buf
, NULL
);
264 submodule
->path
= NULL
;
265 submodule
->url
= NULL
;
266 submodule
->update_strategy
.type
= SM_UPDATE_UNSPECIFIED
;
267 submodule
->update_strategy
.command
= NULL
;
268 submodule
->fetch_recurse
= RECURSE_SUBMODULES_NONE
;
269 submodule
->ignore
= NULL
;
270 submodule
->branch
= NULL
;
271 submodule
->recommend_shallow
= -1;
273 oidcpy(&submodule
->gitmodules_oid
, gitmodules_oid
);
275 cache_add(cache
, submodule
);
280 static int parse_fetch_recurse(const char *opt
, const char *arg
,
283 switch (git_parse_maybe_bool(arg
)) {
285 return RECURSE_SUBMODULES_ON
;
287 return RECURSE_SUBMODULES_OFF
;
289 if (!strcmp(arg
, "on-demand"))
290 return RECURSE_SUBMODULES_ON_DEMAND
;
292 * Please update $__git_fetch_recurse_submodules in
293 * git-completion.bash when you add new options.
296 die("bad %s argument: %s", opt
, arg
);
298 return RECURSE_SUBMODULES_ERROR
;
302 int parse_submodule_fetchjobs(const char *var
, const char *value
)
304 int fetchjobs
= git_config_int(var
, value
);
306 die(_("negative values not allowed for submodule.fetchJobs"));
308 fetchjobs
= online_cpus();
312 int parse_fetch_recurse_submodules_arg(const char *opt
, const char *arg
)
314 return parse_fetch_recurse(opt
, arg
, 1);
317 int option_fetch_parse_recurse_submodules(const struct option
*opt
,
318 const char *arg
, int unset
)
328 *v
= RECURSE_SUBMODULES_OFF
;
331 *v
= parse_fetch_recurse_submodules_arg(opt
->long_name
, arg
);
333 *v
= RECURSE_SUBMODULES_ON
;
338 static int parse_update_recurse(const char *opt
, const char *arg
,
341 switch (git_parse_maybe_bool(arg
)) {
343 return RECURSE_SUBMODULES_ON
;
345 return RECURSE_SUBMODULES_OFF
;
348 die("bad %s argument: %s", opt
, arg
);
349 return RECURSE_SUBMODULES_ERROR
;
353 int parse_update_recurse_submodules_arg(const char *opt
, const char *arg
)
355 return parse_update_recurse(opt
, arg
, 1);
358 static int parse_push_recurse(const char *opt
, const char *arg
,
361 switch (git_parse_maybe_bool(arg
)) {
363 /* There's no simple "on" value when pushing */
365 die("bad %s argument: %s", opt
, arg
);
367 return RECURSE_SUBMODULES_ERROR
;
369 return RECURSE_SUBMODULES_OFF
;
371 if (!strcmp(arg
, "on-demand"))
372 return RECURSE_SUBMODULES_ON_DEMAND
;
373 else if (!strcmp(arg
, "check"))
374 return RECURSE_SUBMODULES_CHECK
;
375 else if (!strcmp(arg
, "only"))
376 return RECURSE_SUBMODULES_ONLY
;
378 * Please update $__git_push_recurse_submodules in
379 * git-completion.bash when you add new modes.
381 else if (die_on_error
)
382 die("bad %s argument: %s", opt
, arg
);
384 return RECURSE_SUBMODULES_ERROR
;
388 int parse_push_recurse_submodules_arg(const char *opt
, const char *arg
)
390 return parse_push_recurse(opt
, arg
, 1);
393 static void warn_multiple_config(const struct object_id
*treeish_name
,
394 const char *name
, const char *option
)
396 const char *commit_string
= "WORKTREE";
398 commit_string
= oid_to_hex(treeish_name
);
399 warning("%s:.gitmodules, multiple configurations found for "
400 "'submodule.%s.%s'. Skipping second one!",
401 commit_string
, name
, option
);
404 static void warn_command_line_option(const char *var
, const char *value
)
406 warning(_("ignoring '%s' which may be interpreted as"
407 " a command-line option: %s"), var
, value
);
410 struct parse_config_parameter
{
411 struct submodule_cache
*cache
;
412 const struct object_id
*treeish_name
;
413 const struct object_id
*gitmodules_oid
;
418 * Parse a config item from .gitmodules.
420 * This does not handle submodule-related configuration from the main
421 * config store (.git/config, etc). Callers are responsible for
422 * checking for overrides in the main config store when appropriate.
424 static int parse_config(const char *var
, const char *value
, void *data
)
426 struct parse_config_parameter
*me
= data
;
427 struct submodule
*submodule
;
428 struct strbuf name
= STRBUF_INIT
, item
= STRBUF_INIT
;
431 /* this also ensures that we only parse submodule entries */
432 if (!name_and_item_from_var(var
, &name
, &item
))
435 submodule
= lookup_or_create_by_name(me
->cache
,
439 if (!strcmp(item
.buf
, "path")) {
441 ret
= config_error_nonbool(var
);
442 else if (looks_like_command_line_option(value
))
443 warn_command_line_option(var
, value
);
444 else if (!me
->overwrite
&& submodule
->path
)
445 warn_multiple_config(me
->treeish_name
, submodule
->name
,
449 cache_remove_path(me
->cache
, submodule
);
450 free((void *) submodule
->path
);
451 submodule
->path
= xstrdup(value
);
452 cache_put_path(me
->cache
, submodule
);
454 } else if (!strcmp(item
.buf
, "fetchrecursesubmodules")) {
455 /* when parsing worktree configurations we can die early */
456 int die_on_error
= is_null_oid(me
->gitmodules_oid
);
457 if (!me
->overwrite
&&
458 submodule
->fetch_recurse
!= RECURSE_SUBMODULES_NONE
)
459 warn_multiple_config(me
->treeish_name
, submodule
->name
,
460 "fetchrecursesubmodules");
462 submodule
->fetch_recurse
= parse_fetch_recurse(
465 } else if (!strcmp(item
.buf
, "ignore")) {
467 ret
= config_error_nonbool(var
);
468 else if (!me
->overwrite
&& submodule
->ignore
)
469 warn_multiple_config(me
->treeish_name
, submodule
->name
,
471 else if (strcmp(value
, "untracked") &&
472 strcmp(value
, "dirty") &&
473 strcmp(value
, "all") &&
474 strcmp(value
, "none"))
475 warning("Invalid parameter '%s' for config option "
476 "'submodule.%s.ignore'", value
, name
.buf
);
478 free((void *) submodule
->ignore
);
479 submodule
->ignore
= xstrdup(value
);
481 } else if (!strcmp(item
.buf
, "url")) {
483 ret
= config_error_nonbool(var
);
484 } else if (looks_like_command_line_option(value
)) {
485 warn_command_line_option(var
, value
);
486 } else if (!me
->overwrite
&& submodule
->url
) {
487 warn_multiple_config(me
->treeish_name
, submodule
->name
,
490 free((void *) submodule
->url
);
491 submodule
->url
= xstrdup(value
);
493 } else if (!strcmp(item
.buf
, "update")) {
495 ret
= config_error_nonbool(var
);
496 else if (!me
->overwrite
&&
497 submodule
->update_strategy
.type
!= SM_UPDATE_UNSPECIFIED
)
498 warn_multiple_config(me
->treeish_name
, submodule
->name
,
500 else if (parse_submodule_update_strategy(value
,
501 &submodule
->update_strategy
) < 0 ||
502 submodule
->update_strategy
.type
== SM_UPDATE_COMMAND
)
503 die(_("invalid value for '%s'"), var
);
504 } else if (!strcmp(item
.buf
, "shallow")) {
505 if (!me
->overwrite
&& submodule
->recommend_shallow
!= -1)
506 warn_multiple_config(me
->treeish_name
, submodule
->name
,
509 submodule
->recommend_shallow
=
510 git_config_bool(var
, value
);
511 } else if (!strcmp(item
.buf
, "branch")) {
512 if (!me
->overwrite
&& submodule
->branch
)
513 warn_multiple_config(me
->treeish_name
, submodule
->name
,
516 free((void *)submodule
->branch
);
517 submodule
->branch
= xstrdup(value
);
521 strbuf_release(&name
);
522 strbuf_release(&item
);
527 static int gitmodule_oid_from_commit(const struct object_id
*treeish_name
,
528 struct object_id
*gitmodules_oid
,
533 if (is_null_oid(treeish_name
)) {
534 oidclr(gitmodules_oid
);
538 strbuf_addf(rev
, "%s:.gitmodules", oid_to_hex(treeish_name
));
539 if (get_oid(rev
->buf
, gitmodules_oid
) >= 0)
545 /* This does a lookup of a submodule configuration by name or by path
546 * (key) with on-demand reading of the appropriate .gitmodules from
549 static const struct submodule
*config_from(struct submodule_cache
*cache
,
550 const struct object_id
*treeish_name
, const char *key
,
551 enum lookup_type lookup_type
)
553 struct strbuf rev
= STRBUF_INIT
;
554 unsigned long config_size
;
556 struct object_id oid
;
557 enum object_type type
;
558 const struct submodule
*submodule
= NULL
;
559 struct parse_config_parameter parameter
;
562 * If any parameter except the cache is a NULL pointer just
563 * return the first submodule. Can be used to check whether
564 * there are any submodules parsed.
566 if (!treeish_name
|| !key
) {
567 struct hashmap_iter iter
;
568 struct submodule_entry
*entry
;
570 entry
= hashmap_iter_first_entry(&cache
->for_name
, &iter
,
571 struct submodule_entry
,
572 ent
/* member name */);
575 return entry
->config
;
578 if (!gitmodule_oid_from_commit(treeish_name
, &oid
, &rev
))
581 switch (lookup_type
) {
583 submodule
= cache_lookup_name(cache
, &oid
, key
);
586 submodule
= cache_lookup_path(cache
, &oid
, key
);
592 config
= read_object_file(&oid
, &type
, &config_size
);
593 if (!config
|| type
!= OBJ_BLOB
)
596 /* fill the submodule config into the cache */
597 parameter
.cache
= cache
;
598 parameter
.treeish_name
= treeish_name
;
599 parameter
.gitmodules_oid
= &oid
;
600 parameter
.overwrite
= 0;
601 git_config_from_mem(parse_config
, CONFIG_ORIGIN_SUBMODULE_BLOB
, rev
.buf
,
602 config
, config_size
, ¶meter
, NULL
);
603 strbuf_release(&rev
);
606 switch (lookup_type
) {
608 return cache_lookup_name(cache
, &oid
, key
);
610 return cache_lookup_path(cache
, &oid
, key
);
616 strbuf_release(&rev
);
621 static void submodule_cache_check_init(struct repository
*repo
)
623 if (repo
->submodule_cache
&& repo
->submodule_cache
->initialized
)
626 if (!repo
->submodule_cache
)
627 repo
->submodule_cache
= submodule_cache_alloc();
629 submodule_cache_init(repo
->submodule_cache
);
633 * Note: This function is private for a reason, the '.gitmodules' file should
634 * not be used as a mechanism to retrieve arbitrary configuration stored in
637 * Runs the provided config function on the '.gitmodules' file found in the
640 static void config_from_gitmodules(config_fn_t fn
, struct repository
*repo
, void *data
)
642 if (repo
->worktree
) {
643 struct git_config_source config_source
= {
644 0, .scope
= CONFIG_SCOPE_SUBMODULE
646 const struct config_options opts
= { 0 };
647 struct object_id oid
;
651 file
= repo_worktree_path(repo
, GITMODULES_FILE
);
652 if (file_exists(file
)) {
653 config_source
.file
= file
;
654 } else if (repo_get_oid(repo
, GITMODULES_INDEX
, &oid
) >= 0 ||
655 repo_get_oid(repo
, GITMODULES_HEAD
, &oid
) >= 0) {
656 config_source
.repo
= repo
;
657 config_source
.blob
= oidstr
= xstrdup(oid_to_hex(&oid
));
658 if (repo
!= the_repository
)
659 add_submodule_odb_by_path(repo
->objects
->odb
->path
);
664 config_with_options(fn
, data
, &config_source
, &opts
);
672 static int gitmodules_cb(const char *var
, const char *value
, void *data
)
674 struct repository
*repo
= data
;
675 struct parse_config_parameter parameter
;
677 parameter
.cache
= repo
->submodule_cache
;
678 parameter
.treeish_name
= NULL
;
679 parameter
.gitmodules_oid
= null_oid();
680 parameter
.overwrite
= 1;
682 return parse_config(var
, value
, ¶meter
);
685 void repo_read_gitmodules(struct repository
*repo
, int skip_if_read
)
687 submodule_cache_check_init(repo
);
689 if (repo
->submodule_cache
->gitmodules_read
&& skip_if_read
)
692 if (repo_read_index(repo
) < 0)
695 if (!is_gitmodules_unmerged(repo
->index
))
696 config_from_gitmodules(gitmodules_cb
, repo
, repo
);
698 repo
->submodule_cache
->gitmodules_read
= 1;
701 void gitmodules_config_oid(const struct object_id
*commit_oid
)
703 struct strbuf rev
= STRBUF_INIT
;
704 struct object_id oid
;
706 submodule_cache_check_init(the_repository
);
708 if (gitmodule_oid_from_commit(commit_oid
, &oid
, &rev
)) {
709 git_config_from_blob_oid(gitmodules_cb
, rev
.buf
,
710 the_repository
, &oid
, the_repository
);
712 strbuf_release(&rev
);
714 the_repository
->submodule_cache
->gitmodules_read
= 1;
717 const struct submodule
*submodule_from_name(struct repository
*r
,
718 const struct object_id
*treeish_name
,
721 repo_read_gitmodules(r
, 1);
722 return config_from(r
->submodule_cache
, treeish_name
, name
, lookup_name
);
725 const struct submodule
*submodule_from_path(struct repository
*r
,
726 const struct object_id
*treeish_name
,
729 repo_read_gitmodules(r
, 1);
730 return config_from(r
->submodule_cache
, treeish_name
, path
, lookup_path
);
734 * Used internally by submodules_of_tree(). Recurses into 'treeish_name'
735 * and appends submodule entries to 'out'. The submodule_cache expects
736 * a root-level treeish_name and paths, so keep track of these values
737 * with 'root_tree' and 'prefix'.
739 static void traverse_tree_submodules(struct repository
*r
,
740 const struct object_id
*root_tree
,
742 const struct object_id
*treeish_name
,
743 struct submodule_entry_list
*out
)
745 struct tree_desc tree
;
746 struct submodule_tree_entry
*st_entry
;
747 struct name_entry
*name_entry
;
748 char *tree_path
= NULL
;
750 name_entry
= xmalloc(sizeof(*name_entry
));
752 fill_tree_descriptor(r
, &tree
, treeish_name
);
753 while (tree_entry(&tree
, name_entry
)) {
756 mkpathdup("%s/%s", prefix
, name_entry
->path
);
758 tree_path
= xstrdup(name_entry
->path
);
760 if (S_ISGITLINK(name_entry
->mode
) &&
761 is_tree_submodule_active(r
, root_tree
, tree_path
)) {
762 ALLOC_GROW(out
->entries
, out
->entry_nr
+ 1,
764 st_entry
= &out
->entries
[out
->entry_nr
++];
766 st_entry
->name_entry
= xmalloc(sizeof(*st_entry
->name_entry
));
767 *st_entry
->name_entry
= *name_entry
;
768 st_entry
->submodule
=
769 submodule_from_path(r
, root_tree
, tree_path
);
770 st_entry
->repo
= xmalloc(sizeof(*st_entry
->repo
));
771 if (repo_submodule_init(st_entry
->repo
, r
, tree_path
,
773 FREE_AND_NULL(st_entry
->repo
);
775 } else if (S_ISDIR(name_entry
->mode
))
776 traverse_tree_submodules(r
, root_tree
, tree_path
,
777 &name_entry
->oid
, out
);
782 void submodules_of_tree(struct repository
*r
,
783 const struct object_id
*treeish_name
,
784 struct submodule_entry_list
*out
)
786 CALLOC_ARRAY(out
->entries
, 0);
788 out
->entry_alloc
= 0;
790 traverse_tree_submodules(r
, treeish_name
, NULL
, treeish_name
, out
);
793 void submodule_free(struct repository
*r
)
795 if (r
->submodule_cache
)
796 submodule_cache_clear(r
->submodule_cache
);
799 static int config_print_callback(const char *var
, const char *value
, void *cb_data
)
801 char *wanted_key
= cb_data
;
803 if (!strcmp(wanted_key
, var
))
804 printf("%s\n", value
);
809 int print_config_from_gitmodules(struct repository
*repo
, const char *key
)
814 ret
= git_config_parse_key(key
, &store_key
, NULL
);
816 return CONFIG_INVALID_KEY
;
818 config_from_gitmodules(config_print_callback
, repo
, store_key
);
824 int config_set_in_gitmodules_file_gently(const char *key
, const char *value
)
828 ret
= git_config_set_in_file_gently(GITMODULES_FILE
, key
, value
);
830 /* Maybe the user already did that, don't error out here */
831 warning(_("Could not update .gitmodules entry %s"), key
);
836 struct fetch_config
{
838 int *recurse_submodules
;
841 static int gitmodules_fetch_config(const char *var
, const char *value
, void *cb
)
843 struct fetch_config
*config
= cb
;
844 if (!strcmp(var
, "submodule.fetchjobs")) {
845 if (config
->max_children
)
846 *(config
->max_children
) =
847 parse_submodule_fetchjobs(var
, value
);
849 } else if (!strcmp(var
, "fetch.recursesubmodules")) {
850 if (config
->recurse_submodules
)
851 *(config
->recurse_submodules
) =
852 parse_fetch_recurse_submodules_arg(var
, value
);
859 void fetch_config_from_gitmodules(int *max_children
, int *recurse_submodules
)
861 struct fetch_config config
= {
862 .max_children
= max_children
,
863 .recurse_submodules
= recurse_submodules
865 config_from_gitmodules(gitmodules_fetch_config
, the_repository
, &config
);
868 static int gitmodules_update_clone_config(const char *var
, const char *value
,
872 if (!strcmp(var
, "submodule.fetchjobs"))
873 *max_jobs
= parse_submodule_fetchjobs(var
, value
);
877 void update_clone_config_from_gitmodules(int *max_jobs
)
879 config_from_gitmodules(gitmodules_update_clone_config
, the_repository
, &max_jobs
);