5 #include "repository.h"
7 #include "submodule-config.h"
10 #include "object-store.h"
11 #include "parse-options.h"
12 #include "tree-walk.h"
15 * submodule cache lookup structure
16 * There is one shared set of 'struct submodule' entries which can be
17 * looked up by their sha1 blob id of the .gitmodules file and either
18 * using path or name as key.
19 * for_path stores submodule entries with path as key
20 * for_name stores submodule entries with name as key
22 struct submodule_cache
{
23 struct hashmap for_path
;
24 struct hashmap for_name
;
25 unsigned initialized
:1;
26 unsigned gitmodules_read
:1;
30 * thin wrapper struct needed to insert 'struct submodule' entries to
33 struct submodule_entry
{
34 struct hashmap_entry ent
;
35 struct submodule
*config
;
43 static int config_path_cmp(const void *cmp_data UNUSED
,
44 const struct hashmap_entry
*eptr
,
45 const struct hashmap_entry
*entry_or_key
,
46 const void *keydata UNUSED
)
48 const struct submodule_entry
*a
, *b
;
50 a
= container_of(eptr
, const struct submodule_entry
, ent
);
51 b
= container_of(entry_or_key
, const struct submodule_entry
, ent
);
53 return strcmp(a
->config
->path
, b
->config
->path
) ||
54 !oideq(&a
->config
->gitmodules_oid
, &b
->config
->gitmodules_oid
);
57 static int config_name_cmp(const void *cmp_data UNUSED
,
58 const struct hashmap_entry
*eptr
,
59 const struct hashmap_entry
*entry_or_key
,
60 const void *keydata UNUSED
)
62 const struct submodule_entry
*a
, *b
;
64 a
= container_of(eptr
, const struct submodule_entry
, ent
);
65 b
= container_of(entry_or_key
, const struct submodule_entry
, ent
);
67 return strcmp(a
->config
->name
, b
->config
->name
) ||
68 !oideq(&a
->config
->gitmodules_oid
, &b
->config
->gitmodules_oid
);
71 static struct submodule_cache
*submodule_cache_alloc(void)
73 return xcalloc(1, sizeof(struct submodule_cache
));
76 static void submodule_cache_init(struct submodule_cache
*cache
)
78 hashmap_init(&cache
->for_path
, config_path_cmp
, NULL
, 0);
79 hashmap_init(&cache
->for_name
, config_name_cmp
, NULL
, 0);
80 cache
->initialized
= 1;
83 static void free_one_config(struct submodule_entry
*entry
)
85 free((void *) entry
->config
->path
);
86 free((void *) entry
->config
->name
);
87 free((void *) entry
->config
->branch
);
88 free((void *) entry
->config
->update_strategy
.command
);
92 static void submodule_cache_clear(struct submodule_cache
*cache
)
94 struct hashmap_iter iter
;
95 struct submodule_entry
*entry
;
97 if (!cache
->initialized
)
101 * We iterate over the name hash here to be symmetric with the
102 * allocation of struct submodule entries. Each is allocated by
103 * their .gitmodules blob sha1 and submodule name.
105 hashmap_for_each_entry(&cache
->for_name
, &iter
, entry
,
106 ent
/* member name */)
107 free_one_config(entry
);
109 hashmap_clear_and_free(&cache
->for_path
, struct submodule_entry
, ent
);
110 hashmap_clear_and_free(&cache
->for_name
, struct submodule_entry
, ent
);
111 cache
->initialized
= 0;
112 cache
->gitmodules_read
= 0;
115 void submodule_cache_free(struct submodule_cache
*cache
)
117 submodule_cache_clear(cache
);
121 static unsigned int hash_oid_string(const struct object_id
*oid
,
124 return memhash(oid
->hash
, the_hash_algo
->rawsz
) + strhash(string
);
127 static void cache_put_path(struct submodule_cache
*cache
,
128 struct submodule
*submodule
)
130 unsigned int hash
= hash_oid_string(&submodule
->gitmodules_oid
,
132 struct submodule_entry
*e
= xmalloc(sizeof(*e
));
133 hashmap_entry_init(&e
->ent
, hash
);
134 e
->config
= submodule
;
135 hashmap_put(&cache
->for_path
, &e
->ent
);
138 static void cache_remove_path(struct submodule_cache
*cache
,
139 struct submodule
*submodule
)
141 unsigned int hash
= hash_oid_string(&submodule
->gitmodules_oid
,
143 struct submodule_entry e
;
144 struct submodule_entry
*removed
;
145 hashmap_entry_init(&e
.ent
, hash
);
146 e
.config
= submodule
;
147 removed
= hashmap_remove_entry(&cache
->for_path
, &e
, ent
, NULL
);
151 static void cache_add(struct submodule_cache
*cache
,
152 struct submodule
*submodule
)
154 unsigned int hash
= hash_oid_string(&submodule
->gitmodules_oid
,
156 struct submodule_entry
*e
= xmalloc(sizeof(*e
));
157 hashmap_entry_init(&e
->ent
, hash
);
158 e
->config
= submodule
;
159 hashmap_add(&cache
->for_name
, &e
->ent
);
162 static const struct submodule
*cache_lookup_path(struct submodule_cache
*cache
,
163 const struct object_id
*gitmodules_oid
, const char *path
)
165 struct submodule_entry
*entry
;
166 unsigned int hash
= hash_oid_string(gitmodules_oid
, path
);
167 struct submodule_entry key
;
168 struct submodule key_config
;
170 oidcpy(&key_config
.gitmodules_oid
, gitmodules_oid
);
171 key_config
.path
= path
;
173 hashmap_entry_init(&key
.ent
, hash
);
174 key
.config
= &key_config
;
176 entry
= hashmap_get_entry(&cache
->for_path
, &key
, ent
, NULL
);
178 return entry
->config
;
182 static struct submodule
*cache_lookup_name(struct submodule_cache
*cache
,
183 const struct object_id
*gitmodules_oid
, const char *name
)
185 struct submodule_entry
*entry
;
186 unsigned int hash
= hash_oid_string(gitmodules_oid
, name
);
187 struct submodule_entry key
;
188 struct submodule key_config
;
190 oidcpy(&key_config
.gitmodules_oid
, gitmodules_oid
);
191 key_config
.name
= name
;
193 hashmap_entry_init(&key
.ent
, hash
);
194 key
.config
= &key_config
;
196 entry
= hashmap_get_entry(&cache
->for_name
, &key
, ent
, NULL
);
198 return entry
->config
;
202 int check_submodule_name(const char *name
)
204 /* Disallow empty names */
209 * Look for '..' as a path component. Check is_xplatform_dir_sep() as
210 * separators rather than is_dir_sep(), because we want the name rules
211 * to be consistent across platforms.
213 goto in_component
; /* always start inside component */
216 if (is_xplatform_dir_sep(c
)) {
218 if (name
[0] == '.' && name
[1] == '.' &&
219 (!name
[2] || is_xplatform_dir_sep(name
[2])))
227 static int name_and_item_from_var(const char *var
, struct strbuf
*name
,
230 const char *subsection
, *key
;
231 size_t subsection_len
;
233 parse
= parse_config_key(var
, "submodule", &subsection
,
234 &subsection_len
, &key
);
235 if (parse
< 0 || !subsection
)
238 strbuf_add(name
, subsection
, subsection_len
);
239 if (check_submodule_name(name
->buf
) < 0) {
240 warning(_("ignoring suspicious submodule name: %s"), name
->buf
);
241 strbuf_release(name
);
245 strbuf_addstr(item
, key
);
250 static struct submodule
*lookup_or_create_by_name(struct submodule_cache
*cache
,
251 const struct object_id
*gitmodules_oid
, const char *name
)
253 struct submodule
*submodule
;
254 struct strbuf name_buf
= STRBUF_INIT
;
256 submodule
= cache_lookup_name(cache
, gitmodules_oid
, name
);
260 submodule
= xmalloc(sizeof(*submodule
));
262 strbuf_addstr(&name_buf
, name
);
263 submodule
->name
= strbuf_detach(&name_buf
, NULL
);
265 submodule
->path
= NULL
;
266 submodule
->url
= NULL
;
267 submodule
->update_strategy
.type
= SM_UPDATE_UNSPECIFIED
;
268 submodule
->update_strategy
.command
= NULL
;
269 submodule
->fetch_recurse
= RECURSE_SUBMODULES_NONE
;
270 submodule
->ignore
= NULL
;
271 submodule
->branch
= NULL
;
272 submodule
->recommend_shallow
= -1;
274 oidcpy(&submodule
->gitmodules_oid
, gitmodules_oid
);
276 cache_add(cache
, submodule
);
281 static int parse_fetch_recurse(const char *opt
, const char *arg
,
284 switch (git_parse_maybe_bool(arg
)) {
286 return RECURSE_SUBMODULES_ON
;
288 return RECURSE_SUBMODULES_OFF
;
290 if (!strcmp(arg
, "on-demand"))
291 return RECURSE_SUBMODULES_ON_DEMAND
;
293 * Please update $__git_fetch_recurse_submodules in
294 * git-completion.bash when you add new options.
297 die("bad %s argument: %s", opt
, arg
);
299 return RECURSE_SUBMODULES_ERROR
;
303 int parse_submodule_fetchjobs(const char *var
, const char *value
)
305 int fetchjobs
= git_config_int(var
, value
);
307 die(_("negative values not allowed for submodule.fetchJobs"));
309 fetchjobs
= online_cpus();
313 int parse_fetch_recurse_submodules_arg(const char *opt
, const char *arg
)
315 return parse_fetch_recurse(opt
, arg
, 1);
318 int option_fetch_parse_recurse_submodules(const struct option
*opt
,
319 const char *arg
, int unset
)
329 *v
= RECURSE_SUBMODULES_OFF
;
332 *v
= parse_fetch_recurse_submodules_arg(opt
->long_name
, arg
);
334 *v
= RECURSE_SUBMODULES_ON
;
339 static int parse_update_recurse(const char *opt
, const char *arg
,
342 switch (git_parse_maybe_bool(arg
)) {
344 return RECURSE_SUBMODULES_ON
;
346 return RECURSE_SUBMODULES_OFF
;
349 die("bad %s argument: %s", opt
, arg
);
350 return RECURSE_SUBMODULES_ERROR
;
354 int parse_update_recurse_submodules_arg(const char *opt
, const char *arg
)
356 return parse_update_recurse(opt
, arg
, 1);
359 static int parse_push_recurse(const char *opt
, const char *arg
,
362 switch (git_parse_maybe_bool(arg
)) {
364 /* There's no simple "on" value when pushing */
366 die("bad %s argument: %s", opt
, arg
);
368 return RECURSE_SUBMODULES_ERROR
;
370 return RECURSE_SUBMODULES_OFF
;
372 if (!strcmp(arg
, "on-demand"))
373 return RECURSE_SUBMODULES_ON_DEMAND
;
374 else if (!strcmp(arg
, "check"))
375 return RECURSE_SUBMODULES_CHECK
;
376 else if (!strcmp(arg
, "only"))
377 return RECURSE_SUBMODULES_ONLY
;
379 * Please update $__git_push_recurse_submodules in
380 * git-completion.bash when you add new modes.
382 else if (die_on_error
)
383 die("bad %s argument: %s", opt
, arg
);
385 return RECURSE_SUBMODULES_ERROR
;
389 int parse_push_recurse_submodules_arg(const char *opt
, const char *arg
)
391 return parse_push_recurse(opt
, arg
, 1);
394 static void warn_multiple_config(const struct object_id
*treeish_name
,
395 const char *name
, const char *option
)
397 const char *commit_string
= "WORKTREE";
399 commit_string
= oid_to_hex(treeish_name
);
400 warning("%s:.gitmodules, multiple configurations found for "
401 "'submodule.%s.%s'. Skipping second one!",
402 commit_string
, name
, option
);
405 static void warn_command_line_option(const char *var
, const char *value
)
407 warning(_("ignoring '%s' which may be interpreted as"
408 " a command-line option: %s"), var
, value
);
411 struct parse_config_parameter
{
412 struct submodule_cache
*cache
;
413 const struct object_id
*treeish_name
;
414 const struct object_id
*gitmodules_oid
;
419 * Parse a config item from .gitmodules.
421 * This does not handle submodule-related configuration from the main
422 * config store (.git/config, etc). Callers are responsible for
423 * checking for overrides in the main config store when appropriate.
425 static int parse_config(const char *var
, const char *value
, void *data
)
427 struct parse_config_parameter
*me
= data
;
428 struct submodule
*submodule
;
429 struct strbuf name
= STRBUF_INIT
, item
= STRBUF_INIT
;
432 /* this also ensures that we only parse submodule entries */
433 if (!name_and_item_from_var(var
, &name
, &item
))
436 submodule
= lookup_or_create_by_name(me
->cache
,
440 if (!strcmp(item
.buf
, "path")) {
442 ret
= config_error_nonbool(var
);
443 else if (looks_like_command_line_option(value
))
444 warn_command_line_option(var
, value
);
445 else if (!me
->overwrite
&& submodule
->path
)
446 warn_multiple_config(me
->treeish_name
, submodule
->name
,
450 cache_remove_path(me
->cache
, submodule
);
451 free((void *) submodule
->path
);
452 submodule
->path
= xstrdup(value
);
453 cache_put_path(me
->cache
, submodule
);
455 } else if (!strcmp(item
.buf
, "fetchrecursesubmodules")) {
456 /* when parsing worktree configurations we can die early */
457 int die_on_error
= is_null_oid(me
->gitmodules_oid
);
458 if (!me
->overwrite
&&
459 submodule
->fetch_recurse
!= RECURSE_SUBMODULES_NONE
)
460 warn_multiple_config(me
->treeish_name
, submodule
->name
,
461 "fetchrecursesubmodules");
463 submodule
->fetch_recurse
= parse_fetch_recurse(
466 } else if (!strcmp(item
.buf
, "ignore")) {
468 ret
= config_error_nonbool(var
);
469 else if (!me
->overwrite
&& submodule
->ignore
)
470 warn_multiple_config(me
->treeish_name
, submodule
->name
,
472 else if (strcmp(value
, "untracked") &&
473 strcmp(value
, "dirty") &&
474 strcmp(value
, "all") &&
475 strcmp(value
, "none"))
476 warning("Invalid parameter '%s' for config option "
477 "'submodule.%s.ignore'", value
, name
.buf
);
479 free((void *) submodule
->ignore
);
480 submodule
->ignore
= xstrdup(value
);
482 } else if (!strcmp(item
.buf
, "url")) {
484 ret
= config_error_nonbool(var
);
485 } else if (looks_like_command_line_option(value
)) {
486 warn_command_line_option(var
, value
);
487 } else if (!me
->overwrite
&& submodule
->url
) {
488 warn_multiple_config(me
->treeish_name
, submodule
->name
,
491 free((void *) submodule
->url
);
492 submodule
->url
= xstrdup(value
);
494 } else if (!strcmp(item
.buf
, "update")) {
496 ret
= config_error_nonbool(var
);
497 else if (!me
->overwrite
&&
498 submodule
->update_strategy
.type
!= SM_UPDATE_UNSPECIFIED
)
499 warn_multiple_config(me
->treeish_name
, submodule
->name
,
501 else if (parse_submodule_update_strategy(value
,
502 &submodule
->update_strategy
) < 0 ||
503 submodule
->update_strategy
.type
== SM_UPDATE_COMMAND
)
504 die(_("invalid value for '%s'"), var
);
505 } else if (!strcmp(item
.buf
, "shallow")) {
506 if (!me
->overwrite
&& submodule
->recommend_shallow
!= -1)
507 warn_multiple_config(me
->treeish_name
, submodule
->name
,
510 submodule
->recommend_shallow
=
511 git_config_bool(var
, value
);
512 } else if (!strcmp(item
.buf
, "branch")) {
513 if (!me
->overwrite
&& submodule
->branch
)
514 warn_multiple_config(me
->treeish_name
, submodule
->name
,
517 free((void *)submodule
->branch
);
518 submodule
->branch
= xstrdup(value
);
522 strbuf_release(&name
);
523 strbuf_release(&item
);
528 static int gitmodule_oid_from_commit(const struct object_id
*treeish_name
,
529 struct object_id
*gitmodules_oid
,
534 if (is_null_oid(treeish_name
)) {
535 oidclr(gitmodules_oid
);
539 strbuf_addf(rev
, "%s:.gitmodules", oid_to_hex(treeish_name
));
540 if (get_oid(rev
->buf
, gitmodules_oid
) >= 0)
546 /* This does a lookup of a submodule configuration by name or by path
547 * (key) with on-demand reading of the appropriate .gitmodules from
550 static const struct submodule
*config_from(struct submodule_cache
*cache
,
551 const struct object_id
*treeish_name
, const char *key
,
552 enum lookup_type lookup_type
)
554 struct strbuf rev
= STRBUF_INIT
;
555 unsigned long config_size
;
557 struct object_id oid
;
558 enum object_type type
;
559 const struct submodule
*submodule
= NULL
;
560 struct parse_config_parameter parameter
;
563 * If any parameter except the cache is a NULL pointer just
564 * return the first submodule. Can be used to check whether
565 * there are any submodules parsed.
567 if (!treeish_name
|| !key
) {
568 struct hashmap_iter iter
;
569 struct submodule_entry
*entry
;
571 entry
= hashmap_iter_first_entry(&cache
->for_name
, &iter
,
572 struct submodule_entry
,
573 ent
/* member name */);
576 return entry
->config
;
579 if (!gitmodule_oid_from_commit(treeish_name
, &oid
, &rev
))
582 switch (lookup_type
) {
584 submodule
= cache_lookup_name(cache
, &oid
, key
);
587 submodule
= cache_lookup_path(cache
, &oid
, key
);
593 config
= read_object_file(&oid
, &type
, &config_size
);
594 if (!config
|| type
!= OBJ_BLOB
)
597 /* fill the submodule config into the cache */
598 parameter
.cache
= cache
;
599 parameter
.treeish_name
= treeish_name
;
600 parameter
.gitmodules_oid
= &oid
;
601 parameter
.overwrite
= 0;
602 git_config_from_mem(parse_config
, CONFIG_ORIGIN_SUBMODULE_BLOB
, rev
.buf
,
603 config
, config_size
, ¶meter
, NULL
);
604 strbuf_release(&rev
);
607 switch (lookup_type
) {
609 return cache_lookup_name(cache
, &oid
, key
);
611 return cache_lookup_path(cache
, &oid
, key
);
617 strbuf_release(&rev
);
622 static void submodule_cache_check_init(struct repository
*repo
)
624 if (repo
->submodule_cache
&& repo
->submodule_cache
->initialized
)
627 if (!repo
->submodule_cache
)
628 repo
->submodule_cache
= submodule_cache_alloc();
630 submodule_cache_init(repo
->submodule_cache
);
634 * Note: This function is private for a reason, the '.gitmodules' file should
635 * not be used as a mechanism to retrieve arbitrary configuration stored in
638 * Runs the provided config function on the '.gitmodules' file found in the
641 static void config_from_gitmodules(config_fn_t fn
, struct repository
*repo
, void *data
)
643 if (repo
->worktree
) {
644 struct git_config_source config_source
= {
645 0, .scope
= CONFIG_SCOPE_SUBMODULE
647 const struct config_options opts
= { 0 };
648 struct object_id oid
;
652 file
= repo_worktree_path(repo
, GITMODULES_FILE
);
653 if (file_exists(file
)) {
654 config_source
.file
= file
;
655 } else if (repo_get_oid(repo
, GITMODULES_INDEX
, &oid
) >= 0 ||
656 repo_get_oid(repo
, GITMODULES_HEAD
, &oid
) >= 0) {
657 config_source
.repo
= repo
;
658 config_source
.blob
= oidstr
= xstrdup(oid_to_hex(&oid
));
659 if (repo
!= the_repository
)
660 add_submodule_odb_by_path(repo
->objects
->odb
->path
);
665 config_with_options(fn
, data
, &config_source
, &opts
);
673 static int gitmodules_cb(const char *var
, const char *value
, void *data
)
675 struct repository
*repo
= data
;
676 struct parse_config_parameter parameter
;
678 parameter
.cache
= repo
->submodule_cache
;
679 parameter
.treeish_name
= NULL
;
680 parameter
.gitmodules_oid
= null_oid();
681 parameter
.overwrite
= 1;
683 return parse_config(var
, value
, ¶meter
);
686 void repo_read_gitmodules(struct repository
*repo
, int skip_if_read
)
688 submodule_cache_check_init(repo
);
690 if (repo
->submodule_cache
->gitmodules_read
&& skip_if_read
)
693 if (repo_read_index(repo
) < 0)
696 if (!is_gitmodules_unmerged(repo
->index
))
697 config_from_gitmodules(gitmodules_cb
, repo
, repo
);
699 repo
->submodule_cache
->gitmodules_read
= 1;
702 void gitmodules_config_oid(const struct object_id
*commit_oid
)
704 struct strbuf rev
= STRBUF_INIT
;
705 struct object_id oid
;
707 submodule_cache_check_init(the_repository
);
709 if (gitmodule_oid_from_commit(commit_oid
, &oid
, &rev
)) {
710 git_config_from_blob_oid(gitmodules_cb
, rev
.buf
,
711 the_repository
, &oid
, the_repository
);
713 strbuf_release(&rev
);
715 the_repository
->submodule_cache
->gitmodules_read
= 1;
718 const struct submodule
*submodule_from_name(struct repository
*r
,
719 const struct object_id
*treeish_name
,
722 repo_read_gitmodules(r
, 1);
723 return config_from(r
->submodule_cache
, treeish_name
, name
, lookup_name
);
726 const struct submodule
*submodule_from_path(struct repository
*r
,
727 const struct object_id
*treeish_name
,
730 repo_read_gitmodules(r
, 1);
731 return config_from(r
->submodule_cache
, treeish_name
, path
, lookup_path
);
735 * Used internally by submodules_of_tree(). Recurses into 'treeish_name'
736 * and appends submodule entries to 'out'. The submodule_cache expects
737 * a root-level treeish_name and paths, so keep track of these values
738 * with 'root_tree' and 'prefix'.
740 static void traverse_tree_submodules(struct repository
*r
,
741 const struct object_id
*root_tree
,
743 const struct object_id
*treeish_name
,
744 struct submodule_entry_list
*out
)
746 struct tree_desc tree
;
747 struct submodule_tree_entry
*st_entry
;
748 struct name_entry
*name_entry
;
749 char *tree_path
= NULL
;
751 name_entry
= xmalloc(sizeof(*name_entry
));
753 fill_tree_descriptor(r
, &tree
, treeish_name
);
754 while (tree_entry(&tree
, name_entry
)) {
757 mkpathdup("%s/%s", prefix
, name_entry
->path
);
759 tree_path
= xstrdup(name_entry
->path
);
761 if (S_ISGITLINK(name_entry
->mode
) &&
762 is_tree_submodule_active(r
, root_tree
, tree_path
)) {
763 ALLOC_GROW(out
->entries
, out
->entry_nr
+ 1,
765 st_entry
= &out
->entries
[out
->entry_nr
++];
767 st_entry
->name_entry
= xmalloc(sizeof(*st_entry
->name_entry
));
768 *st_entry
->name_entry
= *name_entry
;
769 st_entry
->submodule
=
770 submodule_from_path(r
, root_tree
, tree_path
);
771 st_entry
->repo
= xmalloc(sizeof(*st_entry
->repo
));
772 if (repo_submodule_init(st_entry
->repo
, r
, tree_path
,
774 FREE_AND_NULL(st_entry
->repo
);
776 } else if (S_ISDIR(name_entry
->mode
))
777 traverse_tree_submodules(r
, root_tree
, tree_path
,
778 &name_entry
->oid
, out
);
783 void submodules_of_tree(struct repository
*r
,
784 const struct object_id
*treeish_name
,
785 struct submodule_entry_list
*out
)
787 CALLOC_ARRAY(out
->entries
, 0);
789 out
->entry_alloc
= 0;
791 traverse_tree_submodules(r
, treeish_name
, NULL
, treeish_name
, out
);
794 void submodule_free(struct repository
*r
)
796 if (r
->submodule_cache
)
797 submodule_cache_clear(r
->submodule_cache
);
800 static int config_print_callback(const char *var
, const char *value
, void *cb_data
)
802 char *wanted_key
= cb_data
;
804 if (!strcmp(wanted_key
, var
))
805 printf("%s\n", value
);
810 int print_config_from_gitmodules(struct repository
*repo
, const char *key
)
815 ret
= git_config_parse_key(key
, &store_key
, NULL
);
817 return CONFIG_INVALID_KEY
;
819 config_from_gitmodules(config_print_callback
, repo
, store_key
);
825 int config_set_in_gitmodules_file_gently(const char *key
, const char *value
)
829 ret
= git_config_set_in_file_gently(GITMODULES_FILE
, key
, value
);
831 /* Maybe the user already did that, don't error out here */
832 warning(_("Could not update .gitmodules entry %s"), key
);
837 struct fetch_config
{
839 int *recurse_submodules
;
842 static int gitmodules_fetch_config(const char *var
, const char *value
, void *cb
)
844 struct fetch_config
*config
= cb
;
845 if (!strcmp(var
, "submodule.fetchjobs")) {
846 if (config
->max_children
)
847 *(config
->max_children
) =
848 parse_submodule_fetchjobs(var
, value
);
850 } else if (!strcmp(var
, "fetch.recursesubmodules")) {
851 if (config
->recurse_submodules
)
852 *(config
->recurse_submodules
) =
853 parse_fetch_recurse_submodules_arg(var
, value
);
860 void fetch_config_from_gitmodules(int *max_children
, int *recurse_submodules
)
862 struct fetch_config config
= {
863 .max_children
= max_children
,
864 .recurse_submodules
= recurse_submodules
866 config_from_gitmodules(gitmodules_fetch_config
, the_repository
, &config
);
869 static int gitmodules_update_clone_config(const char *var
, const char *value
,
873 if (!strcmp(var
, "submodule.fetchjobs"))
874 *max_jobs
= parse_submodule_fetchjobs(var
, value
);
878 void update_clone_config_from_gitmodules(int *max_jobs
)
880 config_from_gitmodules(gitmodules_update_clone_config
, the_repository
, &max_jobs
);