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