config: create config.h

Move all config related declarations from cache.h to a new config.h header file. This makes cache.h smaller and allows for the opportunity in a following patch to only include config.h when needed. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed Jun 14, 2017 at 11:07 UTC e67a57fc5187f93ced9631edf80fc09eefb3fed9
2 files changed +195 -189
cache.h
+1 -189
@@ -11,6 +11,7 @@
11 #include "string-list.h"
12 #include "pack-revindex.h"
13 #include "hash.h"
14 +#include "config.h"
15
16 #ifndef platform_SHA_CTX
17 /*
@@ -1865,188 +1866,9 @@ extern int packed_object_info(struct packed_git *pack, off_t offset, struct obje
1866 /* Dumb servers support */
1867 extern int update_server_info(int);
1868
1868 -/* git_config_parse_key() returns these negated: */
1869 -#define CONFIG_INVALID_KEY 1
1870 -#define CONFIG_NO_SECTION_OR_NAME 2
1871 -/* git_config_set_gently(), git_config_set_multivar_gently() return the above or these: */
1872 -#define CONFIG_NO_LOCK -1
1873 -#define CONFIG_INVALID_FILE 3
1874 -#define CONFIG_NO_WRITE 4
1875 -#define CONFIG_NOTHING_SET 5
1876 -#define CONFIG_INVALID_PATTERN 6
1877 -#define CONFIG_GENERIC_ERROR 7
1878 -
1879 -#define CONFIG_REGEX_NONE ((void *)1)
1880 -
1881 -struct git_config_source {
1882 - unsigned int use_stdin:1;
1883 - const char *file;
1884 - const char *blob;
1885 -};
1886 -
1887 -enum config_origin_type {
1888 - CONFIG_ORIGIN_BLOB,
1889 - CONFIG_ORIGIN_FILE,
1890 - CONFIG_ORIGIN_STDIN,
1891 - CONFIG_ORIGIN_SUBMODULE_BLOB,
1892 - CONFIG_ORIGIN_CMDLINE
1893 -};
1894 -
1895 -struct config_options {
1896 - unsigned int respect_includes : 1;
1897 - const char *git_dir;
1898 -};
1899 -
1900 -typedef int (*config_fn_t)(const char *, const char *, void *);
1901 -extern int git_default_config(const char *, const char *, void *);
1902 -extern int git_config_from_file(config_fn_t fn, const char *, void *);
1903 -extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
1904 - const char *name, const char *buf, size_t len, void *data);
1905 -extern int git_config_from_blob_sha1(config_fn_t fn, const char *name,
1906 - const unsigned char *sha1, void *data);
1907 -extern void git_config_push_parameter(const char *text);
1908 -extern int git_config_from_parameters(config_fn_t fn, void *data);
1909 -extern void read_early_config(config_fn_t cb, void *data);
1910 -extern void git_config(config_fn_t fn, void *);
1911 -extern int git_config_with_options(config_fn_t fn, void *,
1912 - struct git_config_source *config_source,
1913 - const struct config_options *opts);
1914 -extern int git_parse_ulong(const char *, unsigned long *);
1915 -extern int git_parse_maybe_bool(const char *);
1916 -extern int git_config_int(const char *, const char *);
1917 -extern int64_t git_config_int64(const char *, const char *);
1918 -extern unsigned long git_config_ulong(const char *, const char *);
1919 -extern ssize_t git_config_ssize_t(const char *, const char *);
1920 -extern int git_config_bool_or_int(const char *, const char *, int *);
1921 -extern int git_config_bool(const char *, const char *);
1922 -extern int git_config_maybe_bool(const char *, const char *);
1923 -extern int git_config_string(const char **, const char *, const char *);
1924 -extern int git_config_pathname(const char **, const char *, const char *);
1925 -extern int git_config_set_in_file_gently(const char *, const char *, const char *);
1926 -extern void git_config_set_in_file(const char *, const char *, const char *);
1927 -extern int git_config_set_gently(const char *, const char *);
1928 -extern void git_config_set(const char *, const char *);
1929 -extern int git_config_parse_key(const char *, char **, int *);
1930 -extern int git_config_key_is_valid(const char *key);
1931 -extern int git_config_set_multivar_gently(const char *, const char *, const char *, int);
1932 -extern void git_config_set_multivar(const char *, const char *, const char *, int);
1933 -extern int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int);
1934 -extern void git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int);
1935 -extern int git_config_rename_section(const char *, const char *);
1936 -extern int git_config_rename_section_in_file(const char *, const char *, const char *);
1937 -extern const char *git_etc_gitconfig(void);
1938 -extern int git_env_bool(const char *, int);
1939 -extern unsigned long git_env_ulong(const char *, unsigned long);
1940 -extern int git_config_system(void);
1941 -extern int config_error_nonbool(const char *);
1942 -#if defined(__GNUC__)
1943 -#define config_error_nonbool(s) (config_error_nonbool(s), const_error())
1944 -#endif
1869 extern const char *get_log_output_encoding(void);
1870 extern const char *get_commit_output_encoding(void);
1871
1948 -extern int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
1949 -
1950 -enum config_scope {
1951 - CONFIG_SCOPE_UNKNOWN = 0,
1952 - CONFIG_SCOPE_SYSTEM,
1953 - CONFIG_SCOPE_GLOBAL,
1954 - CONFIG_SCOPE_REPO,
1955 - CONFIG_SCOPE_CMDLINE,
1956 -};
1957 -
1958 -extern enum config_scope current_config_scope(void);
1959 -extern const char *current_config_origin_type(void);
1960 -extern const char *current_config_name(void);
1961 -
1962 -struct config_include_data {
1963 - int depth;
1964 - config_fn_t fn;
1965 - void *data;
1966 - const struct config_options *opts;
1967 -};
1968 -#define CONFIG_INCLUDE_INIT { 0 }
1969 -extern int git_config_include(const char *name, const char *value, void *data);
1970 -
1971 -/*
1972 - * Match and parse a config key of the form:
1973 - *
1974 - * section.(subsection.)?key
1975 - *
1976 - * (i.e., what gets handed to a config_fn_t). The caller provides the section;
1977 - * we return -1 if it does not match, 0 otherwise. The subsection and key
1978 - * out-parameters are filled by the function (and *subsection is NULL if it is
1979 - * missing).
1980 - *
1981 - * If the subsection pointer-to-pointer passed in is NULL, returns 0 only if
1982 - * there is no subsection at all.
1983 - */
1984 -extern int parse_config_key(const char *var,
1985 - const char *section,
1986 - const char **subsection, int *subsection_len,
1987 - const char **key);
1988 -
1989 -struct config_set_element {
1990 - struct hashmap_entry ent;
1991 - char *key;
1992 - struct string_list value_list;
1993 -};
1994 -
1995 -struct configset_list_item {
1996 - struct config_set_element *e;
1997 - int value_index;
1998 -};
1999 -
2000 -/*
2001 - * the contents of the list are ordered according to their
2002 - * position in the config files and order of parsing the files.
2003 - * (i.e. key-value pair at the last position of .git/config will
2004 - * be at the last item of the list)
2005 - */
2006 -struct configset_list {
2007 - struct configset_list_item *items;
2008 - unsigned int nr, alloc;
2009 -};
2010 -
2011 -struct config_set {
2012 - struct hashmap config_hash;
2013 - int hash_initialized;
2014 - struct configset_list list;
2015 -};
2016 -
2017 -extern void git_configset_init(struct config_set *cs);
2018 -extern int git_configset_add_file(struct config_set *cs, const char *filename);
2019 -extern int git_configset_get_value(struct config_set *cs, const char *key, const char **value);
2020 -extern const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key);
2021 -extern void git_configset_clear(struct config_set *cs);
2022 -extern int git_configset_get_string_const(struct config_set *cs, const char *key, const char **dest);
2023 -extern int git_configset_get_string(struct config_set *cs, const char *key, char **dest);
2024 -extern int git_configset_get_int(struct config_set *cs, const char *key, int *dest);
2025 -extern int git_configset_get_ulong(struct config_set *cs, const char *key, unsigned long *dest);
2026 -extern int git_configset_get_bool(struct config_set *cs, const char *key, int *dest);
2027 -extern int git_configset_get_bool_or_int(struct config_set *cs, const char *key, int *is_bool, int *dest);
2028 -extern int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *dest);
2029 -extern int git_configset_get_pathname(struct config_set *cs, const char *key, const char **dest);
2030 -
2031 -extern int git_config_get_value(const char *key, const char **value);
2032 -extern const struct string_list *git_config_get_value_multi(const char *key);
2033 -extern void git_config_clear(void);
2034 -extern void git_config_iter(config_fn_t fn, void *data);
2035 -extern int git_config_get_string_const(const char *key, const char **dest);
2036 -extern int git_config_get_string(const char *key, char **dest);
2037 -extern int git_config_get_int(const char *key, int *dest);
2038 -extern int git_config_get_ulong(const char *key, unsigned long *dest);
2039 -extern int git_config_get_bool(const char *key, int *dest);
2040 -extern int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest);
2041 -extern int git_config_get_maybe_bool(const char *key, int *dest);
2042 -extern int git_config_get_pathname(const char *key, const char **dest);
2043 -extern int git_config_get_untracked_cache(void);
2044 -extern int git_config_get_split_index(void);
2045 -extern int git_config_get_max_percent_split_change(void);
2046 -
2047 -/* This dies if the configured or default date is in the future */
2048 -extern int git_config_get_expiry(const char *key, const char **output);
2049 -
1872 /*
1873 * This is a hack for test programs like test-dump-untracked-cache to
1874 * ensure that they do not modify the untracked cache when reading it.
@@ -2054,16 +1876,6 @@ extern int git_config_get_expiry(const char *key, const char **output);
1876 */
1877 extern int ignore_untracked_cache_config;
1878
2057 -struct key_value_info {
2058 - const char *filename;
2059 - int linenr;
2060 - enum config_origin_type origin_type;
2061 - enum config_scope scope;
2062 -};
2063 -
2064 -extern NORETURN void git_die_config(const char *key, const char *err, ...) __attribute__((format(printf, 2, 3)));
2065 -extern NORETURN void git_die_config_linenr(const char *key, const char *filename, int linenr);
2066 -
1879 extern int committer_ident_sufficiently_given(void);
1880 extern int author_ident_sufficiently_given(void);
1881
config.h new
+194
@@ -0,0 +1,194 @@
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 *git_dir;
34 +};
35 +
36 +typedef int (*config_fn_t)(const char *, const char *, void *);
37 +extern int git_default_config(const char *, const char *, void *);
38 +extern int git_config_from_file(config_fn_t fn, const char *, void *);
39 +extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
40 + const char *name, const char *buf, size_t len, void *data);
41 +extern int git_config_from_blob_sha1(config_fn_t fn, const char *name,
42 + const unsigned char *sha1, void *data);
43 +extern void git_config_push_parameter(const char *text);
44 +extern int git_config_from_parameters(config_fn_t fn, void *data);
45 +extern void read_early_config(config_fn_t cb, void *data);
46 +extern void git_config(config_fn_t fn, void *);
47 +extern int git_config_with_options(config_fn_t fn, void *,
48 + struct git_config_source *config_source,
49 + const struct config_options *opts);
50 +extern int git_parse_ulong(const char *, unsigned long *);
51 +extern int git_parse_maybe_bool(const char *);
52 +extern int git_config_int(const char *, const char *);
53 +extern int64_t git_config_int64(const char *, const char *);
54 +extern unsigned long git_config_ulong(const char *, const char *);
55 +extern ssize_t git_config_ssize_t(const char *, const char *);
56 +extern int git_config_bool_or_int(const char *, const char *, int *);
57 +extern int git_config_bool(const char *, const char *);
58 +extern int git_config_maybe_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_set_in_file_gently(const char *, const char *, const char *);
62 +extern void git_config_set_in_file(const char *, const char *, const char *);
63 +extern int git_config_set_gently(const char *, const char *);
64 +extern void git_config_set(const char *, const char *);
65 +extern int git_config_parse_key(const char *, char **, int *);
66 +extern int git_config_key_is_valid(const char *key);
67 +extern int git_config_set_multivar_gently(const char *, const char *, const char *, int);
68 +extern void git_config_set_multivar(const char *, const char *, const char *, int);
69 +extern int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int);
70 +extern void git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int);
71 +extern int git_config_rename_section(const char *, const char *);
72 +extern int git_config_rename_section_in_file(const char *, const char *, const char *);
73 +extern const char *git_etc_gitconfig(void);
74 +extern int git_env_bool(const char *, int);
75 +extern unsigned long git_env_ulong(const char *, unsigned long);
76 +extern int git_config_system(void);
77 +extern int config_error_nonbool(const char *);
78 +#if defined(__GNUC__)
79 +#define config_error_nonbool(s) (config_error_nonbool(s), const_error())
80 +#endif
81 +
82 +extern int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
83 +
84 +enum config_scope {
85 + CONFIG_SCOPE_UNKNOWN = 0,
86 + CONFIG_SCOPE_SYSTEM,
87 + CONFIG_SCOPE_GLOBAL,
88 + CONFIG_SCOPE_REPO,
89 + CONFIG_SCOPE_CMDLINE,
90 +};
91 +
92 +extern enum config_scope current_config_scope(void);
93 +extern const char *current_config_origin_type(void);
94 +extern const char *current_config_name(void);
95 +
96 +struct config_include_data {
97 + int depth;
98 + config_fn_t fn;
99 + void *data;
100 + const struct config_options *opts;
101 +};
102 +#define CONFIG_INCLUDE_INIT { 0 }
103 +extern int git_config_include(const char *name, const char *value, void *data);
104 +
105 +/*
106 + * Match and parse a config key of the form:
107 + *
108 + * section.(subsection.)?key
109 + *
110 + * (i.e., what gets handed to a config_fn_t). The caller provides the section;
111 + * we return -1 if it does not match, 0 otherwise. The subsection and key
112 + * out-parameters are filled by the function (and *subsection is NULL if it is
113 + * missing).
114 + *
115 + * If the subsection pointer-to-pointer passed in is NULL, returns 0 only if
116 + * there is no subsection at all.
117 + */
118 +extern int parse_config_key(const char *var,
119 + const char *section,
120 + const char **subsection, int *subsection_len,
121 + const char **key);
122 +
123 +struct config_set_element {
124 + struct hashmap_entry ent;
125 + char *key;
126 + struct string_list value_list;
127 +};
128 +
129 +struct configset_list_item {
130 + struct config_set_element *e;
131 + int value_index;
132 +};
133 +
134 +/*
135 + * the contents of the list are ordered according to their
136 + * position in the config files and order of parsing the files.
137 + * (i.e. key-value pair at the last position of .git/config will
138 + * be at the last item of the list)
139 + */
140 +struct configset_list {
141 + struct configset_list_item *items;
142 + unsigned int nr, alloc;
143 +};
144 +
145 +struct config_set {
146 + struct hashmap config_hash;
147 + int hash_initialized;
148 + struct configset_list list;
149 +};
150 +
151 +extern void git_configset_init(struct config_set *cs);
152 +extern int git_configset_add_file(struct config_set *cs, const char *filename);
153 +extern int git_configset_get_value(struct config_set *cs, const char *key, const char **value);
154 +extern const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key);
155 +extern void git_configset_clear(struct config_set *cs);
156 +extern int git_configset_get_string_const(struct config_set *cs, const char *key, const char **dest);
157 +extern int git_configset_get_string(struct config_set *cs, const char *key, char **dest);
158 +extern int git_configset_get_int(struct config_set *cs, const char *key, int *dest);
159 +extern int git_configset_get_ulong(struct config_set *cs, const char *key, unsigned long *dest);
160 +extern int git_configset_get_bool(struct config_set *cs, const char *key, int *dest);
161 +extern int git_configset_get_bool_or_int(struct config_set *cs, const char *key, int *is_bool, int *dest);
162 +extern int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *dest);
163 +extern int git_configset_get_pathname(struct config_set *cs, const char *key, const char **dest);
164 +
165 +extern int git_config_get_value(const char *key, const char **value);
166 +extern const struct string_list *git_config_get_value_multi(const char *key);
167 +extern void git_config_clear(void);
168 +extern void git_config_iter(config_fn_t fn, void *data);
169 +extern int git_config_get_string_const(const char *key, const char **dest);
170 +extern int git_config_get_string(const char *key, char **dest);
171 +extern int git_config_get_int(const char *key, int *dest);
172 +extern int git_config_get_ulong(const char *key, unsigned long *dest);
173 +extern int git_config_get_bool(const char *key, int *dest);
174 +extern int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest);
175 +extern int git_config_get_maybe_bool(const char *key, int *dest);
176 +extern int git_config_get_pathname(const char *key, const char **dest);
177 +extern int git_config_get_untracked_cache(void);
178 +extern int git_config_get_split_index(void);
179 +extern int git_config_get_max_percent_split_change(void);
180 +
181 +/* This dies if the configured or default date is in the future */
182 +extern int git_config_get_expiry(const char *key, const char **output);
183 +
184 +struct key_value_info {
185 + const char *filename;
186 + int linenr;
187 + enum config_origin_type origin_type;
188 + enum config_scope scope;
189 +};
190 +
191 +extern NORETURN void git_die_config(const char *key, const char *err, ...) __attribute__((format(printf, 2, 3)));
192 +extern NORETURN void git_die_config_linenr(const char *key, const char *filename, int linenr);
193 +
194 +#endif /* CONFIG_H */