blob: c11e22cf509ad1be7531c1740f4701578e6db723 [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"
9
Heba Walyd95a77d2019-11-17 21:04:58 +000010/**
11 * The submodule config cache API allows to read submodule
12 * configurations/information from specified revisions. Internally
13 * information is lazily read into a cache that is used to avoid
14 * unnecessary parsing of the same .gitmodules files. Lookups can be done by
15 * submodule path or name.
16 *
17 * Usage
18 * -----
19 *
20 * The caller can look up information about submodules by using the
21 * `submodule_from_path()` or `submodule_from_name()` functions. They return
22 * a `struct submodule` which contains the values. The API automatically
23 * initializes and allocates the needed infrastructure on-demand. If the
24 * caller does only want to lookup values from revisions the initialization
25 * can be skipped.
26 *
27 * If the internal cache might grow too big or when the caller is done with
28 * the API, all internally cached values can be freed with submodule_free().
29 *
30 */
31
Heiko Voigt959b5452015-08-17 17:21:57 -070032/*
33 * Submodule entry containing the information about a certain submodule
Heba Walyd95a77d2019-11-17 21:04:58 +000034 * in a certain revision. It is returned by the lookup functions.
Heiko Voigt959b5452015-08-17 17:21:57 -070035 */
36struct submodule {
37 const char *path;
38 const char *name;
39 const char *url;
40 int fetch_recurse;
41 const char *ignore;
Stefan Bellerb5944f32016-07-28 17:44:07 -070042 const char *branch;
Stefan Bellerea2fa5a2016-02-29 18:07:11 -080043 struct submodule_update_strategy update_strategy;
brian m. carlson34caab02018-05-02 00:25:42 +000044 /* the object id of the responsible .gitmodules file */
45 struct object_id gitmodules_oid;
Stefan Beller37f52e92016-05-26 14:59:42 -070046 int recommend_shallow;
Heiko Voigt959b5452015-08-17 17:21:57 -070047};
48
Heiko Voigtc68f8372017-10-16 15:58:27 +020049#define SUBMODULE_INIT { NULL, NULL, NULL, RECURSE_SUBMODULES_NONE, \
brian m. carlson34caab02018-05-02 00:25:42 +000050 NULL, NULL, SUBMODULE_UPDATE_STRATEGY_INIT, { { 0 } }, -1 };
Heiko Voigtc68f8372017-10-16 15:58:27 +020051
Brandon Williamsbf12fcd2017-06-22 11:43:44 -070052struct submodule_cache;
53struct repository;
54
Denton Liu55454422019-04-29 04:28:14 -040055void submodule_cache_free(struct submodule_cache *cache);
Brandon Williamsbf12fcd2017-06-22 11:43:44 -070056
Denton Liu55454422019-04-29 04:28:14 -040057int parse_submodule_fetchjobs(const char *var, const char *value);
58int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg);
Stefan Beller886dc152017-06-23 12:13:00 -070059struct option;
Denton Liu55454422019-04-29 04:28:14 -040060int option_fetch_parse_recurse_submodules(const struct option *opt,
Denton Liuad6dad02019-04-29 04:28:23 -040061 const char *arg, int unset);
Denton Liu55454422019-04-29 04:28:14 -040062int parse_update_recurse_submodules_arg(const char *opt, const char *arg);
63int parse_push_recurse_submodules_arg(const char *opt, const char *arg);
Matheus Tavaresd7992422020-01-15 23:39:55 -030064void repo_read_gitmodules(struct repository *repo, int skip_if_read);
Denton Liu55454422019-04-29 04:28:14 -040065void gitmodules_config_oid(const struct object_id *commit_oid);
Heba Walyd95a77d2019-11-17 21:04:58 +000066
67/**
68 * Same as submodule_from_path but lookup by name.
69 */
Stefan Beller3b8fb392018-03-28 15:35:29 -070070const struct submodule *submodule_from_name(struct repository *r,
71 const struct object_id *commit_or_tree,
72 const char *name);
Heba Walyd95a77d2019-11-17 21:04:58 +000073
74/**
75 * Given a tree-ish in the superproject and a path, return the submodule that
76 * is bound at the path in the named tree.
77 */
Stefan Beller3b8fb392018-03-28 15:35:29 -070078const struct submodule *submodule_from_path(struct repository *r,
79 const struct object_id *commit_or_tree,
80 const char *path);
Heba Walyd95a77d2019-11-17 21:04:58 +000081
82/**
83 * Use these to free the internally cached values.
84 */
Stefan Bellerf793b892018-03-28 15:35:28 -070085void submodule_free(struct repository *r);
Heba Walyd95a77d2019-11-17 21:04:58 +000086
Antonio Ospitebcbc7802018-10-05 15:05:52 +020087int print_config_from_gitmodules(struct repository *repo, const char *key);
Antonio Ospite45f5ef32018-10-05 15:05:53 +020088int config_set_in_gitmodules_file_gently(const char *key, const char *value);
Heiko Voigt959b5452015-08-17 17:21:57 -070089
Jeff King0383bbb2018-04-30 03:25:25 -040090/*
91 * Returns 0 if the name is syntactically acceptable as a submodule "name"
92 * (e.g., that may be found in the subsection of a .gitmodules file) and -1
93 * otherwise.
94 */
95int check_submodule_name(const char *name);
96
Antonio Ospitead136372018-06-26 12:47:05 +020097/*
Antonio Ospite588929d2018-06-26 12:47:08 +020098 * Note: these helper functions exist solely to maintain backward
99 * compatibility with 'fetch' and 'update_clone' storing configuration in
100 * '.gitmodules'.
Antonio Ospitead136372018-06-26 12:47:05 +0200101 *
Antonio Ospite588929d2018-06-26 12:47:08 +0200102 * New helpers to retrieve arbitrary configuration from the '.gitmodules' file
103 * should NOT be added.
Antonio Ospitead136372018-06-26 12:47:05 +0200104 */
Denton Liu55454422019-04-29 04:28:14 -0400105void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules);
106void update_clone_config_from_gitmodules(int *max_jobs);
Antonio Ospite71a69532018-06-26 12:47:06 +0200107
Heiko Voigt959b5452015-08-17 17:21:57 -0700108#endif /* SUBMODULE_CONFIG_H */