1 #include "git-compat-util.h"
3 #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-ll.h"
14 #include "parse-options.h"
15 #include "thread-utils.h"
16 #include "tree-walk.h"
19 * submodule cache lookup structure
20 * There is one shared set of 'struct submodule' entries which can be
21 * looked up by their sha1 blob id of the .gitmodules file and either
22 * using path or name as key.
23 * for_path stores submodule entries with path as key
24 * for_name stores submodule entries with name as key
26 struct submodule_cache
{
27 struct hashmap for_path
;
28 struct hashmap for_name
;
29 unsigned initialized
:1;
30 unsigned gitmodules_read
:1;
34 * thin wrapper struct needed to insert 'struct submodule' entries to
37 struct submodule_entry
{
38 struct hashmap_entry ent
;
39 struct submodule
*config
;
47 static int config_path_cmp(const void *cmp_data UNUSED
,
48 const struct hashmap_entry
*eptr
,
49 const struct hashmap_entry
*entry_or_key
,
50 const void *keydata UNUSED
)
52 const struct submodule_entry
*a
, *b
;
54 a
= container_of(eptr
, const struct submodule_entry
, ent
);
55 b
= container_of(entry_or_key
, const struct submodule_entry
, ent
);
57 return strcmp(a
->config
->path
, b
->config
->path
) ||
58 !oideq(&a
->config
->gitmodules_oid
, &b
->config
->gitmodules_oid
);
61 static int config_name_cmp(const void *cmp_data UNUSED
,
62 const struct hashmap_entry
*eptr
,
63 const struct hashmap_entry
*entry_or_key
,
64 const void *keydata UNUSED
)
66 const struct submodule_entry
*a
, *b
;
68 a
= container_of(eptr
, const struct submodule_entry
, ent
);
69 b
= container_of(entry_or_key
, const struct submodule_entry
, ent
);
71 return strcmp(a
->config
->name
, b
->config
->name
) ||
72 !oideq(&a
->config
->gitmodules_oid
, &b
->config
->gitmodules_oid
);
75 static struct submodule_cache
*submodule_cache_alloc(void)
77 return xcalloc(1, sizeof(struct submodule_cache
));
80 static void submodule_cache_init(struct submodule_cache
*cache
)
82 hashmap_init(&cache
->for_path
, config_path_cmp
, NULL
, 0);
83 hashmap_init(&cache
->for_name
, config_name_cmp
, NULL
, 0);
84 cache
->initialized
= 1;
87 static void free_one_config(struct submodule_entry
*entry
)
89 free((void *) entry
->config
->path
);
90 free((void *) entry
->config
->name
);
91 free((void *) entry
->config
->branch
);
92 free((void *) entry
->config
->update_strategy
.command
);
96 static void submodule_cache_clear(struct submodule_cache
*cache
)
98 struct hashmap_iter iter
;
99 struct submodule_entry
*entry
;
101 if (!cache
->initialized
)
105 * We iterate over the name hash here to be symmetric with the
106 * allocation of struct submodule entries. Each is allocated by
107 * their .gitmodules blob sha1 and submodule name.
109 hashmap_for_each_entry(&cache
->for_name
, &iter
, entry
,
110 ent
/* member name */)
111 free_one_config(entry
);
113 hashmap_clear_and_free(&cache
->for_path
, struct submodule_entry
, ent
);
114 hashmap_clear_and_free(&cache
->for_name
, struct submodule_entry
, ent
);
115 cache
->initialized
= 0;
116 cache
->gitmodules_read
= 0;
119 void submodule_cache_free(struct submodule_cache
*cache
)
121 submodule_cache_clear(cache
);
125 static unsigned int hash_oid_string(const struct object_id
*oid
,
128 return memhash(oid
->hash
, the_hash_algo
->rawsz
) + strhash(string
);
131 static void cache_put_path(struct submodule_cache
*cache
,
132 struct submodule
*submodule
)
134 unsigned int hash
= hash_oid_string(&submodule
->gitmodules_oid
,
136 struct submodule_entry
*e
= xmalloc(sizeof(*e
));
137 hashmap_entry_init(&e
->ent
, hash
);
138 e
->config
= submodule
;
139 hashmap_put(&cache
->for_path
, &e
->ent
);
142 static void cache_remove_path(struct submodule_cache
*cache
,
143 struct submodule
*submodule
)
145 unsigned int hash
= hash_oid_string(&submodule
->gitmodules_oid
,
147 struct submodule_entry e
;
148 struct submodule_entry
*removed
;
149 hashmap_entry_init(&e
.ent
, hash
);
150 e
.config
= submodule
;
151 removed
= hashmap_remove_entry(&cache
->for_path
, &e
, ent
, NULL
);
155 static void cache_add(struct submodule_cache
*cache
,
156 struct submodule
*submodule
)
158 unsigned int hash
= hash_oid_string(&submodule
->gitmodules_oid
,
160 struct submodule_entry
*e
= xmalloc(sizeof(*e
));
161 hashmap_entry_init(&e
->ent
, hash
);
162 e
->config
= submodule
;
163 hashmap_add(&cache
->for_name
, &e
->ent
);
166 static const struct submodule
*cache_lookup_path(struct submodule_cache
*cache
,
167 const struct object_id
*gitmodules_oid
, const char *path
)
169 struct submodule_entry
*entry
;
170 unsigned int hash
= hash_oid_string(gitmodules_oid
, path
);
171 struct submodule_entry key
;
172 struct submodule key_config
;
174 oidcpy(&key_config
.gitmodules_oid
, gitmodules_oid
);
175 key_config
.path
= path
;
177 hashmap_entry_init(&key
.ent
, hash
);
178 key
.config
= &key_config
;
180 entry
= hashmap_get_entry(&cache
->for_path
, &key
, ent
, NULL
);
182 return entry
->config
;
186 static struct submodule
*cache_lookup_name(struct submodule_cache
*cache
,
187 const struct object_id
*gitmodules_oid
, const char *name
)
189 struct submodule_entry
*entry
;
190 unsigned int hash
= hash_oid_string(gitmodules_oid
, name
);
191 struct submodule_entry key
;
192 struct submodule key_config
;
194 oidcpy(&key_config
.gitmodules_oid
, gitmodules_oid
);
195 key_config
.name
= name
;
197 hashmap_entry_init(&key
.ent
, hash
);
198 key
.config
= &key_config
;
200 entry
= hashmap_get_entry(&cache
->for_name
, &key
, ent
, NULL
);
202 return entry
->config
;
206 int check_submodule_name(const char *name
)
208 /* Disallow empty names */
213 * Look for '..' as a path component. Check is_xplatform_dir_sep() as
214 * separators rather than is_dir_sep(), because we want the name rules
215 * to be consistent across platforms.
217 goto in_component
; /* always start inside component */
220 if (is_xplatform_dir_sep(c
)) {
222 if (name
[0] == '.' && name
[1] == '.' &&
223 (!name
[2] || is_xplatform_dir_sep(name
[2])))
231 static int name_and_item_from_var(const char *var
, struct strbuf
*name
,
234 const char *subsection
, *key
;
235 size_t subsection_len
;
237 parse
= parse_config_key(var
, "submodule", &subsection
,
238 &subsection_len
, &key
);
239 if (parse
< 0 || !subsection
)
242 strbuf_add(name
, subsection
, subsection_len
);
243 if (check_submodule_name(name
->buf
) < 0) {
244 warning(_("ignoring suspicious submodule name: %s"), name
->buf
);
245 strbuf_release(name
);
249 strbuf_addstr(item
, key
);
254 static struct submodule
*lookup_or_create_by_name(struct submodule_cache
*cache
,
255 const struct object_id
*gitmodules_oid
, const char *name
)
257 struct submodule
*submodule
;
258 struct strbuf name_buf
= STRBUF_INIT
;
260 submodule
= cache_lookup_name(cache
, gitmodules_oid
, name
);
264 submodule
= xmalloc(sizeof(*submodule
));
266 strbuf_addstr(&name_buf
, name
);
267 submodule
->name
= strbuf_detach(&name_buf
, NULL
);
269 submodule
->path
= NULL
;
270 submodule
->url
= NULL
;
271 submodule
->update_strategy
.type
= SM_UPDATE_UNSPECIFIED
;
272 submodule
->update_strategy
.command
= NULL
;
273 submodule
->fetch_recurse
= RECURSE_SUBMODULES_NONE
;
274 submodule
->ignore
= NULL
;
275 submodule
->branch
= NULL
;
276 submodule
->recommend_shallow
= -1;
278 oidcpy(&submodule
->gitmodules_oid
, gitmodules_oid
);
280 cache_add(cache
, submodule
);
285 static int parse_fetch_recurse(const char *opt
, const char *arg
,
288 switch (git_parse_maybe_bool(arg
)) {
290 return RECURSE_SUBMODULES_ON
;
292 return RECURSE_SUBMODULES_OFF
;
294 if (!strcmp(arg
, "on-demand"))
295 return RECURSE_SUBMODULES_ON_DEMAND
;
297 * Please update $__git_fetch_recurse_submodules in
298 * git-completion.bash when you add new options.
301 die("bad %s argument: %s", opt
, arg
);
303 return RECURSE_SUBMODULES_ERROR
;
307 int parse_submodule_fetchjobs(const char *var
, const char *value
,
308 const struct key_value_info
*kvi
)
310 int fetchjobs
= git_config_int(var
, value
, kvi
);
312 die(_("negative values not allowed for submodule.fetchJobs"));
314 fetchjobs
= online_cpus();
318 int parse_fetch_recurse_submodules_arg(const char *opt
, const char *arg
)
320 return parse_fetch_recurse(opt
, arg
, 1);
323 int option_fetch_parse_recurse_submodules(const struct option
*opt
,
324 const char *arg
, int unset
)
334 *v
= RECURSE_SUBMODULES_OFF
;
337 *v
= parse_fetch_recurse_submodules_arg(opt
->long_name
, arg
);
339 *v
= RECURSE_SUBMODULES_ON
;
344 static int parse_update_recurse(const char *opt
, const char *arg
,
347 switch (git_parse_maybe_bool(arg
)) {
349 return RECURSE_SUBMODULES_ON
;
351 return RECURSE_SUBMODULES_OFF
;
354 die("bad %s argument: %s", opt
, arg
);
355 return RECURSE_SUBMODULES_ERROR
;
359 int parse_update_recurse_submodules_arg(const char *opt
, const char *arg
)
361 return parse_update_recurse(opt
, arg
, 1);
364 static int parse_push_recurse(const char *opt
, const char *arg
,
367 switch (git_parse_maybe_bool(arg
)) {
369 /* There's no simple "on" value when pushing */
371 die("bad %s argument: %s", opt
, arg
);
373 return RECURSE_SUBMODULES_ERROR
;
375 return RECURSE_SUBMODULES_OFF
;
377 if (!strcmp(arg
, "on-demand"))
378 return RECURSE_SUBMODULES_ON_DEMAND
;
379 else if (!strcmp(arg
, "check"))
380 return RECURSE_SUBMODULES_CHECK
;
381 else if (!strcmp(arg
, "only"))
382 return RECURSE_SUBMODULES_ONLY
;
384 * Please update $__git_push_recurse_submodules in
385 * git-completion.bash when you add new modes.
387 else if (die_on_error
)
388 die("bad %s argument: %s", opt
, arg
);
390 return RECURSE_SUBMODULES_ERROR
;
394 int parse_push_recurse_submodules_arg(const char *opt
, const char *arg
)
396 return parse_push_recurse(opt
, arg
, 1);
399 static void warn_multiple_config(const struct object_id
*treeish_name
,
400 const char *name
, const char *option
)
402 const char *commit_string
= "WORKTREE";
404 commit_string
= oid_to_hex(treeish_name
);
405 warning("%s:.gitmodules, multiple configurations found for "
406 "'submodule.%s.%s'. Skipping second one!",
407 commit_string
, name
, option
);
410 static void warn_command_line_option(const char *var
, const char *value
)
412 warning(_("ignoring '%s' which may be interpreted as"
413 " a command-line option: %s"), var
, value
);
416 struct parse_config_parameter
{
417 struct submodule_cache
*cache
;
418 const struct object_id
*treeish_name
;
419 const struct object_id
*gitmodules_oid
;
424 * Parse a config item from .gitmodules.
426 * This does not handle submodule-related configuration from the main
427 * config store (.git/config, etc). Callers are responsible for
428 * checking for overrides in the main config store when appropriate.
430 static int parse_config(const char *var
, const char *value
,
431 const struct config_context
*ctx UNUSED
, void *data
)
433 struct parse_config_parameter
*me
= data
;
434 struct submodule
*submodule
;
435 struct strbuf name
= STRBUF_INIT
, item
= STRBUF_INIT
;
438 /* this also ensures that we only parse submodule entries */
439 if (!name_and_item_from_var(var
, &name
, &item
))
442 submodule
= lookup_or_create_by_name(me
->cache
,
446 if (!strcmp(item
.buf
, "path")) {
448 ret
= config_error_nonbool(var
);
449 else if (looks_like_command_line_option(value
))
450 warn_command_line_option(var
, value
);
451 else if (!me
->overwrite
&& submodule
->path
)
452 warn_multiple_config(me
->treeish_name
, submodule
->name
,
456 cache_remove_path(me
->cache
, submodule
);
457 free((void *) submodule
->path
);
458 submodule
->path
= xstrdup(value
);
459 cache_put_path(me
->cache
, submodule
);
461 } else if (!strcmp(item
.buf
, "fetchrecursesubmodules")) {
462 /* when parsing worktree configurations we can die early */
463 int die_on_error
= is_null_oid(me
->gitmodules_oid
);
464 if (!me
->overwrite
&&
465 submodule
->fetch_recurse
!= RECURSE_SUBMODULES_NONE
)
466 warn_multiple_config(me
->treeish_name
, submodule
->name
,
467 "fetchrecursesubmodules");
469 submodule
->fetch_recurse
= parse_fetch_recurse(
472 } else if (!strcmp(item
.buf
, "ignore")) {
474 ret
= config_error_nonbool(var
);
475 else if (!me
->overwrite
&& submodule
->ignore
)
476 warn_multiple_config(me
->treeish_name
, submodule
->name
,
478 else if (strcmp(value
, "untracked") &&
479 strcmp(value
, "dirty") &&
480 strcmp(value
, "all") &&
481 strcmp(value
, "none"))
482 warning("Invalid parameter '%s' for config option "
483 "'submodule.%s.ignore'", value
, name
.buf
);
485 free((void *) submodule
->ignore
);
486 submodule
->ignore
= xstrdup(value
);
488 } else if (!strcmp(item
.buf
, "url")) {
490 ret
= config_error_nonbool(var
);
491 } else if (looks_like_command_line_option(value
)) {
492 warn_command_line_option(var
, value
);
493 } else if (!me
->overwrite
&& submodule
->url
) {
494 warn_multiple_config(me
->treeish_name
, submodule
->name
,
497 free((void *) submodule
->url
);
498 submodule
->url
= xstrdup(value
);
500 } else if (!strcmp(item
.buf
, "update")) {
502 ret
= config_error_nonbool(var
);
503 else if (!me
->overwrite
&&
504 submodule
->update_strategy
.type
!= SM_UPDATE_UNSPECIFIED
)
505 warn_multiple_config(me
->treeish_name
, submodule
->name
,
507 else if (parse_submodule_update_strategy(value
,
508 &submodule
->update_strategy
) < 0 ||
509 submodule
->update_strategy
.type
== SM_UPDATE_COMMAND
)
510 die(_("invalid value for '%s'"), var
);
511 } else if (!strcmp(item
.buf
, "shallow")) {
512 if (!me
->overwrite
&& submodule
->recommend_shallow
!= -1)
513 warn_multiple_config(me
->treeish_name
, submodule
->name
,
516 submodule
->recommend_shallow
=
517 git_config_bool(var
, value
);
518 } else if (!strcmp(item
.buf
, "branch")) {
520 ret
= config_error_nonbool(var
);
521 else if (!me
->overwrite
&& submodule
->branch
)
522 warn_multiple_config(me
->treeish_name
, submodule
->name
,
525 free((void *)submodule
->branch
);
526 submodule
->branch
= xstrdup(value
);
530 strbuf_release(&name
);
531 strbuf_release(&item
);
536 static int gitmodule_oid_from_commit(const struct object_id
*treeish_name
,
537 struct object_id
*gitmodules_oid
,
542 if (is_null_oid(treeish_name
)) {
543 oidclr(gitmodules_oid
);
547 strbuf_addf(rev
, "%s:.gitmodules", oid_to_hex(treeish_name
));
548 if (repo_get_oid(the_repository
, rev
->buf
, gitmodules_oid
) >= 0)
554 /* This does a lookup of a submodule configuration by name or by path
555 * (key) with on-demand reading of the appropriate .gitmodules from
558 static const struct submodule
*config_from(struct submodule_cache
*cache
,
559 const struct object_id
*treeish_name
, const char *key
,
560 enum lookup_type lookup_type
)
562 struct strbuf rev
= STRBUF_INIT
;
563 unsigned long config_size
;
565 struct object_id oid
;
566 enum object_type type
;
567 const struct submodule
*submodule
= NULL
;
568 struct parse_config_parameter parameter
;
571 * If any parameter except the cache is a NULL pointer just
572 * return the first submodule. Can be used to check whether
573 * there are any submodules parsed.
575 if (!treeish_name
|| !key
) {
576 struct hashmap_iter iter
;
577 struct submodule_entry
*entry
;
579 entry
= hashmap_iter_first_entry(&cache
->for_name
, &iter
,
580 struct submodule_entry
,
581 ent
/* member name */);
584 return entry
->config
;
587 if (!gitmodule_oid_from_commit(treeish_name
, &oid
, &rev
))
590 switch (lookup_type
) {
592 submodule
= cache_lookup_name(cache
, &oid
, key
);
595 submodule
= cache_lookup_path(cache
, &oid
, key
);
601 config
= repo_read_object_file(the_repository
, &oid
, &type
,
603 if (!config
|| type
!= OBJ_BLOB
)
606 /* fill the submodule config into the cache */
607 parameter
.cache
= cache
;
608 parameter
.treeish_name
= treeish_name
;
609 parameter
.gitmodules_oid
= &oid
;
610 parameter
.overwrite
= 0;
611 git_config_from_mem(parse_config
, CONFIG_ORIGIN_SUBMODULE_BLOB
, rev
.buf
,
612 config
, config_size
, ¶meter
, CONFIG_SCOPE_UNKNOWN
, NULL
);
613 strbuf_release(&rev
);
616 switch (lookup_type
) {
618 return cache_lookup_name(cache
, &oid
, key
);
620 return cache_lookup_path(cache
, &oid
, key
);
626 strbuf_release(&rev
);
631 static void submodule_cache_check_init(struct repository
*repo
)
633 if (repo
->submodule_cache
&& repo
->submodule_cache
->initialized
)
636 if (!repo
->submodule_cache
)
637 repo
->submodule_cache
= submodule_cache_alloc();
639 submodule_cache_init(repo
->submodule_cache
);
643 * Note: This function is private for a reason, the '.gitmodules' file should
644 * not be used as a mechanism to retrieve arbitrary configuration stored in
647 * Runs the provided config function on the '.gitmodules' file found in the
650 static void config_from_gitmodules(config_fn_t fn
, struct repository
*repo
, void *data
)
652 if (repo
->worktree
) {
653 struct git_config_source config_source
= {
654 0, .scope
= CONFIG_SCOPE_SUBMODULE
656 const struct config_options opts
= { 0 };
657 struct object_id oid
;
661 file
= repo_worktree_path(repo
, GITMODULES_FILE
);
662 if (file_exists(file
)) {
663 config_source
.file
= file
;
664 } else if (repo_get_oid(repo
, GITMODULES_INDEX
, &oid
) >= 0 ||
665 repo_get_oid(repo
, GITMODULES_HEAD
, &oid
) >= 0) {
666 config_source
.blob
= oidstr
= xstrdup(oid_to_hex(&oid
));
667 if (repo
!= the_repository
)
668 add_submodule_odb_by_path(repo
->objects
->odb
->path
);
673 config_with_options(fn
, data
, &config_source
, repo
, &opts
);
681 static int gitmodules_cb(const char *var
, const char *value
,
682 const struct config_context
*ctx
, void *data
)
684 struct repository
*repo
= data
;
685 struct parse_config_parameter parameter
;
687 parameter
.cache
= repo
->submodule_cache
;
688 parameter
.treeish_name
= NULL
;
689 parameter
.gitmodules_oid
= null_oid();
690 parameter
.overwrite
= 1;
692 return parse_config(var
, value
, ctx
, ¶meter
);
695 void repo_read_gitmodules(struct repository
*repo
, int skip_if_read
)
697 submodule_cache_check_init(repo
);
699 if (repo
->submodule_cache
->gitmodules_read
&& skip_if_read
)
702 if (repo_read_index(repo
) < 0)
705 if (!is_gitmodules_unmerged(repo
->index
))
706 config_from_gitmodules(gitmodules_cb
, repo
, repo
);
708 repo
->submodule_cache
->gitmodules_read
= 1;
711 void gitmodules_config_oid(const struct object_id
*commit_oid
)
713 struct strbuf rev
= STRBUF_INIT
;
714 struct object_id oid
;
716 submodule_cache_check_init(the_repository
);
718 if (gitmodule_oid_from_commit(commit_oid
, &oid
, &rev
)) {
719 git_config_from_blob_oid(gitmodules_cb
, rev
.buf
,
720 the_repository
, &oid
, the_repository
,
721 CONFIG_SCOPE_UNKNOWN
);
723 strbuf_release(&rev
);
725 the_repository
->submodule_cache
->gitmodules_read
= 1;
728 const struct submodule
*submodule_from_name(struct repository
*r
,
729 const struct object_id
*treeish_name
,
732 repo_read_gitmodules(r
, 1);
733 return config_from(r
->submodule_cache
, treeish_name
, name
, lookup_name
);
736 const struct submodule
*submodule_from_path(struct repository
*r
,
737 const struct object_id
*treeish_name
,
740 repo_read_gitmodules(r
, 1);
741 return config_from(r
->submodule_cache
, treeish_name
, path
, lookup_path
);
745 * Used internally by submodules_of_tree(). Recurses into 'treeish_name'
746 * and appends submodule entries to 'out'. The submodule_cache expects
747 * a root-level treeish_name and paths, so keep track of these values
748 * with 'root_tree' and 'prefix'.
750 static void traverse_tree_submodules(struct repository
*r
,
751 const struct object_id
*root_tree
,
753 const struct object_id
*treeish_name
,
754 struct submodule_entry_list
*out
)
756 struct tree_desc tree
;
757 struct submodule_tree_entry
*st_entry
;
758 struct name_entry
*name_entry
;
759 char *tree_path
= NULL
;
761 name_entry
= xmalloc(sizeof(*name_entry
));
763 fill_tree_descriptor(r
, &tree
, treeish_name
);
764 while (tree_entry(&tree
, name_entry
)) {
767 mkpathdup("%s/%s", prefix
, name_entry
->path
);
769 tree_path
= xstrdup(name_entry
->path
);
771 if (S_ISGITLINK(name_entry
->mode
) &&
772 is_tree_submodule_active(r
, root_tree
, tree_path
)) {
773 ALLOC_GROW(out
->entries
, out
->entry_nr
+ 1,
775 st_entry
= &out
->entries
[out
->entry_nr
++];
777 st_entry
->name_entry
= xmalloc(sizeof(*st_entry
->name_entry
));
778 *st_entry
->name_entry
= *name_entry
;
779 st_entry
->submodule
=
780 submodule_from_path(r
, root_tree
, tree_path
);
781 st_entry
->repo
= xmalloc(sizeof(*st_entry
->repo
));
782 if (repo_submodule_init(st_entry
->repo
, r
, tree_path
,
784 FREE_AND_NULL(st_entry
->repo
);
786 } else if (S_ISDIR(name_entry
->mode
))
787 traverse_tree_submodules(r
, root_tree
, tree_path
,
788 &name_entry
->oid
, out
);
793 void submodules_of_tree(struct repository
*r
,
794 const struct object_id
*treeish_name
,
795 struct submodule_entry_list
*out
)
797 CALLOC_ARRAY(out
->entries
, 0);
799 out
->entry_alloc
= 0;
801 traverse_tree_submodules(r
, treeish_name
, NULL
, treeish_name
, out
);
804 void submodule_free(struct repository
*r
)
806 if (r
->submodule_cache
)
807 submodule_cache_clear(r
->submodule_cache
);
810 static int config_print_callback(const char *var
, const char *value
,
811 const struct config_context
*ctx UNUSED
,
814 char *wanted_key
= cb_data
;
816 if (!strcmp(wanted_key
, var
))
817 printf("%s\n", value
);
822 int print_config_from_gitmodules(struct repository
*repo
, const char *key
)
827 ret
= git_config_parse_key(key
, &store_key
, NULL
);
829 return CONFIG_INVALID_KEY
;
831 config_from_gitmodules(config_print_callback
, repo
, store_key
);
837 int config_set_in_gitmodules_file_gently(const char *key
, const char *value
)
841 ret
= git_config_set_in_file_gently(GITMODULES_FILE
, key
, value
);
843 /* Maybe the user already did that, don't error out here */
844 warning(_("Could not update .gitmodules entry %s"), key
);
849 struct fetch_config
{
851 int *recurse_submodules
;
854 static int gitmodules_fetch_config(const char *var
, const char *value
,
855 const struct config_context
*ctx
,
858 struct fetch_config
*config
= cb
;
859 if (!strcmp(var
, "submodule.fetchjobs")) {
860 if (config
->max_children
)
861 *(config
->max_children
) =
862 parse_submodule_fetchjobs(var
, value
, ctx
->kvi
);
864 } else if (!strcmp(var
, "fetch.recursesubmodules")) {
865 if (config
->recurse_submodules
)
866 *(config
->recurse_submodules
) =
867 parse_fetch_recurse_submodules_arg(var
, value
);
874 void fetch_config_from_gitmodules(int *max_children
, int *recurse_submodules
)
876 struct fetch_config config
= {
877 .max_children
= max_children
,
878 .recurse_submodules
= recurse_submodules
880 config_from_gitmodules(gitmodules_fetch_config
, the_repository
, &config
);
883 static int gitmodules_update_clone_config(const char *var
, const char *value
,
884 const struct config_context
*ctx
,
888 if (!strcmp(var
, "submodule.fetchjobs"))
889 *max_jobs
= parse_submodule_fetchjobs(var
, value
, ctx
->kvi
);
893 void update_clone_config_from_gitmodules(int *max_jobs
)
895 config_from_gitmodules(gitmodules_update_clone_config
, the_repository
, &max_jobs
);