Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/config.h # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / config.h` 745 lines ยท 26490 bytes Raw Blame History 1 #ifndef CONFIG_H 2 #define CONFIG_H 3 4 #include "hashmap.h" 5 #include "string-list.h" 6 #include "repository.h" 7 #include "parse.h" 8 9 /** 10 * The config API gives callers a way to access Git configuration files 11 * (and files which have the same syntax). 12 * 13 * General Usage 14 * ------------- 15 * 16 * Config files are parsed linearly, and each variable found is passed to a 17 * caller-provided callback function. The callback function is responsible 18 * for any actions to be taken on the config option, and is free to ignore 19 * some options. It is not uncommon for the configuration to be parsed 20 * several times during the run of a Git program, with different callbacks 21 * picking out different variables useful to themselves. 22 */ 23 24 struct object_id; 25 struct strbuf; 26 27 /* git_config_parse_key() returns these negated: */ 28 #define CONFIG_INVALID_KEY 1 29 #define CONFIG_NO_SECTION_OR_NAME 2 30 /* repo_config_set_gently(), repo_config_set_multivar_gently() return the above or these: */ 31 #define CONFIG_NO_LOCK -1 32 #define CONFIG_INVALID_FILE 3 33 #define CONFIG_NO_WRITE 4 34 #define CONFIG_NOTHING_SET 5 35 #define CONFIG_INVALID_PATTERN 6 36 #define CONFIG_GENERIC_ERROR 7 37 38 #define CONFIG_REGEX_NONE ((void *)1) 39 40 enum config_scope { 41 CONFIG_SCOPE_UNKNOWN = 0, 42 CONFIG_SCOPE_SYSTEM, 43 CONFIG_SCOPE_GLOBAL, 44 CONFIG_SCOPE_LOCAL, 45 CONFIG_SCOPE_WORKTREE, 46 CONFIG_SCOPE_COMMAND, 47 CONFIG_SCOPE_SUBMODULE, 48 }; 49 const char *config_scope_name(enum config_scope scope); 50 51 struct git_config_source { 52 unsigned int use_stdin:1; 53 const char *file; 54 const char *blob; 55 enum config_scope scope; 56 }; 57 58 enum config_origin_type { 59 CONFIG_ORIGIN_UNKNOWN = 0, 60 CONFIG_ORIGIN_BLOB, 61 CONFIG_ORIGIN_FILE, 62 CONFIG_ORIGIN_STDIN, 63 CONFIG_ORIGIN_SUBMODULE_BLOB, 64 CONFIG_ORIGIN_CMDLINE 65 }; 66 67 enum config_event_t { 68 CONFIG_EVENT_SECTION, 69 CONFIG_EVENT_ENTRY, 70 CONFIG_EVENT_WHITESPACE, 71 CONFIG_EVENT_COMMENT, 72 CONFIG_EVENT_EOF, 73 CONFIG_EVENT_ERROR 74 }; 75 76 struct config_source; 77 /* 78 * The parser event function (if not NULL) is called with the event type and 79 * the begin/end offsets of the parsed elements. 80 * 81 * Note: for CONFIG_EVENT_ENTRY (i.e. config variables), the trailing newline 82 * character is considered part of the element. 83 */ 84 typedef int (*config_parser_event_fn_t)(enum config_event_t type, 85 size_t begin_offset, size_t end_offset, 86 struct config_source *cs, 87 void *event_fn_data); 88 89 struct config_options { 90 unsigned int respect_includes : 1; 91 unsigned int ignore_repo : 1; 92 unsigned int ignore_worktree : 1; 93 unsigned int ignore_cmdline : 1; 94 unsigned int system_gently : 1; 95 96 /* 97 * For internal use. Include all includeif.hasremoteurl paths without 98 * checking if the repo has that remote URL, and when doing so, verify 99 * that files included in this way do not configure any remote URLs 100 * themselves. 101 */ 102 unsigned int unconditional_remote_url : 1; 103 104 const char *commondir; 105 const char *git_dir; 106 /* 107 * event_fn and event_fn_data are for internal use only. Handles events 108 * emitted by the config parser. 109 */ 110 config_parser_event_fn_t event_fn; 111 void *event_fn_data; 112 enum config_error_action { 113 CONFIG_ERROR_UNSET = 0, /* use source-specific default */ 114 CONFIG_ERROR_DIE, /* die() on error */ 115 CONFIG_ERROR_ERROR, /* error() on error, return -1 */ 116 CONFIG_ERROR_SILENT, /* return -1 */ 117 } error_action; 118 }; 119 120 /* Config source metadata for a given config key-value pair */ 121 struct key_value_info { 122 const char *filename; 123 int linenr; 124 enum config_origin_type origin_type; 125 enum config_scope scope; 126 }; 127 #define KVI_INIT { \ 128 .filename = NULL, \ 129 .linenr = -1, \ 130 .origin_type = CONFIG_ORIGIN_UNKNOWN, \ 131 .scope = CONFIG_SCOPE_UNKNOWN, \ 132 } 133 134 /* Captures additional information that a config callback can use. */ 135 struct config_context { 136 /* Config source metadata for key and value. */ 137 const struct key_value_info *kvi; 138 }; 139 #define CONFIG_CONTEXT_INIT { 0 } 140 141 /** 142 * A config callback function takes four parameters: 143 * 144 * - the name of the parsed variable. This is in canonical "flat" form: the 145 * section, subsection, and variable segments will be separated by dots, 146 * and the section and variable segments will be all lowercase. E.g., 147 * `core.ignorecase`, `diff.SomeType.textconv`. 148 * 149 * - the value of the found variable, as a string. If the variable had no 150 * value specified, the value will be NULL (typically this means it 151 * should be interpreted as boolean true). 152 * 153 * - the 'config context', that is, additional information about the config 154 * iteration operation provided by the config machinery. For example, this 155 * includes information about the config source being parsed (e.g. the 156 * filename). 157 * 158 * - a void pointer passed in by the caller of the config API; this can 159 * contain callback-specific data 160 * 161 * A config callback should return 0 for success, or -1 if the variable 162 * could not be parsed properly. 163 */ 164 typedef int (*config_fn_t)(const char *, const char *, 165 const struct config_context *, void *); 166 167 /** 168 * Read a specific file in git-config format. 169 * This function takes the same callback and data parameters as `repo_config`. 170 * 171 * Unlike repo_config(), this function does not respect includes. 172 */ 173 int git_config_from_file(config_fn_t fn, const char *, void *); 174 175 int git_config_from_file_with_options(config_fn_t fn, const char *, 176 void *, enum config_scope, 177 const struct config_options *); 178 int git_config_from_mem(config_fn_t fn, 179 const enum config_origin_type, 180 const char *name, 181 const char *buf, size_t len, 182 void *data, enum config_scope scope, 183 const struct config_options *opts); 184 int git_config_from_blob_oid(config_fn_t fn, const char *name, 185 struct repository *repo, 186 const struct object_id *oid, void *data, 187 enum config_scope scope); 188 void git_config_push_parameter(const char *text); 189 void git_config_push_env(const char *spec); 190 191 /* 192 * Append a config option to the buffer that can be exported via the 193 * GIT_CONFIG_PARAMETERS environment variable, which allows us to 194 * propagate configuration across Git processes. The format of the 195 * variable is a space-separated list of quoted "''=''" 196 * pairs. With a NULL `value`, only 'key'= is appended, which git reads 197 * back as a boolean true, like "-c key" on the command line. 198 */ 199 void git_config_append_parameter(struct strbuf *env, const char *key, 200 const char *value); 201 int git_config_from_parameters(config_fn_t fn, void *data); 202 203 /* 204 * Read config when the Git directory has not yet been set up. In case 205 * `the_repository` has not yet been set up, try to discover the Git 206 * directory to read the configuration from. 207 */ 208 void read_early_config(struct repository *repo, config_fn_t cb, void *data); 209 210 /* 211 * Read config but only enumerate system and global settings. 212 * Omit any repo-local, worktree-local, or command-line settings. 213 */ 214 void read_very_early_config(config_fn_t cb, void *data); 215 216 /** 217 * Most programs will simply want to look up variables in all config files 218 * that Git knows about, using the normal precedence rules. To do this, 219 * call `repo_config` with a callback function and void data pointer. 220 * 221 * `repo_config` will read all config sources in order of increasing 222 * priority. Thus a callback should typically overwrite previously-seen 223 * entries with new ones (e.g., if both the user-wide `~/.gitconfig` and 224 * repo-specific `.git/config` contain `color.ui`, the config machinery 225 * will first feed the user-wide one to the callback, and then the 226 * repo-specific one; by overwriting, the higher-priority repo-specific 227 * value is left at the end). 228 * 229 * In cases where the repository variable is NULL, repo_config() will 230 * skip the per-repository config but retain system and global configs 231 * by calling read_very_early_config() which also ignores one-time 232 * overrides like "git -c var=val". This is to support handling "git foo -h" 233 * (which lets git.c:run_builtin() to pass NULL and have the cmd_foo() 234 * call repo_config() before calling parse_options() to notice "-h", give 235 * help and exit) for a command that ordinarily require a repository 236 * so this limitation may be OK (but if needed you are welcome to fix it). 237 * 238 * Unlike git_config_from_file(), this function respects includes. 239 */ 240 void repo_config(struct repository *r, config_fn_t fn, void *); 241 242 /** 243 * Lets the caller examine config while adjusting some of the default 244 * behavior of `repo_config`. It should almost never be used by "regular" 245 * Git code that is looking up configuration variables. 246 * It is intended for advanced callers like `git-config`, which are 247 * intentionally tweaking the normal config-lookup process. 248 * It takes two extra parameters: 249 * 250 * - `config_source` 251 * If this parameter is non-NULL, it specifies the source to parse for 252 * configuration, rather than looking in the usual files. See `struct 253 * git_config_source` in `config.h` for details. Regular `repo_config` defaults 254 * to `NULL`. 255 * 256 * - `opts` 257 * Specify options to adjust the behavior of parsing config files. See `struct 258 * config_options` in `config.h` for details. As an example: regular `repo_config` 259 * sets `opts.respect_includes` to `1` by default. 260 */ 261 int config_with_options(config_fn_t fn, void *, 262 const struct git_config_source *config_source, 263 struct repository *repo, 264 const struct config_options *opts); 265 266 /** 267 * Value Parsing Helpers 268 * --------------------- 269 * 270 * The following helper functions aid in parsing string values 271 */ 272 273 /** 274 * Parse the string to an integer, including unit factors. Dies on error; 275 * otherwise, returns the parsed result. 276 */ 277 int git_config_int(const char *, const char *, const struct key_value_info *); 278 279 int64_t git_config_int64(const char *, const char *, 280 const struct key_value_info *); 281 282 /** 283 * Identical to `git_config_int`, but for unsigned ints. 284 */ 285 unsigned int git_config_uint(const char *, const char *, 286 const struct key_value_info *); 287 288 /** 289 * Identical to `git_config_int`, but for unsigned longs. 290 */ 291 unsigned long git_config_ulong(const char *, const char *, 292 const struct key_value_info *); 293 294 ssize_t git_config_ssize_t(const char *, const char *, 295 const struct key_value_info *); 296 297 size_t git_config_size_t(const char *, const char *, 298 const struct key_value_info *); 299 300 /** 301 * Identically to `git_config_double`, but for double-precision floating point 302 * values. 303 */ 304 double git_config_double(const char *, const char *, 305 const struct key_value_info *); 306 307 /** 308 * Same as `git_config_bool`, except that integers are returned as-is, and 309 * an `is_bool` flag is unset. 310 */ 311 int git_config_bool_or_int(const char *, const char *, 312 const struct key_value_info *, int *); 313 314 /** 315 * Parse a string into a boolean value, respecting keywords like "true" and 316 * "false". Integer values are converted into true/false values (when they 317 * are non-zero or zero, respectively). Other values cause a die(). If 318 * parsing is successful, the return value is the result. 319 */ 320 int git_config_bool(const char *, const char *); 321 322 /** 323 * Allocates and copies the value string into the `dest` parameter; if no 324 * string is given, prints an error message and returns -1. 325 */ 326 int git_config_string(char **, const char *, const char *); 327 328 /** 329 * Similar to `git_config_string`, but expands `~` or `~user` into the 330 * user's home directory when found at the beginning of the path. 331 */ 332 int git_config_pathname(char **, const char *, const char *); 333 334 int git_config_expiry_date(timestamp_t *, const char *, const char *); 335 int git_config_color(char *, const char *, const char *); 336 int repo_config_set_in_file_gently(struct repository *r, const char *config_filename, 337 const char *key, const char *comment, const char *value); 338 339 /** 340 * write config values to a specific config file, takes a key/value pair as 341 * parameter. 342 */ 343 void repo_config_set_in_file(struct repository *, const char *, const char *, const char *); 344 345 int repo_config_set_gently(struct repository *r, const char *, const char *); 346 347 /** 348 * Write a config value that should apply to the current worktree. If 349 * extensions.worktreeConfig is enabled, then the write will happen in the 350 * current worktree's config. Otherwise, write to the common config file. 351 */ 352 int repo_config_set_worktree_gently(struct repository *, const char *, const char *); 353 354 /** 355 * write config values to `.git/config`, takes a key/value pair as parameter. 356 */ 357 void repo_config_set(struct repository *, const char *, const char *); 358 359 int git_config_parse_key(const char *, char **, size_t *); 360 361 int git_config_key_is_valid(const char *); 362 363 /* 364 * The following macros specify flag bits that alter the behavior 365 * of the repo_config_set_multivar*() methods. 366 */ 367 368 /* 369 * When CONFIG_FLAGS_MULTI_REPLACE is specified, all matching key/values 370 * are removed before a single new pair is written. If the flag is not 371 * present, then set operations replace only the first match. 372 */ 373 #define CONFIG_FLAGS_MULTI_REPLACE (1 << 0) 374 375 /* 376 * When CONFIG_FLAGS_FIXED_VALUE is specified, match key/value pairs 377 * by string comparison (not regex match) to the provided value_pattern 378 * parameter. 379 */ 380 #define CONFIG_FLAGS_FIXED_VALUE (1 << 1) 381 382 int repo_config_set_multivar_gently(struct repository *, const char *, const char *, const char *, unsigned); 383 void repo_config_set_multivar(struct repository *r, const char *, const char *, const char *, unsigned); 384 int repo_config_set_multivar_in_file_gently(struct repository *, const char *, const char *, const char *, const char *, const char *, unsigned); 385 386 char *git_config_prepare_comment_string(const char *); 387 388 /** 389 * takes four parameters: 390 * 391 * - the name of the file, as a string, to which key/value pairs will be written. 392 * 393 * - the name of key, as a string. This is in canonical "flat" form: the section, 394 * subsection, and variable segments will be separated by dots, and the section 395 * and variable segments will be all lowercase. 396 * E.g., `core.ignorecase`, `diff.SomeType.textconv`. 397 * 398 * - the value of the variable, as a string. If value is equal to NULL, it will 399 * remove the matching key from the config file. 400 * 401 * - the value regex, as a string. It will disregard key/value pairs where value 402 * does not match. 403 * 404 * - a flags value with bits corresponding to the CONFIG_FLAG_* macros. 405 * 406 * It returns 0 on success. 407 */ 408 void repo_config_set_multivar_in_file(struct repository *r, 409 const char *config_filename, 410 const char *key, 411 const char *value, 412 const char *value_pattern, 413 unsigned flags); 414 415 /** 416 * rename or remove sections in the config file 417 * parameters `old_name` and `new_name` 418 * If NULL is passed through `new_name` parameter, 419 * the section will be removed from the config file. 420 */ 421 int repo_config_rename_section(struct repository *, const char *, const char *); 422 423 int repo_config_rename_section_in_file(struct repository *, const char *, const char *, const char *); 424 int repo_config_copy_section(struct repository *, const char *, const char *); 425 int repo_config_copy_section_in_file(struct repository *, const char *, const char *, const char *); 426 int git_config_system(void); 427 int config_error_nonbool(const char *); 428 #if defined(__GNUC__) 429 #define config_error_nonbool(s) (config_error_nonbool(s), const_error()) 430 #endif 431 432 char *git_system_config(void); 433 char *git_global_config(void); 434 void git_global_config_paths(char **user, char **xdg); 435 436 int git_config_parse_parameter(const char *, config_fn_t fn, void *data); 437 438 const char *config_origin_type_name(enum config_origin_type type); 439 void kvi_from_param(struct key_value_info *out); 440 441 /* 442 * Match and parse a config key of the form: 443 * 444 * section.(subsection.)?key 445 * 446 * (i.e., what gets handed to a config_fn_t). The caller provides the section; 447 * we return -1 if it does not match, 0 otherwise. The subsection and key 448 * out-parameters are filled by the function (and *subsection is NULL if it is 449 * missing). 450 * 451 * If the subsection pointer-to-pointer passed in is NULL, returns 0 only if 452 * there is no subsection at all. 453 */ 454 int parse_config_key(const char *var, 455 const char *section, 456 const char **subsection, size_t *subsection_len, 457 const char **key); 458 459 /** 460 * Custom Configsets 461 * ----------------- 462 * 463 * A `config_set` can be used to construct an in-memory cache for 464 * config-like files that the caller specifies (i.e., files like `.gitmodules`, 465 * `~/.gitconfig` etc.). For example, 466 * 467 * ---------------------------------------- 468 * struct config_set gm_config; 469 * git_configset_init(&gm_config); 470 * int b; 471 * //we add config files to the config_set 472 * git_configset_add_file(&gm_config, ".gitmodules"); 473 * git_configset_add_file(&gm_config, ".gitmodules_alt"); 474 * 475 * if (!git_configset_get_bool(gm_config, "submodule.frotz.ignore", &b)) { 476 * //hack hack hack 477 * } 478 * 479 * when we are done with the configset: 480 * git_configset_clear(&gm_config); 481 * ---------------------------------------- 482 * 483 * Configset API provides functions for the above mentioned work flow 484 */ 485 486 struct config_set_element { 487 struct hashmap_entry ent; 488 char *key; 489 struct string_list value_list; 490 }; 491 492 struct configset_list_item { 493 struct config_set_element *e; 494 int value_index; 495 }; 496 497 /* 498 * the contents of the list are ordered according to their 499 * position in the config files and order of parsing the files. 500 * (i.e. key-value pair at the last position of .git/config will 501 * be at the last item of the list) 502 */ 503 struct configset_list { 504 struct configset_list_item *items; 505 unsigned int nr, alloc; 506 }; 507 508 struct config_set { 509 struct hashmap config_hash; 510 int hash_initialized; 511 struct configset_list list; 512 }; 513 514 /** 515 * Initializes the config_set `cs`. 516 */ 517 void git_configset_init(struct config_set *cs); 518 519 /** 520 * Parses the file and adds the variable-value pairs to the `config_set`, 521 * dies if there is an error in parsing the file. Returns 0 on success, or 522 * -1 if the file does not exist or is inaccessible. The caller decides 523 * whether to free the incomplete configset or continue using it when 524 * the function returns -1. 525 */ 526 int git_configset_add_file(struct config_set *cs, const char *filename); 527 528 /** 529 * Finds and returns the value list, sorted in order of increasing priority 530 * for the configuration variable `key` and config set `cs`. When the 531 * configuration variable `key` is not found, returns 1 without touching 532 * `value`. 533 * 534 * The key will be parsed for validity with git_config_parse_key(), on 535 * error a negative value will be returned. 536 * 537 * The caller should not free or modify the returned pointer, as it is 538 * owned by the cache. 539 */ 540 RESULT_MUST_BE_USED 541 int git_configset_get_value_multi(struct config_set *cs, const char *key, 542 const struct string_list **dest); 543 544 /** 545 * A validation wrapper for git_configset_get_value_multi() which does 546 * for it what git_configset_get_string() does for 547 * git_configset_get_value(). 548 * 549 * The configuration syntax allows for "[section] key", which will 550 * give us a NULL entry in the "struct string_list", as opposed to 551 * "[section] key =" which is the empty string. Most users of the API 552 * are not prepared to handle NULL in a "struct string_list". 553 */ 554 int git_configset_get_string_multi(struct config_set *cs, const char *key, 555 const struct string_list **dest); 556 557 /** 558 * Clears `config_set` structure, removes all saved variable-value pairs. 559 */ 560 void git_configset_clear(struct config_set *cs); 561 562 /* 563 * These functions return 1 if not found, and 0 if found, leaving the found 564 * value in the 'dest' pointer. 565 */ 566 567 /** 568 * git_configset_get() returns negative values on error, see 569 * repo_config_get() below. 570 */ 571 RESULT_MUST_BE_USED 572 int git_configset_get(struct config_set *cs, const char *key); 573 574 /* 575 * Finds the highest-priority value for the configuration variable `key` 576 * and config set `cs`, stores the pointer to it in `value` and returns 0. 577 * When the configuration variable `key` is not found, returns 1 without 578 * touching `value`. The caller should not free or modify `value`, as it 579 * is owned by the cache. 580 */ 581 int git_configset_get_value(struct config_set *cs, const char *key, 582 const char **dest, struct key_value_info *kvi); 583 584 int git_configset_get_string(struct config_set *cs, const char *key, char **dest); 585 int git_configset_get_int(struct config_set *cs, const char *key, int *dest); 586 int git_configset_get_uint(struct config_set *cs, const char *key, unsigned int *dest); 587 int git_configset_get_ulong(struct config_set *cs, const char *key, unsigned long *dest); 588 int git_configset_get_bool(struct config_set *cs, const char *key, int *dest); 589 int git_configset_get_bool_or_int(struct config_set *cs, const char *key, int *is_bool, int *dest); 590 int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *dest); 591 592 /** 593 * Run only the discover part of the repo_config_get_*() functions 594 * below, in addition to 1 if not found, returns negative values on 595 * error (e.g. if the key itself is invalid). 596 */ 597 int repo_config_get_pathname(struct repository *repo, 598 const char *key, char **dest); 599 600 /* 601 * Functions for reading protected config. By definition, protected 602 * config ignores repository config, so these do not take a `struct 603 * repository` parameter. 604 */ 605 void git_protected_config(config_fn_t fn, void *data); 606 607 /** 608 * Querying For Specific Variables 609 * ------------------------------- 610 * 611 * For programs wanting to query for specific variables in a non-callback 612 * manner, the config API provides two functions `repo_config_get_value` 613 * and `repo_config_get_value_multi`. They both read values from an internal 614 * cache generated previously from reading the config files. 615 * 616 * For those repo_config_get*() functions that aren't documented, 617 * consult the corresponding repo_config_get*() function's 618 * documentation. 619 */ 620 621 RESULT_MUST_BE_USED 622 int repo_config_get(struct repository *r, const char *key); 623 624 /** 625 * Finds the highest-priority value for the configuration variable `key`, 626 * stores the pointer to it in `value` and returns 0. When the 627 * configuration variable `key` is not found, returns 1 without touching 628 * `value`. The caller should not free or modify `value`, as it is owned 629 * by the cache. 630 */ 631 int repo_config_get_value(struct repository *r, const char *key, const char **value); 632 633 /** 634 * Finds and returns the value list, sorted in order of increasing priority 635 * for the configuration variable `key`. When the configuration variable 636 * `key` is not found, returns 1 without touching `value`. 637 * 638 * The caller should not free or modify the returned pointer, as it is 639 * owned by the cache. 640 */ 641 RESULT_MUST_BE_USED 642 int repo_config_get_value_multi(struct repository *r, const char *key, 643 const struct string_list **dest); 644 RESULT_MUST_BE_USED 645 int repo_config_get_string_multi(struct repository *r, const char *key, 646 const struct string_list **dest); 647 648 /** 649 * Resets and invalidates the config cache. 650 */ 651 void repo_config_clear(struct repository *repo); 652 653 /** 654 * Allocates and copies the retrieved string into the `dest` parameter for 655 * the configuration variable `key`; if NULL string is given, prints an 656 * error message and returns -1. When the configuration variable `key` is 657 * not found, returns 1 without touching `dest`. 658 */ 659 int repo_config_get_string(struct repository *r, const char *key, char **dest); 660 661 /** 662 * Similar to `repo_config_get_string`, but does not allocate any new 663 * memory; on success `dest` will point to memory owned by the config 664 * machinery, which could be invalidated if it is discarded and reloaded. 665 */ 666 int repo_config_get_string_tmp(struct repository *r, 667 const char *key, const char **dest); 668 669 /** 670 * Finds and parses the value to an integer for the configuration variable 671 * `key`. Dies on error; otherwise, stores the value of the parsed integer in 672 * `dest` and returns 0. When the configuration variable `key` is not found, 673 * returns 1 without touching `dest`. 674 */ 675 int repo_config_get_int(struct repository *r, const char *key, int *dest); 676 677 /** 678 * Similar to `repo_config_get_int` but for unsigned ints. 679 */ 680 int repo_config_get_uint(struct repository *r, 681 const char *key, unsigned int *dest); 682 683 /** 684 * Similar to `repo_config_get_int` but for unsigned longs. 685 */ 686 int repo_config_get_ulong(struct repository *r, 687 const char *key, unsigned long *dest); 688 689 /** 690 * Finds and parses the value into a boolean value, for the configuration 691 * variable `key` respecting keywords like "true" and "false". Integer 692 * values are converted into true/false values (when they are non-zero or 693 * zero, respectively). Other values cause a die(). If parsing is successful, 694 * stores the value of the parsed result in `dest` and returns 0. When the 695 * configuration variable `key` is not found, returns 1 without touching 696 * `dest`. 697 */ 698 int repo_config_get_bool(struct repository *r, const char *key, int *dest); 699 700 /** 701 * Similar to `repo_config_get_bool`, except that integers are copied as-is, 702 * and `is_bool` flag is unset. 703 */ 704 int repo_config_get_bool_or_int(struct repository *r, const char *key, 705 int *is_bool, int *dest); 706 707 /** 708 * Similar to `repo_config_get_bool`, except that it returns -1 on error 709 * rather than dying. 710 */ 711 int repo_config_get_maybe_bool(struct repository *r, 712 const char *key, int *dest); 713 714 int repo_config_get_index_threads(struct repository *r, int *dest); 715 int repo_config_get_split_index(struct repository *r); 716 int repo_config_get_max_percent_split_change(struct repository *r); 717 718 /* This dies if the configured or default date is in the future */ 719 int repo_config_get_expiry(struct repository *r, const char *key, char **output); 720 721 /* parse either "this many days" integer, or "5.days.ago" approxidate */ 722 int repo_config_get_expiry_in_days(struct repository *r, const char *key, 723 timestamp_t *, timestamp_t now); 724 725 /** 726 * First prints the error message specified by the caller in `err` and then 727 * dies printing the line number and the file name of the highest priority 728 * value for the configuration variable `key`. 729 */ 730 NORETURN void git_die_config(struct repository *r, const char *key, const char *err, ...) 731 __attribute__((format(printf, 3, 4))); 732 733 /** 734 * Helper function which formats the die error message according to the 735 * parameters entered. Used by `git_die_config()`. It can be used by callers 736 * handling `repo_config_get_value_multi()` to print the correct error message 737 * for the desired value. 738 */ 739 NORETURN void git_die_config_linenr(const char *key, const char *filename, int linenr); 740 741 #define LOOKUP_CONFIG(mapping, var) \ 742 lookup_config(mapping, ARRAY_SIZE(mapping), var) 743 int lookup_config(const char **mapping, int nr_mapping, const char *var); 744 745 #endif /* CONFIG_H */