]>
Commit | Line | Data |
---|---|---|
1 | #ifndef CONFIG_H | |
2 | #define CONFIG_H | |
3 | ||
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 | |
14 | ||
15 | #define CONFIG_REGEX_NONE ((void *)1) | |
16 | ||
17 | struct git_config_source { | |
18 | unsigned int use_stdin:1; | |
19 | const char *file; | |
20 | const char *blob; | |
21 | }; | |
22 | ||
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 | |
29 | }; | |
30 | ||
31 | struct config_options { | |
32 | unsigned int respect_includes : 1; | |
33 | const char *commondir; | |
34 | const char *git_dir; | |
35 | }; | |
36 | ||
37 | typedef int (*config_fn_t)(const char *, const char *, void *); | |
38 | extern int git_default_config(const char *, const char *, void *); | |
39 | extern int git_config_from_file(config_fn_t fn, const char *, void *); | |
40 | extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type, | |
41 | const char *name, const char *buf, size_t len, void *data); | |
42 | extern int git_config_from_blob_oid(config_fn_t fn, const char *name, | |
43 | const struct object_id *oid, void *data); | |
44 | extern void git_config_push_parameter(const char *text); | |
45 | extern int git_config_from_parameters(config_fn_t fn, void *data); | |
46 | extern void read_early_config(config_fn_t cb, void *data); | |
47 | extern void git_config(config_fn_t fn, void *); | |
48 | extern int config_with_options(config_fn_t fn, void *, | |
49 | struct git_config_source *config_source, | |
50 | const struct config_options *opts); | |
51 | extern int git_parse_ulong(const char *, unsigned long *); | |
52 | extern int git_parse_maybe_bool(const char *); | |
53 | extern int git_config_int(const char *, const char *); | |
54 | extern int64_t git_config_int64(const char *, const char *); | |
55 | extern unsigned long git_config_ulong(const char *, const char *); | |
56 | extern ssize_t git_config_ssize_t(const char *, const char *); | |
57 | extern int git_config_bool_or_int(const char *, const char *, int *); | |
58 | extern int git_config_bool(const char *, const char *); | |
59 | extern int git_config_string(const char **, const char *, const char *); | |
60 | extern int git_config_pathname(const char **, const char *, const char *); | |
61 | extern int git_config_expiry_date(timestamp_t *, const char *, const char *); | |
62 | extern int git_config_set_in_file_gently(const char *, const char *, const char *); | |
63 | extern void git_config_set_in_file(const char *, const char *, const char *); | |
64 | extern int git_config_set_gently(const char *, const char *); | |
65 | extern void git_config_set(const char *, const char *); | |
66 | extern int git_config_parse_key(const char *, char **, int *); | |
67 | extern int git_config_key_is_valid(const char *key); | |
68 | extern int git_config_set_multivar_gently(const char *, const char *, const char *, int); | |
69 | extern void git_config_set_multivar(const char *, const char *, const char *, int); | |
70 | extern int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int); | |
71 | extern void git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int); | |
72 | extern int git_config_rename_section(const char *, const char *); | |
73 | extern int git_config_rename_section_in_file(const char *, const char *, const char *); | |
74 | extern int git_config_copy_section(const char *, const char *); | |
75 | extern int git_config_copy_section_in_file(const char *, const char *, const char *); | |
76 | extern const char *git_etc_gitconfig(void); | |
77 | extern int git_env_bool(const char *, int); | |
78 | extern unsigned long git_env_ulong(const char *, unsigned long); | |
79 | extern int git_config_system(void); | |
80 | extern int config_error_nonbool(const char *); | |
81 | #if defined(__GNUC__) | |
82 | #define config_error_nonbool(s) (config_error_nonbool(s), const_error()) | |
83 | #endif | |
84 | ||
85 | extern int git_config_parse_parameter(const char *, config_fn_t fn, void *data); | |
86 | ||
87 | enum config_scope { | |
88 | CONFIG_SCOPE_UNKNOWN = 0, | |
89 | CONFIG_SCOPE_SYSTEM, | |
90 | CONFIG_SCOPE_GLOBAL, | |
91 | CONFIG_SCOPE_REPO, | |
92 | CONFIG_SCOPE_CMDLINE, | |
93 | }; | |
94 | ||
95 | extern enum config_scope current_config_scope(void); | |
96 | extern const char *current_config_origin_type(void); | |
97 | extern const char *current_config_name(void); | |
98 | ||
99 | struct config_include_data { | |
100 | int depth; | |
101 | config_fn_t fn; | |
102 | void *data; | |
103 | const struct config_options *opts; | |
104 | }; | |
105 | #define CONFIG_INCLUDE_INIT { 0 } | |
106 | extern int git_config_include(const char *name, const char *value, void *data); | |
107 | ||
108 | /* | |
109 | * Match and parse a config key of the form: | |
110 | * | |
111 | * section.(subsection.)?key | |
112 | * | |
113 | * (i.e., what gets handed to a config_fn_t). The caller provides the section; | |
114 | * we return -1 if it does not match, 0 otherwise. The subsection and key | |
115 | * out-parameters are filled by the function (and *subsection is NULL if it is | |
116 | * missing). | |
117 | * | |
118 | * If the subsection pointer-to-pointer passed in is NULL, returns 0 only if | |
119 | * there is no subsection at all. | |
120 | */ | |
121 | extern int parse_config_key(const char *var, | |
122 | const char *section, | |
123 | const char **subsection, int *subsection_len, | |
124 | const char **key); | |
125 | ||
126 | struct config_set_element { | |
127 | struct hashmap_entry ent; | |
128 | char *key; | |
129 | struct string_list value_list; | |
130 | }; | |
131 | ||
132 | struct configset_list_item { | |
133 | struct config_set_element *e; | |
134 | int value_index; | |
135 | }; | |
136 | ||
137 | /* | |
138 | * the contents of the list are ordered according to their | |
139 | * position in the config files and order of parsing the files. | |
140 | * (i.e. key-value pair at the last position of .git/config will | |
141 | * be at the last item of the list) | |
142 | */ | |
143 | struct configset_list { | |
144 | struct configset_list_item *items; | |
145 | unsigned int nr, alloc; | |
146 | }; | |
147 | ||
148 | struct config_set { | |
149 | struct hashmap config_hash; | |
150 | int hash_initialized; | |
151 | struct configset_list list; | |
152 | }; | |
153 | ||
154 | extern void git_configset_init(struct config_set *cs); | |
155 | extern int git_configset_add_file(struct config_set *cs, const char *filename); | |
156 | extern int git_configset_get_value(struct config_set *cs, const char *key, const char **value); | |
157 | extern const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key); | |
158 | extern void git_configset_clear(struct config_set *cs); | |
159 | extern int git_configset_get_string_const(struct config_set *cs, const char *key, const char **dest); | |
160 | extern int git_configset_get_string(struct config_set *cs, const char *key, char **dest); | |
161 | extern int git_configset_get_int(struct config_set *cs, const char *key, int *dest); | |
162 | extern int git_configset_get_ulong(struct config_set *cs, const char *key, unsigned long *dest); | |
163 | extern int git_configset_get_bool(struct config_set *cs, const char *key, int *dest); | |
164 | extern int git_configset_get_bool_or_int(struct config_set *cs, const char *key, int *is_bool, int *dest); | |
165 | extern int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *dest); | |
166 | extern int git_configset_get_pathname(struct config_set *cs, const char *key, const char **dest); | |
167 | ||
168 | /* Functions for reading a repository's config */ | |
169 | struct repository; | |
170 | extern void repo_config(struct repository *repo, config_fn_t fn, void *data); | |
171 | extern int repo_config_get_value(struct repository *repo, | |
172 | const char *key, const char **value); | |
173 | extern const struct string_list *repo_config_get_value_multi(struct repository *repo, | |
174 | const char *key); | |
175 | extern int repo_config_get_string_const(struct repository *repo, | |
176 | const char *key, const char **dest); | |
177 | extern int repo_config_get_string(struct repository *repo, | |
178 | const char *key, char **dest); | |
179 | extern int repo_config_get_int(struct repository *repo, | |
180 | const char *key, int *dest); | |
181 | extern int repo_config_get_ulong(struct repository *repo, | |
182 | const char *key, unsigned long *dest); | |
183 | extern int repo_config_get_bool(struct repository *repo, | |
184 | const char *key, int *dest); | |
185 | extern int repo_config_get_bool_or_int(struct repository *repo, | |
186 | const char *key, int *is_bool, int *dest); | |
187 | extern int repo_config_get_maybe_bool(struct repository *repo, | |
188 | const char *key, int *dest); | |
189 | extern int repo_config_get_pathname(struct repository *repo, | |
190 | const char *key, const char **dest); | |
191 | ||
192 | /* | |
193 | * Note: This function exists solely to maintain backward compatibility with | |
194 | * 'fetch' and 'update_clone' storing configuration in '.gitmodules' and should | |
195 | * NOT be used anywhere else. | |
196 | * | |
197 | * Runs the provided config function on the '.gitmodules' file found in the | |
198 | * working directory. | |
199 | */ | |
200 | extern void config_from_gitmodules(config_fn_t fn, void *data); | |
201 | ||
202 | extern int git_config_get_value(const char *key, const char **value); | |
203 | extern const struct string_list *git_config_get_value_multi(const char *key); | |
204 | extern void git_config_clear(void); | |
205 | extern int git_config_get_string_const(const char *key, const char **dest); | |
206 | extern int git_config_get_string(const char *key, char **dest); | |
207 | extern int git_config_get_int(const char *key, int *dest); | |
208 | extern int git_config_get_ulong(const char *key, unsigned long *dest); | |
209 | extern int git_config_get_bool(const char *key, int *dest); | |
210 | extern int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest); | |
211 | extern int git_config_get_maybe_bool(const char *key, int *dest); | |
212 | extern int git_config_get_pathname(const char *key, const char **dest); | |
213 | extern int git_config_get_untracked_cache(void); | |
214 | extern int git_config_get_split_index(void); | |
215 | extern int git_config_get_max_percent_split_change(void); | |
216 | extern int git_config_get_fsmonitor(void); | |
217 | ||
218 | /* This dies if the configured or default date is in the future */ | |
219 | extern int git_config_get_expiry(const char *key, const char **output); | |
220 | ||
221 | /* parse either "this many days" integer, or "5.days.ago" approxidate */ | |
222 | extern int git_config_get_expiry_in_days(const char *key, timestamp_t *, timestamp_t now); | |
223 | ||
224 | struct key_value_info { | |
225 | const char *filename; | |
226 | int linenr; | |
227 | enum config_origin_type origin_type; | |
228 | enum config_scope scope; | |
229 | }; | |
230 | ||
231 | extern NORETURN void git_die_config(const char *key, const char *err, ...) __attribute__((format(printf, 2, 3))); | |
232 | extern NORETURN void git_die_config_linenr(const char *key, const char *filename, int linenr); | |
233 | ||
234 | #endif /* CONFIG_H */ |