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