blob: 28a8ca6bf46845906cb4bc2071a594a383eefc72 [file] [log] [blame]
Heiko Voigt959b5452015-08-17 17:21:57 -07001#ifndef SUBMODULE_CONFIG_CACHE_H
2#define SUBMODULE_CONFIG_CACHE_H
3
brian m. carlson34caab02018-05-02 00:25:42 +00004#include "cache.h"
Antonio Ospitead136372018-06-26 12:47:05 +02005#include "config.h"
Heiko Voigt959b5452015-08-17 17:21:57 -07006#include "hashmap.h"
Stefan Bellerea2fa5a2016-02-29 18:07:11 -08007#include "submodule.h"
Heiko Voigt959b5452015-08-17 17:21:57 -07008#include "strbuf.h"
Glen Choo961b1302022-01-28 16:04:45 -08009#include "tree-walk.h"
Heiko Voigt959b5452015-08-17 17:21:57 -070010
Heba Walyd95a77d2019-11-17 21:04:58 +000011/**
12 * The submodule config cache API allows to read submodule
13 * configurations/information from specified revisions. Internally
14 * information is lazily read into a cache that is used to avoid
15 * unnecessary parsing of the same .gitmodules files. Lookups can be done by
16 * submodule path or name.
17 *
18 * Usage
19 * -----
20 *
21 * The caller can look up information about submodules by using the
22 * `submodule_from_path()` or `submodule_from_name()` functions. They return
23 * a `struct submodule` which contains the values. The API automatically
24 * initializes and allocates the needed infrastructure on-demand. If the
25 * caller does only want to lookup values from revisions the initialization
26 * can be skipped.
27 *
28 * If the internal cache might grow too big or when the caller is done with
29 * the API, all internally cached values can be freed with submodule_free().
30 *
31 */
32
Heiko Voigt959b5452015-08-17 17:21:57 -070033/*
34 * Submodule entry containing the information about a certain submodule
Heba Walyd95a77d2019-11-17 21:04:58 +000035 * in a certain revision. It is returned by the lookup functions.
Heiko Voigt959b5452015-08-17 17:21:57 -070036 */
37struct submodule {
38 const char *path;
39 const char *name;
40 const char *url;
Philippe Blain465b30a2022-04-04 17:10:11 +000041 enum submodule_recurse_mode fetch_recurse;
Heiko Voigt959b5452015-08-17 17:21:57 -070042 const char *ignore;
Stefan Bellerb5944f32016-07-28 17:44:07 -070043 const char *branch;
Stefan Bellerea2fa5a2016-02-29 18:07:11 -080044 struct submodule_update_strategy update_strategy;
brian m. carlson34caab02018-05-02 00:25:42 +000045 /* the object id of the responsible .gitmodules file */
46 struct object_id gitmodules_oid;
Stefan Beller37f52e92016-05-26 14:59:42 -070047 int recommend_shallow;
Heiko Voigt959b5452015-08-17 17:21:57 -070048};
Brandon Williamsbf12fcd2017-06-22 11:43:44 -070049struct submodule_cache;
50struct repository;
51
Denton Liu55454422019-04-29 04:28:14 -040052void submodule_cache_free(struct submodule_cache *cache);
Brandon Williamsbf12fcd2017-06-22 11:43:44 -070053
Denton Liu55454422019-04-29 04:28:14 -040054int parse_submodule_fetchjobs(const char *var, const char *value);
55int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg);
Stefan Beller886dc152017-06-23 12:13:00 -070056struct option;
Denton Liu55454422019-04-29 04:28:14 -040057int option_fetch_parse_recurse_submodules(const struct option *opt,
Denton Liuad6dad02019-04-29 04:28:23 -040058 const char *arg, int unset);
Denton Liu55454422019-04-29 04:28:14 -040059int parse_update_recurse_submodules_arg(const char *opt, const char *arg);
60int parse_push_recurse_submodules_arg(const char *opt, const char *arg);
Matheus Tavaresd7992422020-01-15 23:39:55 -030061void repo_read_gitmodules(struct repository *repo, int skip_if_read);
Denton Liu55454422019-04-29 04:28:14 -040062void gitmodules_config_oid(const struct object_id *commit_oid);
Heba Walyd95a77d2019-11-17 21:04:58 +000063
64/**
65 * Same as submodule_from_path but lookup by name.
66 */
Stefan Beller3b8fb392018-03-28 15:35:29 -070067const struct submodule *submodule_from_name(struct repository *r,
68 const struct object_id *commit_or_tree,
69 const char *name);
Heba Walyd95a77d2019-11-17 21:04:58 +000070
71/**
72 * Given a tree-ish in the superproject and a path, return the submodule that
73 * is bound at the path in the named tree.
74 */
Stefan Beller3b8fb392018-03-28 15:35:29 -070075const struct submodule *submodule_from_path(struct repository *r,
76 const struct object_id *commit_or_tree,
77 const char *path);
Heba Walyd95a77d2019-11-17 21:04:58 +000078
79/**
80 * Use these to free the internally cached values.
81 */
Stefan Bellerf793b892018-03-28 15:35:28 -070082void submodule_free(struct repository *r);
Heba Walyd95a77d2019-11-17 21:04:58 +000083
Antonio Ospitebcbc7802018-10-05 15:05:52 +020084int print_config_from_gitmodules(struct repository *repo, const char *key);
Antonio Ospite45f5ef32018-10-05 15:05:53 +020085int config_set_in_gitmodules_file_gently(const char *key, const char *value);
Heiko Voigt959b5452015-08-17 17:21:57 -070086
Jeff King0383bbb2018-04-30 03:25:25 -040087/*
88 * Returns 0 if the name is syntactically acceptable as a submodule "name"
89 * (e.g., that may be found in the subsection of a .gitmodules file) and -1
90 * otherwise.
91 */
92int check_submodule_name(const char *name);
93
Antonio Ospitead136372018-06-26 12:47:05 +020094/*
Antonio Ospite588929d2018-06-26 12:47:08 +020095 * Note: these helper functions exist solely to maintain backward
96 * compatibility with 'fetch' and 'update_clone' storing configuration in
97 * '.gitmodules'.
Antonio Ospitead136372018-06-26 12:47:05 +020098 *
Antonio Ospite588929d2018-06-26 12:47:08 +020099 * New helpers to retrieve arbitrary configuration from the '.gitmodules' file
100 * should NOT be added.
Antonio Ospitead136372018-06-26 12:47:05 +0200101 */
Denton Liu55454422019-04-29 04:28:14 -0400102void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules);
103void update_clone_config_from_gitmodules(int *max_jobs);
Antonio Ospite71a69532018-06-26 12:47:06 +0200104
Glen Choo961b1302022-01-28 16:04:45 -0800105/*
106 * Submodule entry that contains relevant information about a
107 * submodule in a tree.
108 */
109struct submodule_tree_entry {
110 /* The submodule's tree entry. */
111 struct name_entry *name_entry;
112 /*
113 * A struct repository corresponding to the submodule. May be
114 * NULL if the submodule has not been updated.
115 */
116 struct repository *repo;
117 /*
118 * A struct submodule containing the submodule config in the
119 * tree's .gitmodules.
120 */
121 const struct submodule *submodule;
122};
123
124struct submodule_entry_list {
125 struct submodule_tree_entry *entries;
126 int entry_nr;
127 int entry_alloc;
128};
129
130/**
131 * Given a treeish, return all submodules in the tree and its subtrees,
132 * but excluding nested submodules. Callers that require nested
133 * submodules are expected to recurse into the submodules themselves.
134 */
135void submodules_of_tree(struct repository *r,
136 const struct object_id *treeish_name,
137 struct submodule_entry_list *ret);
Heiko Voigt959b5452015-08-17 17:21:57 -0700138#endif /* SUBMODULE_CONFIG_H */