1 #include "git-compat-util.h"
4 #include "environment.h"
7 #include "repository.h"
9 #include "submodule-config.h"
10 #include "submodule.h"
12 #include "object-name.h"
13 #include "object-store.h"
14 #include "parse-options.h"
15 #include "tree-walk.h"
18 * submodule cache lookup structure
19 * There is one shared set of 'struct submodule' entries which can be
20 * looked up by their sha1 blob id of the .gitmodules file and either
21 * using path or name as key.
22 * for_path stores submodule entries with path as key
23 * for_name stores submodule entries with name as key
25 struct submodule_cache
{
26 struct hashmap for_path
;
27 struct hashmap for_name
;
28 unsigned initialized
:1;
29 unsigned gitmodules_read
:1;
33 * thin wrapper struct needed to insert 'struct submodule' entries to
36 struct submodule_entry
{
37 struct hashmap_entry ent
;
38 struct submodule
*config
;
46 static int config_path_cmp(const void *cmp_data UNUSED
,
47 const struct hashmap_entry
*eptr
,
48 const struct hashmap_entry
*entry_or_key
,
49 const void *keydata UNUSED
)
51 const struct submodule_entry
*a
, *b
;
53 a
= container_of(eptr
, const struct submodule_entry
, ent
);
54 b
= container_of(entry_or_key
, const struct submodule_entry
, ent
);
56 return strcmp(a
->config
->path
, b
->config
->path
) ||
57 !oideq(&a
->config
->gitmodules_oid
, &b
->config
->gitmodules_oid
);
60 static int config_name_cmp(const void *cmp_data UNUSED
,
61 const struct hashmap_entry
*eptr
,
62 const struct hashmap_entry
*entry_or_key
,
63 const void *keydata UNUSED
)
65 const struct submodule_entry
*a
, *b
;
67 a
= container_of(eptr
, const struct submodule_entry
, ent
);
68 b
= container_of(entry_or_key
, const struct submodule_entry
, ent
);
70 return strcmp(a
->config
->name
, b
->config
->name
) ||
71 !oideq(&a
->config
->gitmodules_oid
, &b
->config
->gitmodules_oid
);
74 static struct submodule_cache
*submodule_cache_alloc(void)
76 return xcalloc(1, sizeof(struct submodule_cache
));
79 static void submodule_cache_init(struct submodule_cache
*cache
)
81 hashmap_init(&cache
->for_path
, config_path_cmp
, NULL
, 0);
82 hashmap_init(&cache
->for_name
, config_name_cmp
, NULL
, 0);
83 cache
->initialized
= 1;
86 static void free_one_config(struct submodule_entry
*entry
)
88 free((void *) entry
->config
->path
);
89 free((void *) entry
->config
->name
);
90 free((void *) entry
->config
->branch
);
91 free((void *) entry
->config
->update_strategy
.command
);
95 static void submodule_cache_clear(struct submodule_cache
*cache
)
97 struct hashmap_iter iter
;
98 struct submodule_entry
*entry
;
100 if (!cache
->initialized
)
104 * We iterate over the name hash here to be symmetric with the
105 * allocation of struct submodule entries. Each is allocated by
106 * their .gitmodules blob sha1 and submodule name.
108 hashmap_for_each_entry(&cache
->for_name
, &iter
, entry
,
109 ent
/* member name */)
110 free_one_config(entry
);
112 hashmap_clear_and_free(&cache
->for_path
, struct submodule_entry
, ent
);
113 hashmap_clear_and_free(&cache
->for_name
, struct submodule_entry
, ent
);
114 cache
->initialized
= 0;
115 cache
->gitmodules_read
= 0;
118 void submodule_cache_free(struct submodule_cache
*cache
)
120 submodule_cache_clear(cache
);
124 static unsigned int hash_oid_string(const struct object_id
*oid
,
127 return memhash(oid
->hash
, the_hash_algo
->rawsz
) + strhash(string
);
130 static void cache_put_path(struct submodule_cache
*cache
,
131 struct submodule
*submodule
)
133 unsigned int hash
= hash_oid_string(&submodule
->gitmodules_oid
,
135 struct submodule_entry
*e
= xmalloc(sizeof(*e
));
136 hashmap_entry_init(&e
->ent
, hash
);
137 e
->config
= submodule
;
138 hashmap_put(&cache
->for_path
, &e
->ent
);
141 static void cache_remove_path(struct submodule_cache
*cache
,
142 struct submodule
*submodule
)
144 unsigned int hash
= hash_oid_string(&submodule
->gitmodules_oid
,
146 struct submodule_entry e
;
147 struct submodule_entry
*removed
;
148 hashmap_entry_init(&e
.ent
, hash
);
149 e
.config
= submodule
;
150 removed
= hashmap_remove_entry(&cache
->for_path
, &e
, ent
, NULL
);
154 static void cache_add(struct submodule_cache
*cache
,
155 struct submodule
*submodule
)
157 unsigned int hash
= hash_oid_string(&submodule
->gitmodules_oid
,
159 struct submodule_entry
*e
= xmalloc(sizeof(*e
));
160 hashmap_entry_init(&e
->ent
, hash
);
161 e
->config
= submodule
;
162 hashmap_add(&cache
->for_name
, &e
->ent
);
165 static const struct submodule
*cache_lookup_path(struct submodule_cache
*cache
,
166 const struct object_id
*gitmodules_oid
, const char *path
)
168 struct submodule_entry
*entry
;
169 unsigned int hash
= hash_oid_string(gitmodules_oid
, path
);
170 struct submodule_entry key
;
171 struct submodule key_config
;
173 oidcpy(&key_config
.gitmodules_oid
, gitmodules_oid
);
174 key_config
.path
= path
;
176 hashmap_entry_init(&key
.ent
, hash
);
177 key
.config
= &key_config
;
179 entry
= hashmap_get_entry(&cache
->for_path
, &key
, ent
, NULL
);
181 return entry
->config
;
185 static struct submodule
*cache_lookup_name(struct submodule_cache
*cache
,
186 const struct object_id
*gitmodules_oid
, const char *name
)
188 struct submodule_entry
*entry
;
189 unsigned int hash
= hash_oid_string(gitmodules_oid
, name
);
190 struct submodule_entry key
;
191 struct submodule key_config
;
193 oidcpy(&key_config
.gitmodules_oid
, gitmodules_oid
);
194 key_config
.name
= name
;
196 hashmap_entry_init(&key
.ent
, hash
);
197 key
.config
= &key_config
;
199 entry
= hashmap_get_entry(&cache
->for_name
, &key
, ent
, NULL
);
201 return entry
->config
;
205 int check_submodule_name(const char *name
)
207 /* Disallow empty names */
212 * Look for '..' as a path component. Check is_xplatform_dir_sep() as
213 * separators rather than is_dir_sep(), because we want the name rules
214 * to be consistent across platforms.
216 goto in_component
; /* always start inside component */
219 if (is_xplatform_dir_sep(c
)) {
221 if (name
[0] == '.' && name
[1] == '.' &&
222 (!name
[2] || is_xplatform_dir_sep(name
[2])))
230 static int name_and_item_from_var(const char *var
, struct strbuf
*name
,
233 const char *subsection
, *key
;
234 size_t subsection_len
;
236 parse
= parse_config_key(var
, "submodule", &subsection
,
237 &subsection_len
, &key
);
238 if (parse
< 0 || !subsection
)
241 strbuf_add(name
, subsection
, subsection_len
);
242 if (check_submodule_name(name
->buf
) < 0) {
243 warning(_("ignoring suspicious submodule name: %s"), name
->buf
);
244 strbuf_release(name
);
248 strbuf_addstr(item
, key
);
253 static struct submodule
*lookup_or_create_by_name(struct submodule_cache
*cache
,
254 const struct object_id
*gitmodules_oid
, const char *name
)
256 struct submodule
*submodule
;
257 struct strbuf name_buf
= STRBUF_INIT
;
259 submodule
= cache_lookup_name(cache
, gitmodules_oid
, name
);
263 submodule
= xmalloc(sizeof(*submodule
));
265 strbuf_addstr(&name_buf
, name
);
266 submodule
->name
= strbuf_detach(&name_buf
, NULL
);
268 submodule
->path
= NULL
;
269 submodule
->url
= NULL
;
270 submodule
->update_strategy
.type
= SM_UPDATE_UNSPECIFIED
;
271 submodule
->update_strategy
.command
= NULL
;
272 submodule
->fetch_recurse
= RECURSE_SUBMODULES_NONE
;
273 submodule
->ignore
= NULL
;
274 submodule
->branch
= NULL
;
275 submodule
->recommend_shallow
= -1;
277 oidcpy(&submodule
->gitmodules_oid
, gitmodules_oid
);
279 cache_add(cache
, submodule
);
284 static int parse_fetch_recurse(const char *opt
, const char *arg
,
287 switch (git_parse_maybe_bool(arg
)) {
289 return RECURSE_SUBMODULES_ON
;
291 return RECURSE_SUBMODULES_OFF
;
293 if (!strcmp(arg
, "on-demand"))
294 return RECURSE_SUBMODULES_ON_DEMAND
;
296 * Please update $__git_fetch_recurse_submodules in
297 * git-completion.bash when you add new options.
300 die("bad %s argument: %s", opt
, arg
);
302 return RECURSE_SUBMODULES_ERROR
;
306 int parse_submodule_fetchjobs(const char *var
, const char *value
)
308 int fetchjobs
= git_config_int(var
, value
);
310 die(_("negative values not allowed for submodule.fetchJobs"));
312 fetchjobs
= online_cpus();
316 int parse_fetch_recurse_submodules_arg(const char *opt
, const char *arg
)
318 return parse_fetch_recurse(opt
, arg
, 1);
321 int option_fetch_parse_recurse_submodules(const struct option
*opt
,
322 const char *arg
, int unset
)
332 *v
= RECURSE_SUBMODULES_OFF
;
335 *v
= parse_fetch_recurse_submodules_arg(opt
->long_name
, arg
);
337 *v
= RECURSE_SUBMODULES_ON
;
342 static int parse_update_recurse(const char *opt
, const char *arg
,
345 switch (git_parse_maybe_bool(arg
)) {
347 return RECURSE_SUBMODULES_ON
;
349 return RECURSE_SUBMODULES_OFF
;
352 die("bad %s argument: %s", opt
, arg
);
353 return RECURSE_SUBMODULES_ERROR
;
357 int parse_update_recurse_submodules_arg(const char *opt
, const char *arg
)
359 return parse_update_recurse(opt
, arg
, 1);
362 static int parse_push_recurse(const char *opt
, const char *arg
,
365 switch (git_parse_maybe_bool(arg
)) {
367 /* There's no simple "on" value when pushing */
369 die("bad %s argument: %s", opt
, arg
);
371 return RECURSE_SUBMODULES_ERROR
;
373 return RECURSE_SUBMODULES_OFF
;
375 if (!strcmp(arg
, "on-demand"))
376 return RECURSE_SUBMODULES_ON_DEMAND
;
377 else if (!strcmp(arg
, "check"))
378 return RECURSE_SUBMODULES_CHECK
;
379 else if (!strcmp(arg
, "only"))
380 return RECURSE_SUBMODULES_ONLY
;
382 * Please update $__git_push_recurse_submodules in
383 * git-completion.bash when you add new modes.
385 else if (die_on_error
)
386 die("bad %s argument: %s", opt
, arg
);
388 return RECURSE_SUBMODULES_ERROR
;
392 int parse_push_recurse_submodules_arg(const char *opt
, const char *arg
)
394 return parse_push_recurse(opt
, arg
, 1);
397 static void warn_multiple_config(const struct object_id
*treeish_name
,
398 const char *name
, const char *option
)
400 const char *commit_string
= "WORKTREE";
402 commit_string
= oid_to_hex(treeish_name
);
403 warning("%s:.gitmodules, multiple configurations found for "
404 "'submodule.%s.%s'. Skipping second one!",
405 commit_string
, name
, option
);
408 static void warn_command_line_option(const char *var
, const char *value
)
410 warning(_("ignoring '%s' which may be interpreted as"
411 " a command-line option: %s"), var
, value
);
414 struct parse_config_parameter
{
415 struct submodule_cache
*cache
;
416 const struct object_id
*treeish_name
;
417 const struct object_id
*gitmodules_oid
;
422 * Parse a config item from .gitmodules.
424 * This does not handle submodule-related configuration from the main
425 * config store (.git/config, etc). Callers are responsible for
426 * checking for overrides in the main config store when appropriate.
428 static int parse_config(const char *var
, const char *value
, void *data
)
430 struct parse_config_parameter
*me
= data
;
431 struct submodule
*submodule
;
432 struct strbuf name
= STRBUF_INIT
, item
= STRBUF_INIT
;
435 /* this also ensures that we only parse submodule entries */
436 if (!name_and_item_from_var(var
, &name
, &item
))
439 submodule
= lookup_or_create_by_name(me
->cache
,
443 if (!strcmp(item
.buf
, "path")) {
445 ret
= config_error_nonbool(var
);
446 else if (looks_like_command_line_option(value
))
447 warn_command_line_option(var
, value
);
448 else if (!me
->overwrite
&& submodule
->path
)
449 warn_multiple_config(me
->treeish_name
, submodule
->name
,
453 cache_remove_path(me
->cache
, submodule
);
454 free((void *) submodule
->path
);
455 submodule
->path
= xstrdup(value
);
456 cache_put_path(me
->cache
, submodule
);
458 } else if (!strcmp(item
.buf
, "fetchrecursesubmodules")) {
459 /* when parsing worktree configurations we can die early */
460 int die_on_error
= is_null_oid(me
->gitmodules_oid
);
461 if (!me
->overwrite
&&
462 submodule
->fetch_recurse
!= RECURSE_SUBMODULES_NONE
)
463 warn_multiple_config(me
->treeish_name
, submodule
->name
,
464 "fetchrecursesubmodules");
466 submodule
->fetch_recurse
= parse_fetch_recurse(
469 } else if (!strcmp(item
.buf
, "ignore")) {
471 ret
= config_error_nonbool(var
);
472 else if (!me
->overwrite
&& submodule
->ignore
)
473 warn_multiple_config(me
->treeish_name
, submodule
->name
,
475 else if (strcmp(value
, "untracked") &&
476 strcmp(value
, "dirty") &&
477 strcmp(value
, "all") &&
478 strcmp(value
, "none"))
479 warning("Invalid parameter '%s' for config option "
480 "'submodule.%s.ignore'", value
, name
.buf
);
482 free((void *) submodule
->ignore
);
483 submodule
->ignore
= xstrdup(value
);
485 } else if (!strcmp(item
.buf
, "url")) {
487 ret
= config_error_nonbool(var
);
488 } else if (looks_like_command_line_option(value
)) {
489 warn_command_line_option(var
, value
);
490 } else if (!me
->overwrite
&& submodule
->url
) {
491 warn_multiple_config(me
->treeish_name
, submodule
->name
,
494 free((void *) submodule
->url
);
495 submodule
->url
= xstrdup(value
);
497 } else if (!strcmp(item
.buf
, "update")) {
499 ret
= config_error_nonbool(var
);
500 else if (!me
->overwrite
&&
501 submodule
->update_strategy
.type
!= SM_UPDATE_UNSPECIFIED
)
502 warn_multiple_config(me
->treeish_name
, submodule
->name
,
504 else if (parse_submodule_update_strategy(value
,
505 &submodule
->update_strategy
) < 0 ||
506 submodule
->update_strategy
.type
== SM_UPDATE_COMMAND
)
507 die(_("invalid value for '%s'"), var
);
508 } else if (!strcmp(item
.buf
, "shallow")) {
509 if (!me
->overwrite
&& submodule
->recommend_shallow
!= -1)
510 warn_multiple_config(me
->treeish_name
, submodule
->name
,
513 submodule
->recommend_shallow
=
514 git_config_bool(var
, value
);
515 } else if (!strcmp(item
.buf
, "branch")) {
516 if (!me
->overwrite
&& submodule
->branch
)
517 warn_multiple_config(me
->treeish_name
, submodule
->name
,
520 free((void *)submodule
->branch
);
521 submodule
->branch
= xstrdup(value
);
525 strbuf_release(&name
);
526 strbuf_release(&item
);
531 static int gitmodule_oid_from_commit(const struct object_id
*treeish_name
,
532 struct object_id
*gitmodules_oid
,
537 if (is_null_oid(treeish_name
)) {
538 oidclr(gitmodules_oid
);
542 strbuf_addf(rev
, "%s:.gitmodules", oid_to_hex(treeish_name
));
543 if (repo_get_oid(the_repository
, rev
->buf
, gitmodules_oid
) >= 0)
549 /* This does a lookup of a submodule configuration by name or by path
550 * (key) with on-demand reading of the appropriate .gitmodules from
553 static const struct submodule
*config_from(struct submodule_cache
*cache
,
554 const struct object_id
*treeish_name
, const char *key
,
555 enum lookup_type lookup_type
)
557 struct strbuf rev
= STRBUF_INIT
;
558 unsigned long config_size
;
560 struct object_id oid
;
561 enum object_type type
;
562 const struct submodule
*submodule
= NULL
;
563 struct parse_config_parameter parameter
;
566 * If any parameter except the cache is a NULL pointer just
567 * return the first submodule. Can be used to check whether
568 * there are any submodules parsed.
570 if (!treeish_name
|| !key
) {
571 struct hashmap_iter iter
;
572 struct submodule_entry
*entry
;
574 entry
= hashmap_iter_first_entry(&cache
->for_name
, &iter
,
575 struct submodule_entry
,
576 ent
/* member name */);
579 return entry
->config
;
582 if (!gitmodule_oid_from_commit(treeish_name
, &oid
, &rev
))
585 switch (lookup_type
) {
587 submodule
= cache_lookup_name(cache
, &oid
, key
);
590 submodule
= cache_lookup_path(cache
, &oid
, key
);
596 config
= repo_read_object_file(the_repository
, &oid
, &type
,
598 if (!config
|| type
!= OBJ_BLOB
)
601 /* fill the submodule config into the cache */
602 parameter
.cache
= cache
;
603 parameter
.treeish_name
= treeish_name
;
604 parameter
.gitmodules_oid
= &oid
;
605 parameter
.overwrite
= 0;
606 git_config_from_mem(parse_config
, CONFIG_ORIGIN_SUBMODULE_BLOB
, rev
.buf
,
607 config
, config_size
, ¶meter
, NULL
);
608 strbuf_release(&rev
);
611 switch (lookup_type
) {
613 return cache_lookup_name(cache
, &oid
, key
);
615 return cache_lookup_path(cache
, &oid
, key
);
621 strbuf_release(&rev
);
626 static void submodule_cache_check_init(struct repository
*repo
)
628 if (repo
->submodule_cache
&& repo
->submodule_cache
->initialized
)
631 if (!repo
->submodule_cache
)
632 repo
->submodule_cache
= submodule_cache_alloc();
634 submodule_cache_init(repo
->submodule_cache
);
638 * Note: This function is private for a reason, the '.gitmodules' file should
639 * not be used as a mechanism to retrieve arbitrary configuration stored in
642 * Runs the provided config function on the '.gitmodules' file found in the
645 static void config_from_gitmodules(config_fn_t fn
, struct repository
*repo
, void *data
)
647 if (repo
->worktree
) {
648 struct git_config_source config_source
= {
649 0, .scope
= CONFIG_SCOPE_SUBMODULE
651 const struct config_options opts
= { 0 };
652 struct object_id oid
;
656 file
= repo_worktree_path(repo
, GITMODULES_FILE
);
657 if (file_exists(file
)) {
658 config_source
.file
= file
;
659 } else if (repo_get_oid(repo
, GITMODULES_INDEX
, &oid
) >= 0 ||
660 repo_get_oid(repo
, GITMODULES_HEAD
, &oid
) >= 0) {
661 config_source
.repo
= repo
;
662 config_source
.blob
= oidstr
= xstrdup(oid_to_hex(&oid
));
663 if (repo
!= the_repository
)
664 add_submodule_odb_by_path(repo
->objects
->odb
->path
);
669 config_with_options(fn
, data
, &config_source
, &opts
);
677 static int gitmodules_cb(const char *var
, const char *value
, void *data
)
679 struct repository
*repo
= data
;
680 struct parse_config_parameter parameter
;
682 parameter
.cache
= repo
->submodule_cache
;
683 parameter
.treeish_name
= NULL
;
684 parameter
.gitmodules_oid
= null_oid();
685 parameter
.overwrite
= 1;
687 return parse_config(var
, value
, ¶meter
);
690 void repo_read_gitmodules(struct repository
*repo
, int skip_if_read
)
692 submodule_cache_check_init(repo
);
694 if (repo
->submodule_cache
->gitmodules_read
&& skip_if_read
)
697 if (repo_read_index(repo
) < 0)
700 if (!is_gitmodules_unmerged(repo
->index
))
701 config_from_gitmodules(gitmodules_cb
, repo
, repo
);
703 repo
->submodule_cache
->gitmodules_read
= 1;
706 void gitmodules_config_oid(const struct object_id
*commit_oid
)
708 struct strbuf rev
= STRBUF_INIT
;
709 struct object_id oid
;
711 submodule_cache_check_init(the_repository
);
713 if (gitmodule_oid_from_commit(commit_oid
, &oid
, &rev
)) {
714 git_config_from_blob_oid(gitmodules_cb
, rev
.buf
,
715 the_repository
, &oid
, the_repository
);
717 strbuf_release(&rev
);
719 the_repository
->submodule_cache
->gitmodules_read
= 1;
722 const struct submodule
*submodule_from_name(struct repository
*r
,
723 const struct object_id
*treeish_name
,
726 repo_read_gitmodules(r
, 1);
727 return config_from(r
->submodule_cache
, treeish_name
, name
, lookup_name
);
730 const struct submodule
*submodule_from_path(struct repository
*r
,
731 const struct object_id
*treeish_name
,
734 repo_read_gitmodules(r
, 1);
735 return config_from(r
->submodule_cache
, treeish_name
, path
, lookup_path
);
739 * Used internally by submodules_of_tree(). Recurses into 'treeish_name'
740 * and appends submodule entries to 'out'. The submodule_cache expects
741 * a root-level treeish_name and paths, so keep track of these values
742 * with 'root_tree' and 'prefix'.
744 static void traverse_tree_submodules(struct repository
*r
,
745 const struct object_id
*root_tree
,
747 const struct object_id
*treeish_name
,
748 struct submodule_entry_list
*out
)
750 struct tree_desc tree
;
751 struct submodule_tree_entry
*st_entry
;
752 struct name_entry
*name_entry
;
753 char *tree_path
= NULL
;
755 name_entry
= xmalloc(sizeof(*name_entry
));
757 fill_tree_descriptor(r
, &tree
, treeish_name
);
758 while (tree_entry(&tree
, name_entry
)) {
761 mkpathdup("%s/%s", prefix
, name_entry
->path
);
763 tree_path
= xstrdup(name_entry
->path
);
765 if (S_ISGITLINK(name_entry
->mode
) &&
766 is_tree_submodule_active(r
, root_tree
, tree_path
)) {
767 ALLOC_GROW(out
->entries
, out
->entry_nr
+ 1,
769 st_entry
= &out
->entries
[out
->entry_nr
++];
771 st_entry
->name_entry
= xmalloc(sizeof(*st_entry
->name_entry
));
772 *st_entry
->name_entry
= *name_entry
;
773 st_entry
->submodule
=
774 submodule_from_path(r
, root_tree
, tree_path
);
775 st_entry
->repo
= xmalloc(sizeof(*st_entry
->repo
));
776 if (repo_submodule_init(st_entry
->repo
, r
, tree_path
,
778 FREE_AND_NULL(st_entry
->repo
);
780 } else if (S_ISDIR(name_entry
->mode
))
781 traverse_tree_submodules(r
, root_tree
, tree_path
,
782 &name_entry
->oid
, out
);
787 void submodules_of_tree(struct repository
*r
,
788 const struct object_id
*treeish_name
,
789 struct submodule_entry_list
*out
)
791 CALLOC_ARRAY(out
->entries
, 0);
793 out
->entry_alloc
= 0;
795 traverse_tree_submodules(r
, treeish_name
, NULL
, treeish_name
, out
);
798 void submodule_free(struct repository
*r
)
800 if (r
->submodule_cache
)
801 submodule_cache_clear(r
->submodule_cache
);
804 static int config_print_callback(const char *var
, const char *value
, void *cb_data
)
806 char *wanted_key
= cb_data
;
808 if (!strcmp(wanted_key
, var
))
809 printf("%s\n", value
);
814 int print_config_from_gitmodules(struct repository
*repo
, const char *key
)
819 ret
= git_config_parse_key(key
, &store_key
, NULL
);
821 return CONFIG_INVALID_KEY
;
823 config_from_gitmodules(config_print_callback
, repo
, store_key
);
829 int config_set_in_gitmodules_file_gently(const char *key
, const char *value
)
833 ret
= git_config_set_in_file_gently(GITMODULES_FILE
, key
, value
);
835 /* Maybe the user already did that, don't error out here */
836 warning(_("Could not update .gitmodules entry %s"), key
);
841 struct fetch_config
{
843 int *recurse_submodules
;
846 static int gitmodules_fetch_config(const char *var
, const char *value
, void *cb
)
848 struct fetch_config
*config
= cb
;
849 if (!strcmp(var
, "submodule.fetchjobs")) {
850 if (config
->max_children
)
851 *(config
->max_children
) =
852 parse_submodule_fetchjobs(var
, value
);
854 } else if (!strcmp(var
, "fetch.recursesubmodules")) {
855 if (config
->recurse_submodules
)
856 *(config
->recurse_submodules
) =
857 parse_fetch_recurse_submodules_arg(var
, value
);
864 void fetch_config_from_gitmodules(int *max_children
, int *recurse_submodules
)
866 struct fetch_config config
= {
867 .max_children
= max_children
,
868 .recurse_submodules
= recurse_submodules
870 config_from_gitmodules(gitmodules_fetch_config
, the_repository
, &config
);
873 static int gitmodules_update_clone_config(const char *var
, const char *value
,
877 if (!strcmp(var
, "submodule.fetchjobs"))
878 *max_jobs
= parse_submodule_fetchjobs(var
, value
);
882 void update_clone_config_from_gitmodules(int *max_jobs
)
884 config_from_gitmodules(gitmodules_update_clone_config
, the_repository
, &max_jobs
);