blob: f55d4e3b61a59bd50d2a9b4833b575b7844b2232 [file] [log] [blame]
Heiko Voigt959b5452015-08-17 17:21:57 -07001#ifndef SUBMODULE_CONFIG_CACHE_H
2#define SUBMODULE_CONFIG_CACHE_H
3
Antonio Ospitead136372018-06-26 12:47:05 +02004#include "config.h"
Stefan Bellerea2fa5a2016-02-29 18:07:11 -08005#include "submodule.h"
Glen Choo961b1302022-01-28 16:04:45 -08006#include "tree-walk.h"
Heiko Voigt959b5452015-08-17 17:21:57 -07007
Heba Walyd95a77d2019-11-17 21:04:58 +00008/**
9 * The submodule config cache API allows to read submodule
10 * configurations/information from specified revisions. Internally
11 * information is lazily read into a cache that is used to avoid
12 * unnecessary parsing of the same .gitmodules files. Lookups can be done by
13 * submodule path or name.
14 *
15 * Usage
16 * -----
17 *
18 * The caller can look up information about submodules by using the
19 * `submodule_from_path()` or `submodule_from_name()` functions. They return
20 * a `struct submodule` which contains the values. The API automatically
21 * initializes and allocates the needed infrastructure on-demand. If the
22 * caller does only want to lookup values from revisions the initialization
23 * can be skipped.
24 *
25 * If the internal cache might grow too big or when the caller is done with
26 * the API, all internally cached values can be freed with submodule_free().
27 *
28 */
29
Heiko Voigt959b5452015-08-17 17:21:57 -070030/*
31 * Submodule entry containing the information about a certain submodule
Heba Walyd95a77d2019-11-17 21:04:58 +000032 * in a certain revision. It is returned by the lookup functions.
Heiko Voigt959b5452015-08-17 17:21:57 -070033 */
34struct submodule {
35 const char *path;
36 const char *name;
37 const char *url;
Philippe Blain465b30a2022-04-04 17:10:11 +000038 enum submodule_recurse_mode fetch_recurse;
Heiko Voigt959b5452015-08-17 17:21:57 -070039 const char *ignore;
Stefan Bellerb5944f32016-07-28 17:44:07 -070040 const char *branch;
Stefan Bellerea2fa5a2016-02-29 18:07:11 -080041 struct submodule_update_strategy update_strategy;
brian m. carlson34caab02018-05-02 00:25:42 +000042 /* the object id of the responsible .gitmodules file */
43 struct object_id gitmodules_oid;
Stefan Beller37f52e92016-05-26 14:59:42 -070044 int recommend_shallow;
Heiko Voigt959b5452015-08-17 17:21:57 -070045};
Brandon Williamsbf12fcd2017-06-22 11:43:44 -070046struct submodule_cache;
47struct repository;
48
Denton Liu55454422019-04-29 04:28:14 -040049void submodule_cache_free(struct submodule_cache *cache);
Brandon Williamsbf12fcd2017-06-22 11:43:44 -070050
Glen Choo8868b1e2023-06-28 19:26:27 +000051int parse_submodule_fetchjobs(const char *var, const char *value,
52 const struct key_value_info *kvi);
Denton Liu55454422019-04-29 04:28:14 -040053int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg);
Stefan Beller886dc152017-06-23 12:13:00 -070054struct option;
Denton Liu55454422019-04-29 04:28:14 -040055int option_fetch_parse_recurse_submodules(const struct option *opt,
Denton Liuad6dad02019-04-29 04:28:23 -040056 const char *arg, int unset);
Denton Liu55454422019-04-29 04:28:14 -040057int parse_update_recurse_submodules_arg(const char *opt, const char *arg);
58int parse_push_recurse_submodules_arg(const char *opt, const char *arg);
Matheus Tavaresd7992422020-01-15 23:39:55 -030059void repo_read_gitmodules(struct repository *repo, int skip_if_read);
Denton Liu55454422019-04-29 04:28:14 -040060void gitmodules_config_oid(const struct object_id *commit_oid);
Heba Walyd95a77d2019-11-17 21:04:58 +000061
62/**
63 * Same as submodule_from_path but lookup by name.
64 */
Stefan Beller3b8fb392018-03-28 15:35:29 -070065const struct submodule *submodule_from_name(struct repository *r,
66 const struct object_id *commit_or_tree,
67 const char *name);
Heba Walyd95a77d2019-11-17 21:04:58 +000068
69/**
70 * Given a tree-ish in the superproject and a path, return the submodule that
71 * is bound at the path in the named tree.
72 */
Stefan Beller3b8fb392018-03-28 15:35:29 -070073const struct submodule *submodule_from_path(struct repository *r,
74 const struct object_id *commit_or_tree,
75 const char *path);
Heba Walyd95a77d2019-11-17 21:04:58 +000076
77/**
78 * Use these to free the internally cached values.
79 */
Stefan Bellerf793b892018-03-28 15:35:28 -070080void submodule_free(struct repository *r);
Heba Walyd95a77d2019-11-17 21:04:58 +000081
Antonio Ospitebcbc7802018-10-05 15:05:52 +020082int print_config_from_gitmodules(struct repository *repo, const char *key);
Antonio Ospite45f5ef32018-10-05 15:05:53 +020083int config_set_in_gitmodules_file_gently(const char *key, const char *value);
Heiko Voigt959b5452015-08-17 17:21:57 -070084
Jeff King0383bbb2018-04-30 03:25:25 -040085/*
86 * Returns 0 if the name is syntactically acceptable as a submodule "name"
87 * (e.g., that may be found in the subsection of a .gitmodules file) and -1
88 * otherwise.
89 */
90int check_submodule_name(const char *name);
91
Victoria Dye13320ff2024-01-18 01:55:15 +000092/* Returns 0 if the URL valid per RFC3986 and -1 otherwise. */
93int check_submodule_url(const char *url);
94
Antonio Ospitead136372018-06-26 12:47:05 +020095/*
Antonio Ospite588929d2018-06-26 12:47:08 +020096 * Note: these helper functions exist solely to maintain backward
97 * compatibility with 'fetch' and 'update_clone' storing configuration in
98 * '.gitmodules'.
Antonio Ospitead136372018-06-26 12:47:05 +020099 *
Antonio Ospite588929d2018-06-26 12:47:08 +0200100 * New helpers to retrieve arbitrary configuration from the '.gitmodules' file
101 * should NOT be added.
Antonio Ospitead136372018-06-26 12:47:05 +0200102 */
Denton Liu55454422019-04-29 04:28:14 -0400103void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules);
104void update_clone_config_from_gitmodules(int *max_jobs);
Antonio Ospite71a69532018-06-26 12:47:06 +0200105
Glen Choo961b1302022-01-28 16:04:45 -0800106/*
107 * Submodule entry that contains relevant information about a
108 * submodule in a tree.
109 */
110struct submodule_tree_entry {
111 /* The submodule's tree entry. */
112 struct name_entry *name_entry;
113 /*
114 * A struct repository corresponding to the submodule. May be
115 * NULL if the submodule has not been updated.
116 */
117 struct repository *repo;
118 /*
119 * A struct submodule containing the submodule config in the
120 * tree's .gitmodules.
121 */
122 const struct submodule *submodule;
123};
124
125struct submodule_entry_list {
126 struct submodule_tree_entry *entries;
127 int entry_nr;
128 int entry_alloc;
129};
130
131/**
132 * Given a treeish, return all submodules in the tree and its subtrees,
133 * but excluding nested submodules. Callers that require nested
134 * submodules are expected to recurse into the submodules themselves.
135 */
136void submodules_of_tree(struct repository *r,
137 const struct object_id *treeish_name,
138 struct submodule_entry_list *ret);
Patrick Steinhardt5cca1142024-09-30 11:13:27 +0200139
140void submodule_entry_list_release(struct submodule_entry_list *list);
141
Heiko Voigt959b5452015-08-17 17:21:57 -0700142#endif /* SUBMODULE_CONFIG_H */