4 #include "environment.h"
7 #include "repository.h"
9 #include "submodule-config.h"
10 #include "submodule.h"
12 #include "object-store.h"
13 #include "parse-options.h"
14 #include "tree-walk.h"
17 * submodule cache lookup structure
18 * There is one shared set of 'struct submodule' entries which can be
19 * looked up by their sha1 blob id of the .gitmodules file and either
20 * using path or name as key.
21 * for_path stores submodule entries with path as key
22 * for_name stores submodule entries with name as key
24 struct submodule_cache
{
25 struct hashmap for_path
;
26 struct hashmap for_name
;
27 unsigned initialized
:1;
28 unsigned gitmodules_read
:1;
32 * thin wrapper struct needed to insert 'struct submodule' entries to
35 struct submodule_entry
{
36 struct hashmap_entry ent
;
37 struct submodule
*config
;
45 static int config_path_cmp(const void *cmp_data UNUSED
,
46 const struct hashmap_entry
*eptr
,
47 const struct hashmap_entry
*entry_or_key
,
48 const void *keydata UNUSED
)
50 const struct submodule_entry
*a
, *b
;
52 a
= container_of(eptr
, const struct submodule_entry
, ent
);
53 b
= container_of(entry_or_key
, const struct submodule_entry
, ent
);
55 return strcmp(a
->config
->path
, b
->config
->path
) ||
56 !oideq(&a
->config
->gitmodules_oid
, &b
->config
->gitmodules_oid
);
59 static int config_name_cmp(const void *cmp_data UNUSED
,
60 const struct hashmap_entry
*eptr
,
61 const struct hashmap_entry
*entry_or_key
,
62 const void *keydata UNUSED
)
64 const struct submodule_entry
*a
, *b
;
66 a
= container_of(eptr
, const struct submodule_entry
, ent
);
67 b
= container_of(entry_or_key
, const struct submodule_entry
, ent
);
69 return strcmp(a
->config
->name
, b
->config
->name
) ||
70 !oideq(&a
->config
->gitmodules_oid
, &b
->config
->gitmodules_oid
);
73 static struct submodule_cache
*submodule_cache_alloc(void)
75 return xcalloc(1, sizeof(struct submodule_cache
));
78 static void submodule_cache_init(struct submodule_cache
*cache
)
80 hashmap_init(&cache
->for_path
, config_path_cmp
, NULL
, 0);
81 hashmap_init(&cache
->for_name
, config_name_cmp
, NULL
, 0);
82 cache
->initialized
= 1;
85 static void free_one_config(struct submodule_entry
*entry
)
87 free((void *) entry
->config
->path
);
88 free((void *) entry
->config
->name
);
89 free((void *) entry
->config
->branch
);
90 free((void *) entry
->config
->update_strategy
.command
);
94 static void submodule_cache_clear(struct submodule_cache
*cache
)
96 struct hashmap_iter iter
;
97 struct submodule_entry
*entry
;
99 if (!cache
->initialized
)
103 * We iterate over the name hash here to be symmetric with the
104 * allocation of struct submodule entries. Each is allocated by
105 * their .gitmodules blob sha1 and submodule name.
107 hashmap_for_each_entry(&cache
->for_name
, &iter
, entry
,
108 ent
/* member name */)
109 free_one_config(entry
);
111 hashmap_clear_and_free(&cache
->for_path
, struct submodule_entry
, ent
);
112 hashmap_clear_and_free(&cache
->for_name
, struct submodule_entry
, ent
);
113 cache
->initialized
= 0;
114 cache
->gitmodules_read
= 0;
117 void submodule_cache_free(struct submodule_cache
*cache
)
119 submodule_cache_clear(cache
);
123 static unsigned int hash_oid_string(const struct object_id
*oid
,
126 return memhash(oid
->hash
, the_hash_algo
->rawsz
) + strhash(string
);
129 static void cache_put_path(struct submodule_cache
*cache
,
130 struct submodule
*submodule
)
132 unsigned int hash
= hash_oid_string(&submodule
->gitmodules_oid
,
134 struct submodule_entry
*e
= xmalloc(sizeof(*e
));
135 hashmap_entry_init(&e
->ent
, hash
);
136 e
->config
= submodule
;
137 hashmap_put(&cache
->for_path
, &e
->ent
);
140 static void cache_remove_path(struct submodule_cache
*cache
,
141 struct submodule
*submodule
)
143 unsigned int hash
= hash_oid_string(&submodule
->gitmodules_oid
,
145 struct submodule_entry e
;
146 struct submodule_entry
*removed
;
147 hashmap_entry_init(&e
.ent
, hash
);
148 e
.config
= submodule
;
149 removed
= hashmap_remove_entry(&cache
->for_path
, &e
, ent
, NULL
);
153 static void cache_add(struct submodule_cache
*cache
,
154 struct submodule
*submodule
)
156 unsigned int hash
= hash_oid_string(&submodule
->gitmodules_oid
,
158 struct submodule_entry
*e
= xmalloc(sizeof(*e
));
159 hashmap_entry_init(&e
->ent
, hash
);
160 e
->config
= submodule
;
161 hashmap_add(&cache
->for_name
, &e
->ent
);
164 static const struct submodule
*cache_lookup_path(struct submodule_cache
*cache
,
165 const struct object_id
*gitmodules_oid
, const char *path
)
167 struct submodule_entry
*entry
;
168 unsigned int hash
= hash_oid_string(gitmodules_oid
, path
);
169 struct submodule_entry key
;
170 struct submodule key_config
;
172 oidcpy(&key_config
.gitmodules_oid
, gitmodules_oid
);
173 key_config
.path
= path
;
175 hashmap_entry_init(&key
.ent
, hash
);
176 key
.config
= &key_config
;
178 entry
= hashmap_get_entry(&cache
->for_path
, &key
, ent
, NULL
);
180 return entry
->config
;
184 static struct submodule
*cache_lookup_name(struct submodule_cache
*cache
,
185 const struct object_id
*gitmodules_oid
, const char *name
)
187 struct submodule_entry
*entry
;
188 unsigned int hash
= hash_oid_string(gitmodules_oid
, name
);
189 struct submodule_entry key
;
190 struct submodule key_config
;
192 oidcpy(&key_config
.gitmodules_oid
, gitmodules_oid
);
193 key_config
.name
= name
;
195 hashmap_entry_init(&key
.ent
, hash
);
196 key
.config
= &key_config
;
198 entry
= hashmap_get_entry(&cache
->for_name
, &key
, ent
, NULL
);
200 return entry
->config
;
204 int check_submodule_name(const char *name
)
206 /* Disallow empty names */
211 * Look for '..' as a path component. Check is_xplatform_dir_sep() as
212 * separators rather than is_dir_sep(), because we want the name rules
213 * to be consistent across platforms.
215 goto in_component
; /* always start inside component */
218 if (is_xplatform_dir_sep(c
)) {
220 if (name
[0] == '.' && name
[1] == '.' &&
221 (!name
[2] || is_xplatform_dir_sep(name
[2])))
229 static int name_and_item_from_var(const char *var
, struct strbuf
*name
,
232 const char *subsection
, *key
;
233 size_t subsection_len
;
235 parse
= parse_config_key(var
, "submodule", &subsection
,
236 &subsection_len
, &key
);
237 if (parse
< 0 || !subsection
)
240 strbuf_add(name
, subsection
, subsection_len
);
241 if (check_submodule_name(name
->buf
) < 0) {
242 warning(_("ignoring suspicious submodule name: %s"), name
->buf
);
243 strbuf_release(name
);
247 strbuf_addstr(item
, key
);
252 static struct submodule
*lookup_or_create_by_name(struct submodule_cache
*cache
,
253 const struct object_id
*gitmodules_oid
, const char *name
)
255 struct submodule
*submodule
;
256 struct strbuf name_buf
= STRBUF_INIT
;
258 submodule
= cache_lookup_name(cache
, gitmodules_oid
, name
);
262 submodule
= xmalloc(sizeof(*submodule
));
264 strbuf_addstr(&name_buf
, name
);
265 submodule
->name
= strbuf_detach(&name_buf
, NULL
);
267 submodule
->path
= NULL
;
268 submodule
->url
= NULL
;
269 submodule
->update_strategy
.type
= SM_UPDATE_UNSPECIFIED
;
270 submodule
->update_strategy
.command
= NULL
;
271 submodule
->fetch_recurse
= RECURSE_SUBMODULES_NONE
;
272 submodule
->ignore
= NULL
;
273 submodule
->branch
= NULL
;
274 submodule
->recommend_shallow
= -1;
276 oidcpy(&submodule
->gitmodules_oid
, gitmodules_oid
);
278 cache_add(cache
, submodule
);
283 static int parse_fetch_recurse(const char *opt
, const char *arg
,
286 switch (git_parse_maybe_bool(arg
)) {
288 return RECURSE_SUBMODULES_ON
;
290 return RECURSE_SUBMODULES_OFF
;
292 if (!strcmp(arg
, "on-demand"))
293 return RECURSE_SUBMODULES_ON_DEMAND
;
295 * Please update $__git_fetch_recurse_submodules in
296 * git-completion.bash when you add new options.
299 die("bad %s argument: %s", opt
, arg
);
301 return RECURSE_SUBMODULES_ERROR
;
305 int parse_submodule_fetchjobs(const char *var
, const char *value
)
307 int fetchjobs
= git_config_int(var
, value
);
309 die(_("negative values not allowed for submodule.fetchJobs"));
311 fetchjobs
= online_cpus();
315 int parse_fetch_recurse_submodules_arg(const char *opt
, const char *arg
)
317 return parse_fetch_recurse(opt
, arg
, 1);
320 int option_fetch_parse_recurse_submodules(const struct option
*opt
,
321 const char *arg
, int unset
)
331 *v
= RECURSE_SUBMODULES_OFF
;
334 *v
= parse_fetch_recurse_submodules_arg(opt
->long_name
, arg
);
336 *v
= RECURSE_SUBMODULES_ON
;
341 static int parse_update_recurse(const char *opt
, const char *arg
,
344 switch (git_parse_maybe_bool(arg
)) {
346 return RECURSE_SUBMODULES_ON
;
348 return RECURSE_SUBMODULES_OFF
;
351 die("bad %s argument: %s", opt
, arg
);
352 return RECURSE_SUBMODULES_ERROR
;
356 int parse_update_recurse_submodules_arg(const char *opt
, const char *arg
)
358 return parse_update_recurse(opt
, arg
, 1);
361 static int parse_push_recurse(const char *opt
, const char *arg
,
364 switch (git_parse_maybe_bool(arg
)) {
366 /* There's no simple "on" value when pushing */
368 die("bad %s argument: %s", opt
, arg
);
370 return RECURSE_SUBMODULES_ERROR
;
372 return RECURSE_SUBMODULES_OFF
;
374 if (!strcmp(arg
, "on-demand"))
375 return RECURSE_SUBMODULES_ON_DEMAND
;
376 else if (!strcmp(arg
, "check"))
377 return RECURSE_SUBMODULES_CHECK
;
378 else if (!strcmp(arg
, "only"))
379 return RECURSE_SUBMODULES_ONLY
;
381 * Please update $__git_push_recurse_submodules in
382 * git-completion.bash when you add new modes.
384 else if (die_on_error
)
385 die("bad %s argument: %s", opt
, arg
);
387 return RECURSE_SUBMODULES_ERROR
;
391 int parse_push_recurse_submodules_arg(const char *opt
, const char *arg
)
393 return parse_push_recurse(opt
, arg
, 1);
396 static void warn_multiple_config(const struct object_id
*treeish_name
,
397 const char *name
, const char *option
)
399 const char *commit_string
= "WORKTREE";
401 commit_string
= oid_to_hex(treeish_name
);
402 warning("%s:.gitmodules, multiple configurations found for "
403 "'submodule.%s.%s'. Skipping second one!",
404 commit_string
, name
, option
);
407 static void warn_command_line_option(const char *var
, const char *value
)
409 warning(_("ignoring '%s' which may be interpreted as"
410 " a command-line option: %s"), var
, value
);
413 struct parse_config_parameter
{
414 struct submodule_cache
*cache
;
415 const struct object_id
*treeish_name
;
416 const struct object_id
*gitmodules_oid
;
421 * Parse a config item from .gitmodules.
423 * This does not handle submodule-related configuration from the main
424 * config store (.git/config, etc). Callers are responsible for
425 * checking for overrides in the main config store when appropriate.
427 static int parse_config(const char *var
, const char *value
, void *data
)
429 struct parse_config_parameter
*me
= data
;
430 struct submodule
*submodule
;
431 struct strbuf name
= STRBUF_INIT
, item
= STRBUF_INIT
;
434 /* this also ensures that we only parse submodule entries */
435 if (!name_and_item_from_var(var
, &name
, &item
))
438 submodule
= lookup_or_create_by_name(me
->cache
,
442 if (!strcmp(item
.buf
, "path")) {
444 ret
= config_error_nonbool(var
);
445 else if (looks_like_command_line_option(value
))
446 warn_command_line_option(var
, value
);
447 else if (!me
->overwrite
&& submodule
->path
)
448 warn_multiple_config(me
->treeish_name
, submodule
->name
,
452 cache_remove_path(me
->cache
, submodule
);
453 free((void *) submodule
->path
);
454 submodule
->path
= xstrdup(value
);
455 cache_put_path(me
->cache
, submodule
);
457 } else if (!strcmp(item
.buf
, "fetchrecursesubmodules")) {
458 /* when parsing worktree configurations we can die early */
459 int die_on_error
= is_null_oid(me
->gitmodules_oid
);
460 if (!me
->overwrite
&&
461 submodule
->fetch_recurse
!= RECURSE_SUBMODULES_NONE
)
462 warn_multiple_config(me
->treeish_name
, submodule
->name
,
463 "fetchrecursesubmodules");
465 submodule
->fetch_recurse
= parse_fetch_recurse(
468 } else if (!strcmp(item
.buf
, "ignore")) {
470 ret
= config_error_nonbool(var
);
471 else if (!me
->overwrite
&& submodule
->ignore
)
472 warn_multiple_config(me
->treeish_name
, submodule
->name
,
474 else if (strcmp(value
, "untracked") &&
475 strcmp(value
, "dirty") &&
476 strcmp(value
, "all") &&
477 strcmp(value
, "none"))
478 warning("Invalid parameter '%s' for config option "
479 "'submodule.%s.ignore'", value
, name
.buf
);
481 free((void *) submodule
->ignore
);
482 submodule
->ignore
= xstrdup(value
);
484 } else if (!strcmp(item
.buf
, "url")) {
486 ret
= config_error_nonbool(var
);
487 } else if (looks_like_command_line_option(value
)) {
488 warn_command_line_option(var
, value
);
489 } else if (!me
->overwrite
&& submodule
->url
) {
490 warn_multiple_config(me
->treeish_name
, submodule
->name
,
493 free((void *) submodule
->url
);
494 submodule
->url
= xstrdup(value
);
496 } else if (!strcmp(item
.buf
, "update")) {
498 ret
= config_error_nonbool(var
);
499 else if (!me
->overwrite
&&
500 submodule
->update_strategy
.type
!= SM_UPDATE_UNSPECIFIED
)
501 warn_multiple_config(me
->treeish_name
, submodule
->name
,
503 else if (parse_submodule_update_strategy(value
,
504 &submodule
->update_strategy
) < 0 ||
505 submodule
->update_strategy
.type
== SM_UPDATE_COMMAND
)
506 die(_("invalid value for '%s'"), var
);
507 } else if (!strcmp(item
.buf
, "shallow")) {
508 if (!me
->overwrite
&& submodule
->recommend_shallow
!= -1)
509 warn_multiple_config(me
->treeish_name
, submodule
->name
,
512 submodule
->recommend_shallow
=
513 git_config_bool(var
, value
);
514 } else if (!strcmp(item
.buf
, "branch")) {
515 if (!me
->overwrite
&& submodule
->branch
)
516 warn_multiple_config(me
->treeish_name
, submodule
->name
,
519 free((void *)submodule
->branch
);
520 submodule
->branch
= xstrdup(value
);
524 strbuf_release(&name
);
525 strbuf_release(&item
);
530 static int gitmodule_oid_from_commit(const struct object_id
*treeish_name
,
531 struct object_id
*gitmodules_oid
,
536 if (is_null_oid(treeish_name
)) {
537 oidclr(gitmodules_oid
);
541 strbuf_addf(rev
, "%s:.gitmodules", oid_to_hex(treeish_name
));
542 if (repo_get_oid(the_repository
, rev
->buf
, gitmodules_oid
) >= 0)
548 /* This does a lookup of a submodule configuration by name or by path
549 * (key) with on-demand reading of the appropriate .gitmodules from
552 static const struct submodule
*config_from(struct submodule_cache
*cache
,
553 const struct object_id
*treeish_name
, const char *key
,
554 enum lookup_type lookup_type
)
556 struct strbuf rev
= STRBUF_INIT
;
557 unsigned long config_size
;
559 struct object_id oid
;
560 enum object_type type
;
561 const struct submodule
*submodule
= NULL
;
562 struct parse_config_parameter parameter
;
565 * If any parameter except the cache is a NULL pointer just
566 * return the first submodule. Can be used to check whether
567 * there are any submodules parsed.
569 if (!treeish_name
|| !key
) {
570 struct hashmap_iter iter
;
571 struct submodule_entry
*entry
;
573 entry
= hashmap_iter_first_entry(&cache
->for_name
, &iter
,
574 struct submodule_entry
,
575 ent
/* member name */);
578 return entry
->config
;
581 if (!gitmodule_oid_from_commit(treeish_name
, &oid
, &rev
))
584 switch (lookup_type
) {
586 submodule
= cache_lookup_name(cache
, &oid
, key
);
589 submodule
= cache_lookup_path(cache
, &oid
, key
);
595 config
= repo_read_object_file(the_repository
, &oid
, &type
,
597 if (!config
|| type
!= OBJ_BLOB
)
600 /* fill the submodule config into the cache */
601 parameter
.cache
= cache
;
602 parameter
.treeish_name
= treeish_name
;
603 parameter
.gitmodules_oid
= &oid
;
604 parameter
.overwrite
= 0;
605 git_config_from_mem(parse_config
, CONFIG_ORIGIN_SUBMODULE_BLOB
, rev
.buf
,
606 config
, config_size
, ¶meter
, NULL
);
607 strbuf_release(&rev
);
610 switch (lookup_type
) {
612 return cache_lookup_name(cache
, &oid
, key
);
614 return cache_lookup_path(cache
, &oid
, key
);
620 strbuf_release(&rev
);
625 static void submodule_cache_check_init(struct repository
*repo
)
627 if (repo
->submodule_cache
&& repo
->submodule_cache
->initialized
)
630 if (!repo
->submodule_cache
)
631 repo
->submodule_cache
= submodule_cache_alloc();
633 submodule_cache_init(repo
->submodule_cache
);
637 * Note: This function is private for a reason, the '.gitmodules' file should
638 * not be used as a mechanism to retrieve arbitrary configuration stored in
641 * Runs the provided config function on the '.gitmodules' file found in the
644 static void config_from_gitmodules(config_fn_t fn
, struct repository
*repo
, void *data
)
646 if (repo
->worktree
) {
647 struct git_config_source config_source
= {
648 0, .scope
= CONFIG_SCOPE_SUBMODULE
650 const struct config_options opts
= { 0 };
651 struct object_id oid
;
655 file
= repo_worktree_path(repo
, GITMODULES_FILE
);
656 if (file_exists(file
)) {
657 config_source
.file
= file
;
658 } else if (repo_get_oid(repo
, GITMODULES_INDEX
, &oid
) >= 0 ||
659 repo_get_oid(repo
, GITMODULES_HEAD
, &oid
) >= 0) {
660 config_source
.repo
= repo
;
661 config_source
.blob
= oidstr
= xstrdup(oid_to_hex(&oid
));
662 if (repo
!= the_repository
)
663 add_submodule_odb_by_path(repo
->objects
->odb
->path
);
668 config_with_options(fn
, data
, &config_source
, &opts
);
676 static int gitmodules_cb(const char *var
, const char *value
, void *data
)
678 struct repository
*repo
= data
;
679 struct parse_config_parameter parameter
;
681 parameter
.cache
= repo
->submodule_cache
;
682 parameter
.treeish_name
= NULL
;
683 parameter
.gitmodules_oid
= null_oid();
684 parameter
.overwrite
= 1;
686 return parse_config(var
, value
, ¶meter
);
689 void repo_read_gitmodules(struct repository
*repo
, int skip_if_read
)
691 submodule_cache_check_init(repo
);
693 if (repo
->submodule_cache
->gitmodules_read
&& skip_if_read
)
696 if (repo_read_index(repo
) < 0)
699 if (!is_gitmodules_unmerged(repo
->index
))
700 config_from_gitmodules(gitmodules_cb
, repo
, repo
);
702 repo
->submodule_cache
->gitmodules_read
= 1;
705 void gitmodules_config_oid(const struct object_id
*commit_oid
)
707 struct strbuf rev
= STRBUF_INIT
;
708 struct object_id oid
;
710 submodule_cache_check_init(the_repository
);
712 if (gitmodule_oid_from_commit(commit_oid
, &oid
, &rev
)) {
713 git_config_from_blob_oid(gitmodules_cb
, rev
.buf
,
714 the_repository
, &oid
, the_repository
);
716 strbuf_release(&rev
);
718 the_repository
->submodule_cache
->gitmodules_read
= 1;
721 const struct submodule
*submodule_from_name(struct repository
*r
,
722 const struct object_id
*treeish_name
,
725 repo_read_gitmodules(r
, 1);
726 return config_from(r
->submodule_cache
, treeish_name
, name
, lookup_name
);
729 const struct submodule
*submodule_from_path(struct repository
*r
,
730 const struct object_id
*treeish_name
,
733 repo_read_gitmodules(r
, 1);
734 return config_from(r
->submodule_cache
, treeish_name
, path
, lookup_path
);
738 * Used internally by submodules_of_tree(). Recurses into 'treeish_name'
739 * and appends submodule entries to 'out'. The submodule_cache expects
740 * a root-level treeish_name and paths, so keep track of these values
741 * with 'root_tree' and 'prefix'.
743 static void traverse_tree_submodules(struct repository
*r
,
744 const struct object_id
*root_tree
,
746 const struct object_id
*treeish_name
,
747 struct submodule_entry_list
*out
)
749 struct tree_desc tree
;
750 struct submodule_tree_entry
*st_entry
;
751 struct name_entry
*name_entry
;
752 char *tree_path
= NULL
;
754 name_entry
= xmalloc(sizeof(*name_entry
));
756 fill_tree_descriptor(r
, &tree
, treeish_name
);
757 while (tree_entry(&tree
, name_entry
)) {
760 mkpathdup("%s/%s", prefix
, name_entry
->path
);
762 tree_path
= xstrdup(name_entry
->path
);
764 if (S_ISGITLINK(name_entry
->mode
) &&
765 is_tree_submodule_active(r
, root_tree
, tree_path
)) {
766 ALLOC_GROW(out
->entries
, out
->entry_nr
+ 1,
768 st_entry
= &out
->entries
[out
->entry_nr
++];
770 st_entry
->name_entry
= xmalloc(sizeof(*st_entry
->name_entry
));
771 *st_entry
->name_entry
= *name_entry
;
772 st_entry
->submodule
=
773 submodule_from_path(r
, root_tree
, tree_path
);
774 st_entry
->repo
= xmalloc(sizeof(*st_entry
->repo
));
775 if (repo_submodule_init(st_entry
->repo
, r
, tree_path
,
777 FREE_AND_NULL(st_entry
->repo
);
779 } else if (S_ISDIR(name_entry
->mode
))
780 traverse_tree_submodules(r
, root_tree
, tree_path
,
781 &name_entry
->oid
, out
);
786 void submodules_of_tree(struct repository
*r
,
787 const struct object_id
*treeish_name
,
788 struct submodule_entry_list
*out
)
790 CALLOC_ARRAY(out
->entries
, 0);
792 out
->entry_alloc
= 0;
794 traverse_tree_submodules(r
, treeish_name
, NULL
, treeish_name
, out
);
797 void submodule_free(struct repository
*r
)
799 if (r
->submodule_cache
)
800 submodule_cache_clear(r
->submodule_cache
);
803 static int config_print_callback(const char *var
, const char *value
, void *cb_data
)
805 char *wanted_key
= cb_data
;
807 if (!strcmp(wanted_key
, var
))
808 printf("%s\n", value
);
813 int print_config_from_gitmodules(struct repository
*repo
, const char *key
)
818 ret
= git_config_parse_key(key
, &store_key
, NULL
);
820 return CONFIG_INVALID_KEY
;
822 config_from_gitmodules(config_print_callback
, repo
, store_key
);
828 int config_set_in_gitmodules_file_gently(const char *key
, const char *value
)
832 ret
= git_config_set_in_file_gently(GITMODULES_FILE
, key
, value
);
834 /* Maybe the user already did that, don't error out here */
835 warning(_("Could not update .gitmodules entry %s"), key
);
840 struct fetch_config
{
842 int *recurse_submodules
;
845 static int gitmodules_fetch_config(const char *var
, const char *value
, void *cb
)
847 struct fetch_config
*config
= cb
;
848 if (!strcmp(var
, "submodule.fetchjobs")) {
849 if (config
->max_children
)
850 *(config
->max_children
) =
851 parse_submodule_fetchjobs(var
, value
);
853 } else if (!strcmp(var
, "fetch.recursesubmodules")) {
854 if (config
->recurse_submodules
)
855 *(config
->recurse_submodules
) =
856 parse_fetch_recurse_submodules_arg(var
, value
);
863 void fetch_config_from_gitmodules(int *max_children
, int *recurse_submodules
)
865 struct fetch_config config
= {
866 .max_children
= max_children
,
867 .recurse_submodules
= recurse_submodules
869 config_from_gitmodules(gitmodules_fetch_config
, the_repository
, &config
);
872 static int gitmodules_update_clone_config(const char *var
, const char *value
,
876 if (!strcmp(var
, "submodule.fetchjobs"))
877 *max_jobs
= parse_submodule_fetchjobs(var
, value
);
881 void update_clone_config_from_gitmodules(int *max_jobs
)
883 config_from_gitmodules(gitmodules_update_clone_config
, the_repository
, &max_jobs
);