1 /* 2 * Copyright (C) the libgit2 contributors. All rights reserved. 3 * 4 * This file is part of libgit2, distributed under the GNU GPL v2 with 5 * a Linking Exception. For full terms see the included COPYING file. 6 */ 7 /** 8 * License: GPL-2.0(Linking Exception) 9 */ 10 module libgit2.config; 11 12 13 private static import libgit2.buffer; 14 private static import libgit2.sys.config; 15 private static import libgit2.types; 16 private import libgit2.common: GIT_EXTERN; 17 18 /* 19 * @file git2/config.h 20 * @brief Git config management routines 21 * @defgroup git_config Git config management routines 22 * @ingroup Git 23 * @{ 24 */ 25 extern (C): 26 nothrow @nogc: 27 public: 28 29 /** 30 * Priority level of a config file. 31 * These priority levels correspond to the natural escalation logic 32 * (from higher to lower) when searching for config entries in git.git. 33 * 34 * git_config_open_default() and git_repository_config() honor those 35 * priority levels as well. 36 */ 37 enum git_config_level_t 38 { 39 /** 40 * System-wide on Windows, for compatibility with portable git 41 */ 42 GIT_CONFIG_LEVEL_PROGRAMDATA = 1, 43 44 /** 45 * System-wide configuration file; /etc/gitconfig on Linux systems 46 */ 47 GIT_CONFIG_LEVEL_SYSTEM = 2, 48 49 /** 50 * XDG compatible configuration file; typically ~/.config/git/config 51 */ 52 GIT_CONFIG_LEVEL_XDG = 3, 53 54 /** 55 * User-specific configuration file (also called Global configuration 56 * file); typically ~/.gitconfig 57 */ 58 GIT_CONFIG_LEVEL_GLOBAL = 4, 59 60 /** 61 * Repository specific configuration file; $WORK_DIR/.git/config on 62 * non-bare repos 63 */ 64 GIT_CONFIG_LEVEL_LOCAL = 5, 65 66 /** 67 * Application specific configuration file; freely defined by applications 68 */ 69 GIT_CONFIG_LEVEL_APP = 6, 70 71 /** 72 * Represents the highest level available config file (i.e. the most 73 * specific config file available that actually is loaded) 74 */ 75 GIT_CONFIG_HIGHEST_LEVEL = -1, 76 } 77 78 //Declaration name in C language 79 enum 80 { 81 GIT_CONFIG_LEVEL_PROGRAMDATA = .git_config_level_t.GIT_CONFIG_LEVEL_PROGRAMDATA, 82 GIT_CONFIG_LEVEL_SYSTEM = .git_config_level_t.GIT_CONFIG_LEVEL_SYSTEM, 83 GIT_CONFIG_LEVEL_XDG = .git_config_level_t.GIT_CONFIG_LEVEL_XDG, 84 GIT_CONFIG_LEVEL_GLOBAL = .git_config_level_t.GIT_CONFIG_LEVEL_GLOBAL, 85 GIT_CONFIG_LEVEL_LOCAL = .git_config_level_t.GIT_CONFIG_LEVEL_LOCAL, 86 GIT_CONFIG_LEVEL_APP = .git_config_level_t.GIT_CONFIG_LEVEL_APP, 87 GIT_CONFIG_HIGHEST_LEVEL = .git_config_level_t.GIT_CONFIG_HIGHEST_LEVEL, 88 } 89 90 /** 91 * An entry in a configuration file 92 */ 93 struct git_config_entry 94 { 95 /** 96 * Name of the entry (normalised) 97 */ 98 const (char)* name; 99 100 /** 101 * String value of the entry 102 */ 103 const (char)* value; 104 105 /** 106 * Depth of includes where this variable was found 107 */ 108 uint include_depth; 109 110 /** 111 * Which config file this was found in 112 */ 113 .git_config_level_t level = cast(.git_config_level_t)(0); 114 115 /** 116 * Free function for this entry 117 */ 118 void function(.git_config_entry* entry) free; 119 120 /** 121 * Opaque value for the free function. Do not read or write 122 */ 123 void* payload; 124 } 125 126 /** 127 * Free a config entry 128 * 129 * Params: 130 * entry = The entry to free. 131 */ 132 @GIT_EXTERN 133 void git_config_entry_free(.git_config_entry* entry); 134 135 /** 136 * A config enumeration callback 137 * 138 * Returns: non-zero to terminate the iteration. 139 */ 140 /* 141 * Params: 142 * entry = the entry currently being enumerated 143 * payload = a user-specified pointer 144 */ 145 alias git_config_foreach_cb = int function(const (.git_config_entry)* entry, void* payload); 146 147 /** 148 * An opaque structure for a configuration iterator 149 */ 150 alias git_config_iterator = libgit2.sys.config.git_config_iterator; 151 152 /** 153 * Config var type 154 */ 155 enum git_configmap_t 156 { 157 GIT_CONFIGMAP_FALSE = 0, 158 GIT_CONFIGMAP_TRUE = 1, 159 GIT_CONFIGMAP_INT32, 160 GIT_CONFIGMAP_STRING, 161 } 162 163 //Declaration name in C language 164 enum 165 { 166 GIT_CONFIGMAP_FALSE = .git_configmap_t.GIT_CONFIGMAP_FALSE, 167 GIT_CONFIGMAP_TRUE = .git_configmap_t.GIT_CONFIGMAP_TRUE, 168 GIT_CONFIGMAP_INT32 = .git_configmap_t.GIT_CONFIGMAP_INT32, 169 GIT_CONFIGMAP_STRING = .git_configmap_t.GIT_CONFIGMAP_STRING, 170 } 171 172 /** 173 * Mapping from config variables to values. 174 */ 175 struct git_configmap 176 { 177 .git_configmap_t cvar_type; 178 const (char)* str_match; 179 int map_value; 180 } 181 182 /** 183 * Locate the path to the global configuration file 184 * 185 * The user or global configuration file is usually 186 * located in `$HOME/.gitconfig`. 187 * 188 * This method will try to guess the full path to that 189 * file, if the file exists. The returned path 190 * may be used on any `git_config` call to load the 191 * global configuration file. 192 * 193 * This method will not guess the path to the xdg compatible 194 * config file (`.config/git/config`). 195 * 196 * Params: 197 * out_ = Pointer to a user-allocated git_buf in which to store the path 198 * 199 * Returns: 0 if a global configuration file has been found. Its path will be stored in `out`. 200 */ 201 @GIT_EXTERN 202 int git_config_find_global(libgit2.buffer.git_buf* out_); 203 204 /** 205 * Locate the path to the global xdg compatible configuration file 206 * 207 * The xdg compatible configuration file is usually 208 * located in `$HOME/.config/git/config`. 209 * 210 * This method will try to guess the full path to that 211 * file, if the file exists. The returned path 212 * may be used on any `git_config` call to load the 213 * xdg compatible configuration file. 214 * 215 * Params: 216 * out_ = Pointer to a user-allocated git_buf in which to store the path 217 * 218 * Returns: 0 if a xdg compatible configuration file has been found. Its path will be stored in `out`. 219 */ 220 @GIT_EXTERN 221 int git_config_find_xdg(libgit2.buffer.git_buf* out_); 222 223 /** 224 * Locate the path to the system configuration file 225 * 226 * If `/etc/gitconfig` doesn't exist, it will look for 227 * `%PROGRAMFILES%\Git\etc\gitconfig`. 228 * 229 * Params: 230 * out_ = Pointer to a user-allocated git_buf in which to store the path 231 * 232 * Returns: 0 if a system configuration file has been found. Its path will be stored in `out`. 233 */ 234 @GIT_EXTERN 235 int git_config_find_system(libgit2.buffer.git_buf* out_); 236 237 /** 238 * Locate the path to the configuration file in ProgramData 239 * 240 * Look for the file in `%PROGRAMDATA%\Git\config` used by portable git. 241 * 242 * Params: 243 * out_ = Pointer to a user-allocated git_buf in which to store the path 244 * 245 * Returns: 0 if a ProgramData configuration file has been found. Its path will be stored in `out`. 246 */ 247 @GIT_EXTERN 248 int git_config_find_programdata(libgit2.buffer.git_buf* out_); 249 250 /** 251 * Open the global, XDG and system configuration files 252 * 253 * Utility wrapper that finds the global, XDG and system configuration files 254 * and opens them into a single prioritized config object that can be 255 * used when accessing default config data outside a repository. 256 * 257 * Params: 258 * out_ = Pointer to store the config instance 259 * 260 * Returns: 0 or an error code 261 */ 262 @GIT_EXTERN 263 int git_config_open_default(libgit2.types.git_config** out_); 264 265 /** 266 * Allocate a new configuration object 267 * 268 * This object is empty, so you have to add a file to it before you 269 * can do anything with it. 270 * 271 * Params: 272 * out_ = pointer to the new configuration 273 * 274 * Returns: 0 or an error code 275 */ 276 @GIT_EXTERN 277 int git_config_new(libgit2.types.git_config** out_); 278 279 /** 280 * Add an on-disk config file instance to an existing config 281 * 282 * The on-disk file pointed at by `path` will be opened and 283 * parsed; it's expected to be a native Git config file following 284 * the default Git config syntax (see man git-config). 285 * 286 * If the file does not exist, the file will still be added and it 287 * will be created the first time we write to it. 288 * 289 * Note that the configuration object will free the file 290 * automatically. 291 * 292 * Further queries on this config object will access each 293 * of the config file instances in order (instances with 294 * a higher priority level will be accessed first). 295 * 296 * Params: 297 * cfg = the configuration to add the file to 298 * path = path to the configuration file to add 299 * level = the priority level of the backend 300 * force = replace config file at the given priority level 301 * repo = optional repository to allow parsing of conditional includes 302 * 303 * Returns: 0 on success, git_error_code.GIT_EEXISTS when adding more than one file for a given priority level (and force_replace set to 0), git_error_code.GIT_ENOTFOUND when the file doesn't exist or error code 304 */ 305 @GIT_EXTERN 306 int git_config_add_file_ondisk(libgit2.types.git_config* cfg, const (char)* path, .git_config_level_t level, const (libgit2.types.git_repository)* repo, int force); 307 308 /** 309 * Create a new config instance containing a single on-disk file 310 * 311 * This method is a simple utility wrapper for the following sequence 312 * of calls: 313 * - git_config_new 314 * - git_config_add_file_ondisk 315 * 316 * Params: 317 * out_ = The configuration instance to create 318 * path = Path to the on-disk file to open 319 * 320 * Returns: 0 on success, or an error code 321 */ 322 @GIT_EXTERN 323 int git_config_open_ondisk(libgit2.types.git_config** out_, const (char)* path); 324 325 /** 326 * Build a single-level focused config object from a multi-level one. 327 * 328 * The returned config object can be used to perform get/set/delete operations 329 * on a single specific level. 330 * 331 * Getting several times the same level from the same parent multi-level config 332 * will return different config instances, but containing the same config_file 333 * instance. 334 * 335 * Params: 336 * out_ = The configuration instance to create 337 * parent = Multi-level config to search for the given level 338 * level = Configuration level to search for 339 * 340 * Returns: 0, git_error_code.GIT_ENOTFOUND if the passed level cannot be found in the multi-level parent config, or an error code 341 */ 342 @GIT_EXTERN 343 int git_config_open_level(libgit2.types.git_config** out_, const (libgit2.types.git_config)* parent, .git_config_level_t level); 344 345 /** 346 * Open the global/XDG configuration file according to git's rules 347 * 348 * Git allows you to store your global configuration at 349 * `$HOME/.gitconfig` or `$XDG_CONFIG_HOME/git/config`. For backwards 350 * compatibility, the XDG file shouldn't be used unless the use has 351 * created it explicitly. With this function you'll open the correct 352 * one to write to. 353 * 354 * Params: 355 * out_ = pointer in which to store the config object 356 * config = the config object in which to look 357 * 358 * Returns: 0 or an error code. 359 */ 360 @GIT_EXTERN 361 int git_config_open_global(libgit2.types.git_config** out_, libgit2.types.git_config* config); 362 363 /** 364 * Create a snapshot of the configuration 365 * 366 * Create a snapshot of the current state of a configuration, which 367 * allows you to look into a consistent view of the configuration for 368 * looking up complex values (e.g. a remote, submodule). 369 * 370 * The string returned when querying such a config object is valid 371 * until it is freed. 372 * 373 * Params: 374 * out_ = pointer in which to store the snapshot config object 375 * config = configuration to snapshot 376 * 377 * Returns: 0 or an error code 378 */ 379 @GIT_EXTERN 380 int git_config_snapshot(libgit2.types.git_config** out_, libgit2.types.git_config* config); 381 382 /** 383 * Free the configuration and its associated memory and files 384 * 385 * Params: 386 * cfg = the configuration to free 387 */ 388 @GIT_EXTERN 389 void git_config_free(libgit2.types.git_config* cfg); 390 391 /** 392 * Get the git_config_entry of a config variable. 393 * 394 * Free the git_config_entry after use with `git_config_entry_free()`. 395 * 396 * Params: 397 * out_ = pointer to the variable git_config_entry 398 * cfg = where to look for the variable 399 * name = the variable's name 400 * 401 * Returns: 0 or an error code 402 */ 403 @GIT_EXTERN 404 int git_config_get_entry(.git_config_entry** out_, const (libgit2.types.git_config)* cfg, const (char)* name); 405 406 /** 407 * Get the value of an integer config variable. 408 * 409 * All config files will be looked into, in the order of their 410 * defined level. A higher level means a higher priority. The 411 * first occurrence of the variable will be returned here. 412 * 413 * Params: 414 * out_ = pointer to the variable where the value should be stored 415 * cfg = where to look for the variable 416 * name = the variable's name 417 * 418 * Returns: 0 or an error code 419 */ 420 @GIT_EXTERN 421 int git_config_get_int32(int* out_, const (libgit2.types.git_config)* cfg, const (char)* name); 422 423 /** 424 * Get the value of a long integer config variable. 425 * 426 * All config files will be looked into, in the order of their 427 * defined level. A higher level means a higher priority. The 428 * first occurrence of the variable will be returned here. 429 * 430 * Params: 431 * out_ = pointer to the variable where the value should be stored 432 * cfg = where to look for the variable 433 * name = the variable's name 434 * 435 * Returns: 0 or an error code 436 */ 437 @GIT_EXTERN 438 int git_config_get_int64(long* out_, const (libgit2.types.git_config)* cfg, const (char)* name); 439 440 /** 441 * Get the value of a boolean config variable. 442 * 443 * This function uses the usual C convention of 0 being false and 444 * anything else true. 445 * 446 * All config files will be looked into, in the order of their 447 * defined level. A higher level means a higher priority. The 448 * first occurrence of the variable will be returned here. 449 * 450 * Params: 451 * out_ = pointer to the variable where the value should be stored 452 * cfg = where to look for the variable 453 * name = the variable's name 454 * 455 * Returns: 0 or an error code 456 */ 457 @GIT_EXTERN 458 int git_config_get_bool(int* out_, const (libgit2.types.git_config)* cfg, const (char)* name); 459 460 /** 461 * Get the value of a path config variable. 462 * 463 * A leading '~' will be expanded to the global search path \(which 464 * defaults to the user's home directory but can be overridden via 465 * `git_libgit2_opts()`. 466 * 467 * All config files will be looked into, in the order of their 468 * defined level. A higher level means a higher priority. The 469 * first occurrence of the variable will be returned here. 470 * 471 * Params: 472 * out_ = the buffer in which to store the result 473 * cfg = where to look for the variable 474 * name = the variable's name 475 * 476 * Returns: 0 or an error code 477 */ 478 @GIT_EXTERN 479 int git_config_get_path(libgit2.buffer.git_buf* out_, const (libgit2.types.git_config)* cfg, const (char)* name); 480 481 /** 482 * Get the value of a string config variable. 483 * 484 * This function can only be used on snapshot config objects. The 485 * string is owned by the config and should not be freed by the 486 * user. The pointer will be valid until the config is freed. 487 * 488 * All config files will be looked into, in the order of their 489 * defined level. A higher level means a higher priority. The 490 * first occurrence of the variable will be returned here. 491 * 492 * Params: 493 * out_ = pointer to the string 494 * cfg = where to look for the variable 495 * name = the variable's name 496 * 497 * Returns: 0 or an error code 498 */ 499 @GIT_EXTERN 500 int git_config_get_string(const (char)** out_, const (libgit2.types.git_config)* cfg, const (char)* name); 501 502 /** 503 * Get the value of a string config variable. 504 * 505 * The value of the config will be copied into the buffer. 506 * 507 * All config files will be looked into, in the order of their 508 * defined level. A higher level means a higher priority. The 509 * first occurrence of the variable will be returned here. 510 * 511 * Params: 512 * out_ = buffer in which to store the string 513 * cfg = where to look for the variable 514 * name = the variable's name 515 * 516 * Returns: 0 or an error code 517 */ 518 @GIT_EXTERN 519 int git_config_get_string_buf(libgit2.buffer.git_buf* out_, const (libgit2.types.git_config)* cfg, const (char)* name); 520 521 /** 522 * Get each value of a multivar in a foreach callback 523 * 524 * The callback will be called on each variable found 525 * 526 * The regular expression is applied case-sensitively on the normalized form of 527 * the variable name: the section and variable parts are lower-cased. The 528 * subsection is left unchanged. 529 * 530 * Params: 531 * cfg = where to look for the variable 532 * name = the variable's name 533 * regexp = regular expression to filter which variables we're interested in. Use null to indicate all 534 * callback = the function to be called on each value of the variable 535 * payload = opaque pointer to pass to the callback 536 * 537 * Returns: 0 or an error code. 538 */ 539 @GIT_EXTERN 540 int git_config_get_multivar_foreach(const (libgit2.types.git_config)* cfg, const (char)* name, const (char)* regexp, .git_config_foreach_cb callback, void* payload); 541 542 /** 543 * Get each value of a multivar 544 * 545 * The regular expression is applied case-sensitively on the normalized form of 546 * the variable name: the section and variable parts are lower-cased. The 547 * subsection is left unchanged. 548 * 549 * Params: 550 * out_ = pointer to store the iterator 551 * cfg = where to look for the variable 552 * name = the variable's name 553 * regexp = regular expression to filter which variables we're interested in. Use null to indicate all 554 * 555 * Returns: 0 or an error code. 556 */ 557 @GIT_EXTERN 558 int git_config_multivar_iterator_new(.git_config_iterator** out_, const (libgit2.types.git_config)* cfg, const (char)* name, const (char)* regexp); 559 560 /** 561 * Return the current entry and advance the iterator 562 * 563 * The pointers returned by this function are valid until the next call 564 * to `git_config_next` or until the iterator is freed. 565 * 566 * Params: 567 * entry = pointer to store the entry 568 * iter = the iterator 569 * 570 * Returns: 0 or an error code. git_error_code.GIT_ITEROVER if the iteration has completed 571 */ 572 @GIT_EXTERN 573 int git_config_next(.git_config_entry** entry, .git_config_iterator* iter); 574 575 /** 576 * Free a config iterator 577 * 578 * Params: 579 * iter = the iterator to free 580 */ 581 @GIT_EXTERN 582 void git_config_iterator_free(.git_config_iterator* iter); 583 584 /** 585 * Set the value of an integer config variable in the config file 586 * with the highest level (usually the local one). 587 * 588 * Params: 589 * cfg = where to look for the variable 590 * name = the variable's name 591 * value = Integer value for the variable 592 * 593 * Returns: 0 or an error code 594 */ 595 @GIT_EXTERN 596 int git_config_set_int32(libgit2.types.git_config* cfg, const (char)* name, int value); 597 598 /** 599 * Set the value of a long integer config variable in the config file 600 * with the highest level (usually the local one). 601 * 602 * Params: 603 * cfg = where to look for the variable 604 * name = the variable's name 605 * value = Long integer value for the variable 606 * 607 * Returns: 0 or an error code 608 */ 609 @GIT_EXTERN 610 int git_config_set_int64(libgit2.types.git_config* cfg, const (char)* name, long value); 611 612 /** 613 * Set the value of a boolean config variable in the config file 614 * with the highest level (usually the local one). 615 * 616 * Params: 617 * cfg = where to look for the variable 618 * name = the variable's name 619 * value = the value to store 620 * 621 * Returns: 0 or an error code 622 */ 623 @GIT_EXTERN 624 int git_config_set_bool(libgit2.types.git_config* cfg, const (char)* name, int value); 625 626 /** 627 * Set the value of a string config variable in the config file 628 * with the highest level (usually the local one). 629 * 630 * A copy of the string is made and the user is free to use it 631 * afterwards. 632 * 633 * Params: 634 * cfg = where to look for the variable 635 * name = the variable's name 636 * value = the string to store. 637 * 638 * Returns: 0 or an error code 639 */ 640 @GIT_EXTERN 641 int git_config_set_string(libgit2.types.git_config* cfg, const (char)* name, const (char)* value); 642 643 /** 644 * Set a multivar in the local config file. 645 * 646 * The regular expression is applied case-sensitively on the value. 647 * 648 * Params: 649 * cfg = where to look for the variable 650 * name = the variable's name 651 * regexp = a regular expression to indicate which values to replace 652 * value = the new value. 653 * 654 * Returns: 0 or an error code. 655 */ 656 @GIT_EXTERN 657 int git_config_set_multivar(libgit2.types.git_config* cfg, const (char)* name, const (char)* regexp, const (char)* value); 658 659 /** 660 * Delete a config variable from the config file 661 * with the highest level (usually the local one). 662 * 663 * Params: 664 * cfg = the configuration 665 * name = the variable to delete 666 * 667 * Returns: 0 or an error code. 668 */ 669 @GIT_EXTERN 670 int git_config_delete_entry(libgit2.types.git_config* cfg, const (char)* name); 671 672 /** 673 * Deletes one or several entries from a multivar in the local config file. 674 * 675 * The regular expression is applied case-sensitively on the value. 676 * 677 * Params: 678 * cfg = where to look for the variables 679 * name = the variable's name 680 * regexp = a regular expression to indicate which values to delete 681 * 682 * Returns: 0 or an error code 683 */ 684 @GIT_EXTERN 685 int git_config_delete_multivar(libgit2.types.git_config* cfg, const (char)* name, const (char)* regexp); 686 687 /** 688 * Perform an operation on each config variable. 689 * 690 * The callback receives the normalized name and value of each variable 691 * in the config backend, and the data pointer passed to this function. 692 * If the callback returns a non-zero value, the function stops iterating 693 * and returns that value to the caller. 694 * 695 * The pointers passed to the callback are only valid as long as the 696 * iteration is ongoing. 697 * 698 * Params: 699 * cfg = where to get the variables from 700 * callback = the function to call on each variable 701 * payload = the data to pass to the callback 702 * 703 * Returns: 0 on success, non-zero callback return value, or error code 704 */ 705 @GIT_EXTERN 706 int git_config_foreach(const (libgit2.types.git_config)* cfg, .git_config_foreach_cb callback, void* payload); 707 708 /** 709 * Iterate over all the config variables 710 * 711 * Use `git_config_next` to advance the iteration and 712 * `git_config_iterator_free` when done. 713 * 714 * Params: 715 * out_ = pointer to store the iterator 716 * cfg = where to get the variables from 717 * 718 * Returns: 0 or an error code. 719 */ 720 @GIT_EXTERN 721 int git_config_iterator_new(.git_config_iterator** out_, const (libgit2.types.git_config)* cfg); 722 723 /** 724 * Iterate over all the config variables whose name matches a pattern 725 * 726 * Use `git_config_next` to advance the iteration and 727 * `git_config_iterator_free` when done. 728 * 729 * The regular expression is applied case-sensitively on the normalized form of 730 * the variable name: the section and variable parts are lower-cased. The 731 * subsection is left unchanged. 732 * 733 * Params: 734 * out_ = pointer to store the iterator 735 * cfg = where to ge the variables from 736 * regexp = regular expression to match the names 737 * 738 * Returns: 0 or an error code. 739 */ 740 @GIT_EXTERN 741 int git_config_iterator_glob_new(.git_config_iterator** out_, const (libgit2.types.git_config)* cfg, const (char)* regexp); 742 743 /** 744 * Perform an operation on each config variable matching a regular expression. 745 * 746 * This behaves like `git_config_foreach` with an additional filter of a 747 * regular expression that filters which config keys are passed to the 748 * callback. 749 * 750 * The regular expression is applied case-sensitively on the normalized form of 751 * the variable name: the section and variable parts are lower-cased. The 752 * subsection is left unchanged. 753 * 754 * The regular expression is applied case-sensitively on the normalized form of 755 * the variable name: the case-insensitive parts are lower-case. 756 * 757 * Params: 758 * cfg = where to get the variables from 759 * regexp = regular expression to match against config names 760 * callback = the function to call on each variable 761 * payload = the data to pass to the callback 762 * 763 * Returns: 0 or the return value of the callback which didn't return 0 764 */ 765 @GIT_EXTERN 766 int git_config_foreach_match(const (libgit2.types.git_config)* cfg, const (char)* regexp, .git_config_foreach_cb callback, void* payload); 767 768 /** 769 * Query the value of a config variable and return it mapped to 770 * an integer constant. 771 * 772 * This is a helper method to easily map different possible values 773 * to a variable to integer constants that easily identify them. 774 * 775 * A mapping array looks as follows: 776 * 777 * git_configmap[] autocrlf_mapping = { 778 * {GIT_CVAR_FALSE, null, GIT_AUTO_CRLF_FALSE}, 779 * {GIT_CVAR_TRUE, null, GIT_AUTO_CRLF_TRUE}, 780 * {GIT_CVAR_STRING, "input", GIT_AUTO_CRLF_INPUT}, 781 * {GIT_CVAR_STRING, "default", GIT_AUTO_CRLF_DEFAULT}}; 782 * 783 * On any "false" value for the variable (e.g. "false", "FALSE", "no"), the 784 * mapping will store `GIT_AUTO_CRLF_FALSE` in the `out` parameter. 785 * 786 * The same thing applies for any "true" value such as "true", "yes" or "1", 787 *storing the `GIT_AUTO_CRLF_TRUE` variable. 788 * 789 * Otherwise, if the value matches the string "input" (with case insensitive 790 *comparison), the given constant will be stored in `out`, and likewise for 791 *"default". 792 * 793 * If not a single match can be made to store in `out`, an error code will be 794 * returned. 795 * 796 * Params: 797 * out_ = place to store the result of the mapping 798 * cfg = config file to get the variables from 799 * name = name of the config variable to lookup 800 * maps = array of `git_configmap` objects specifying the possible mappings 801 * map_n = number of mapping objects in `maps` 802 * 803 * Returns: 0 on success, error code otherwise 804 */ 805 @GIT_EXTERN 806 int git_config_get_mapped(int* out_, const (libgit2.types.git_config)* cfg, const (char)* name, const (.git_configmap)* maps, size_t map_n); 807 808 /** 809 * Maps a string value to an integer constant 810 * 811 * Params: 812 * out_ = place to store the result of the parsing 813 * maps = array of `git_configmap` objects specifying the possible mappings 814 * map_n = number of mapping objects in `maps` 815 * value = value to parse 816 * 817 * Returns: 0 or an error code. 818 */ 819 @GIT_EXTERN 820 int git_config_lookup_map_value(int* out_, const (.git_configmap)* maps, size_t map_n, const (char)* value); 821 822 /** 823 * Parse a string value as a bool. 824 * 825 * Valid values for true are: 'true', 'yes', 'on', 1 or any 826 * number different from 0 827 * Valid values for false are: 'false', 'no', 'off', 0 828 * 829 * Params: 830 * out_ = place to store the result of the parsing 831 * value = value to parse 832 * 833 * Returns: 0 or an error code. 834 */ 835 @GIT_EXTERN 836 int git_config_parse_bool(int* out_, const (char)* value); 837 838 /** 839 * Parse a string value as an int32. 840 * 841 * An optional value suffix of 'k', 'm', or 'g' will 842 * cause the value to be multiplied by 1024, 1048576, 843 * or 1073741824 prior to output. 844 * 845 * Params: 846 * out_ = place to store the result of the parsing 847 * value = value to parse 848 * 849 * Returns: 0 or an error code. 850 */ 851 @GIT_EXTERN 852 int git_config_parse_int32(int* out_, const (char)* value); 853 854 /** 855 * Parse a string value as an int64. 856 * 857 * An optional value suffix of 'k', 'm', or 'g' will 858 * cause the value to be multiplied by 1024, 1048576, 859 * or 1073741824 prior to output. 860 * 861 * Params: 862 * out_ = place to store the result of the parsing 863 * value = value to parse 864 * 865 * Returns: 0 or an error code. 866 */ 867 @GIT_EXTERN 868 int git_config_parse_int64(long* out_, const (char)* value); 869 870 /** 871 * Parse a string value as a path. 872 * 873 * A leading '~' will be expanded to the global search path \(which 874 * defaults to the user's home directory but can be overridden via 875 * `git_libgit2_opts()`. 876 * 877 * If the value does not begin with a tilde, the input will be 878 * returned. 879 * 880 * Params: 881 * out_ = placae to store the result of parsing 882 * value = the path to evaluate 883 * 884 * Returns: 0 or an error code. 885 */ 886 @GIT_EXTERN 887 int git_config_parse_path(libgit2.buffer.git_buf* out_, const (char)* value); 888 889 /** 890 * Perform an operation on each config variable in a given config backend, 891 * matching a regular expression. 892 * 893 * This behaves like `git_config_foreach_match` except that only config 894 * entries from the given backend entry are enumerated. 895 * 896 * The regular expression is applied case-sensitively on the normalized form of 897 * the variable name: the section and variable parts are lower-cased. The 898 * subsection is left unchanged. 899 * 900 * Params: 901 * backend = where to get the variables from 902 * regexp = regular expression to match against config names (can be null) 903 * callback = the function to call on each variable 904 * payload = the data to pass to the callback 905 * 906 * Returns: 0 or an error code. 907 */ 908 @GIT_EXTERN 909 int git_config_backend_foreach_match(libgit2.types.git_config_backend* backend, const (char)* regexp, .git_config_foreach_cb callback, void* payload); 910 911 /** 912 * Lock the backend with the highest priority 913 * 914 * Locking disallows anybody else from writing to that backend. Any 915 * updates made after locking will not be visible to a reader until 916 * the file is unlocked. 917 * 918 * You can apply the changes by calling `git_transaction_commit()` 919 * before freeing the transaction. Either of these actions will unlock 920 * the config. 921 * 922 * Params: 923 * tx = the resulting transaction, use this to commit or undo the changes 924 * cfg = the configuration in which to lock 925 * 926 * Returns: 0 or an error code 927 */ 928 @GIT_EXTERN 929 int git_config_lock(libgit2.types.git_transaction** tx, libgit2.types.git_config* cfg); 930 931 /* @} */