t2024: mark test using "checkout -p" with PERL prerequisite
[git/debian.git] / config.h
blobcdac2fc73e6a2d0bc3230848425557a23e88d0bf
1 #ifndef CONFIG_H
2 #define CONFIG_H
4 /* git_config_parse_key() returns these negated: */
5 #define CONFIG_INVALID_KEY 1
6 #define CONFIG_NO_SECTION_OR_NAME 2
7 /* git_config_set_gently(), git_config_set_multivar_gently() return the above or these: */
8 #define CONFIG_NO_LOCK -1
9 #define CONFIG_INVALID_FILE 3
10 #define CONFIG_NO_WRITE 4
11 #define CONFIG_NOTHING_SET 5
12 #define CONFIG_INVALID_PATTERN 6
13 #define CONFIG_GENERIC_ERROR 7
15 #define CONFIG_REGEX_NONE ((void *)1)
17 struct git_config_source {
18 unsigned int use_stdin:1;
19 const char *file;
20 const char *blob;
23 enum config_origin_type {
24 CONFIG_ORIGIN_BLOB,
25 CONFIG_ORIGIN_FILE,
26 CONFIG_ORIGIN_STDIN,
27 CONFIG_ORIGIN_SUBMODULE_BLOB,
28 CONFIG_ORIGIN_CMDLINE
31 enum config_event_t {
32 CONFIG_EVENT_SECTION,
33 CONFIG_EVENT_ENTRY,
34 CONFIG_EVENT_WHITESPACE,
35 CONFIG_EVENT_COMMENT,
36 CONFIG_EVENT_EOF,
37 CONFIG_EVENT_ERROR
41 * The parser event function (if not NULL) is called with the event type and
42 * the begin/end offsets of the parsed elements.
44 * Note: for CONFIG_EVENT_ENTRY (i.e. config variables), the trailing newline
45 * character is considered part of the element.
47 typedef int (*config_parser_event_fn_t)(enum config_event_t type,
48 size_t begin_offset, size_t end_offset,
49 void *event_fn_data);
51 struct config_options {
52 unsigned int respect_includes : 1;
53 const char *commondir;
54 const char *git_dir;
55 config_parser_event_fn_t event_fn;
56 void *event_fn_data;
59 typedef int (*config_fn_t)(const char *, const char *, void *);
60 extern int git_default_config(const char *, const char *, void *);
61 extern int git_config_from_file(config_fn_t fn, const char *, void *);
62 extern int git_config_from_file_with_options(config_fn_t fn, const char *,
63 void *,
64 const struct config_options *);
65 extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
66 const char *name, const char *buf, size_t len, void *data);
67 extern int git_config_from_blob_oid(config_fn_t fn, const char *name,
68 const struct object_id *oid, void *data);
69 extern void git_config_push_parameter(const char *text);
70 extern int git_config_from_parameters(config_fn_t fn, void *data);
71 extern void read_early_config(config_fn_t cb, void *data);
72 extern void git_config(config_fn_t fn, void *);
73 extern int config_with_options(config_fn_t fn, void *,
74 struct git_config_source *config_source,
75 const struct config_options *opts);
76 extern int git_parse_ulong(const char *, unsigned long *);
77 extern int git_parse_maybe_bool(const char *);
78 extern int git_config_int(const char *, const char *);
79 extern int64_t git_config_int64(const char *, const char *);
80 extern unsigned long git_config_ulong(const char *, const char *);
81 extern ssize_t git_config_ssize_t(const char *, const char *);
82 extern int git_config_bool_or_int(const char *, const char *, int *);
83 extern int git_config_bool(const char *, const char *);
84 extern int git_config_string(const char **, const char *, const char *);
85 extern int git_config_pathname(const char **, const char *, const char *);
86 extern int git_config_expiry_date(timestamp_t *, const char *, const char *);
87 extern int git_config_color(char *, const char *, const char *);
88 extern int git_config_set_in_file_gently(const char *, const char *, const char *);
89 extern void git_config_set_in_file(const char *, const char *, const char *);
90 extern int git_config_set_gently(const char *, const char *);
91 extern void git_config_set(const char *, const char *);
92 extern int git_config_parse_key(const char *, char **, int *);
93 extern int git_config_key_is_valid(const char *key);
94 extern int git_config_set_multivar_gently(const char *, const char *, const char *, int);
95 extern void git_config_set_multivar(const char *, const char *, const char *, int);
96 extern int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int);
97 extern void git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int);
98 extern int git_config_rename_section(const char *, const char *);
99 extern int git_config_rename_section_in_file(const char *, const char *, const char *);
100 extern int git_config_copy_section(const char *, const char *);
101 extern int git_config_copy_section_in_file(const char *, const char *, const char *);
102 extern const char *git_etc_gitconfig(void);
103 extern int git_env_bool(const char *, int);
104 extern unsigned long git_env_ulong(const char *, unsigned long);
105 extern int git_config_system(void);
106 extern int config_error_nonbool(const char *);
107 #if defined(__GNUC__)
108 #define config_error_nonbool(s) (config_error_nonbool(s), const_error())
109 #endif
111 extern int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
113 enum config_scope {
114 CONFIG_SCOPE_UNKNOWN = 0,
115 CONFIG_SCOPE_SYSTEM,
116 CONFIG_SCOPE_GLOBAL,
117 CONFIG_SCOPE_REPO,
118 CONFIG_SCOPE_CMDLINE,
121 extern enum config_scope current_config_scope(void);
122 extern const char *current_config_origin_type(void);
123 extern const char *current_config_name(void);
125 struct config_include_data {
126 int depth;
127 config_fn_t fn;
128 void *data;
129 const struct config_options *opts;
131 #define CONFIG_INCLUDE_INIT { 0 }
132 extern int git_config_include(const char *name, const char *value, void *data);
135 * Match and parse a config key of the form:
137 * section.(subsection.)?key
139 * (i.e., what gets handed to a config_fn_t). The caller provides the section;
140 * we return -1 if it does not match, 0 otherwise. The subsection and key
141 * out-parameters are filled by the function (and *subsection is NULL if it is
142 * missing).
144 * If the subsection pointer-to-pointer passed in is NULL, returns 0 only if
145 * there is no subsection at all.
147 extern int parse_config_key(const char *var,
148 const char *section,
149 const char **subsection, int *subsection_len,
150 const char **key);
152 struct config_set_element {
153 struct hashmap_entry ent;
154 char *key;
155 struct string_list value_list;
158 struct configset_list_item {
159 struct config_set_element *e;
160 int value_index;
164 * the contents of the list are ordered according to their
165 * position in the config files and order of parsing the files.
166 * (i.e. key-value pair at the last position of .git/config will
167 * be at the last item of the list)
169 struct configset_list {
170 struct configset_list_item *items;
171 unsigned int nr, alloc;
174 struct config_set {
175 struct hashmap config_hash;
176 int hash_initialized;
177 struct configset_list list;
180 extern void git_configset_init(struct config_set *cs);
181 extern int git_configset_add_file(struct config_set *cs, const char *filename);
182 extern int git_configset_get_value(struct config_set *cs, const char *key, const char **value);
183 extern const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key);
184 extern void git_configset_clear(struct config_set *cs);
185 extern int git_configset_get_string_const(struct config_set *cs, const char *key, const char **dest);
186 extern int git_configset_get_string(struct config_set *cs, const char *key, char **dest);
187 extern int git_configset_get_int(struct config_set *cs, const char *key, int *dest);
188 extern int git_configset_get_ulong(struct config_set *cs, const char *key, unsigned long *dest);
189 extern int git_configset_get_bool(struct config_set *cs, const char *key, int *dest);
190 extern int git_configset_get_bool_or_int(struct config_set *cs, const char *key, int *is_bool, int *dest);
191 extern int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *dest);
192 extern int git_configset_get_pathname(struct config_set *cs, const char *key, const char **dest);
194 /* Functions for reading a repository's config */
195 struct repository;
196 extern void repo_config(struct repository *repo, config_fn_t fn, void *data);
197 extern int repo_config_get_value(struct repository *repo,
198 const char *key, const char **value);
199 extern const struct string_list *repo_config_get_value_multi(struct repository *repo,
200 const char *key);
201 extern int repo_config_get_string_const(struct repository *repo,
202 const char *key, const char **dest);
203 extern int repo_config_get_string(struct repository *repo,
204 const char *key, char **dest);
205 extern int repo_config_get_int(struct repository *repo,
206 const char *key, int *dest);
207 extern int repo_config_get_ulong(struct repository *repo,
208 const char *key, unsigned long *dest);
209 extern int repo_config_get_bool(struct repository *repo,
210 const char *key, int *dest);
211 extern int repo_config_get_bool_or_int(struct repository *repo,
212 const char *key, int *is_bool, int *dest);
213 extern int repo_config_get_maybe_bool(struct repository *repo,
214 const char *key, int *dest);
215 extern int repo_config_get_pathname(struct repository *repo,
216 const char *key, const char **dest);
219 * Note: This function exists solely to maintain backward compatibility with
220 * 'fetch' and 'update_clone' storing configuration in '.gitmodules' and should
221 * NOT be used anywhere else.
223 * Runs the provided config function on the '.gitmodules' file found in the
224 * working directory.
226 extern void config_from_gitmodules(config_fn_t fn, void *data);
228 extern int git_config_get_value(const char *key, const char **value);
229 extern const struct string_list *git_config_get_value_multi(const char *key);
230 extern void git_config_clear(void);
231 extern int git_config_get_string_const(const char *key, const char **dest);
232 extern int git_config_get_string(const char *key, char **dest);
233 extern int git_config_get_int(const char *key, int *dest);
234 extern int git_config_get_ulong(const char *key, unsigned long *dest);
235 extern int git_config_get_bool(const char *key, int *dest);
236 extern int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest);
237 extern int git_config_get_maybe_bool(const char *key, int *dest);
238 extern int git_config_get_pathname(const char *key, const char **dest);
239 extern int git_config_get_untracked_cache(void);
240 extern int git_config_get_split_index(void);
241 extern int git_config_get_max_percent_split_change(void);
242 extern int git_config_get_fsmonitor(void);
244 /* This dies if the configured or default date is in the future */
245 extern int git_config_get_expiry(const char *key, const char **output);
247 /* parse either "this many days" integer, or "5.days.ago" approxidate */
248 extern int git_config_get_expiry_in_days(const char *key, timestamp_t *, timestamp_t now);
250 struct key_value_info {
251 const char *filename;
252 int linenr;
253 enum config_origin_type origin_type;
254 enum config_scope scope;
257 extern NORETURN void git_die_config(const char *key, const char *err, ...) __attribute__((format(printf, 2, 3)));
258 extern NORETURN void git_die_config_linenr(const char *key, const char *filename, int linenr);
260 #endif /* CONFIG_H */