]>
Commit | Line | Data |
---|---|---|
bb742ede | 1 | /* |
359fc2d2 | 2 | * Copyright (C) the libgit2 contributors. All rights reserved. |
bb742ede VM |
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 | */ | |
6d7bb4e0 CMN |
7 | #ifndef INCLUDE_config_h__ |
8 | #define INCLUDE_config_h__ | |
9 | ||
eae0bfdc PP |
10 | #include "common.h" |
11 | ||
c0335005 | 12 | #include "git2.h" |
6d7bb4e0 | 13 | #include "git2/config.h" |
c0335005 | 14 | #include "vector.h" |
44daec42 | 15 | #include "repository.h" |
6b45cb8a | 16 | |
8c7c5fa5 | 17 | #define GIT_CONFIG_FILENAME_PROGRAMDATA "config" |
73b51450 | 18 | #define GIT_CONFIG_FILENAME_SYSTEM "gitconfig" |
5540d947 RB |
19 | #define GIT_CONFIG_FILENAME_GLOBAL ".gitconfig" |
20 | #define GIT_CONFIG_FILENAME_XDG "config" | |
21 | ||
22 | #define GIT_CONFIG_FILENAME_INREPO "config" | |
01ad7b3a | 23 | #define GIT_CONFIG_FILE_MODE 0666 |
8adbf2ed | 24 | |
5d4cd003 | 25 | struct git_config { |
9462c471 | 26 | git_refcount rc; |
b0b527e0 | 27 | git_vector files; |
5d4cd003 CMN |
28 | }; |
29 | ||
a4b75dcf CMN |
30 | extern int git_config__global_location(git_buf *buf); |
31 | ||
aba70781 | 32 | extern int git_config_rename_section( |
33 | git_repository *repo, | |
34 | const char *old_section_name, /* eg "branch.dummy" */ | |
35 | const char *new_section_name); /* NULL to drop the old section */ | |
36 | ||
d36451c9 | 37 | /** |
38 | * Create a configuration file backend for ondisk files | |
39 | * | |
40 | * These are the normal `.gitconfig` files that Core Git | |
41 | * processes. Note that you first have to add this file to a | |
42 | * configuration object before you can query it for configuration | |
43 | * variables. | |
44 | * | |
45 | * @param out the new backend | |
46 | * @param path where the config file is located | |
47 | */ | |
5173ea92 | 48 | extern int git_config_file__ondisk(git_config_backend **out, const char *path); |
d36451c9 | 49 | |
f4be8209 CMN |
50 | extern int git_config__normalize_name(const char *in, char **out); |
51 | ||
9f77b3f6 RB |
52 | /* internal only: does not normalize key and sets out to NULL if not found */ |
53 | extern int git_config__lookup_entry( | |
9a97f49e | 54 | git_config_entry **out, |
9f77b3f6 RB |
55 | const git_config *cfg, |
56 | const char *key, | |
57 | bool no_errors); | |
58 | ||
8286300a RB |
59 | /* internal only: update and/or delete entry string with constraints */ |
60 | extern int git_config__update_entry( | |
61 | git_config *cfg, | |
62 | const char *key, | |
63 | const char *value, | |
64 | bool overwrite_existing, | |
65 | bool only_if_existing); | |
66 | ||
9f77b3f6 RB |
67 | /* |
68 | * Lookup functions that cannot fail. These functions look up a config | |
69 | * value and return a fallback value if the value is missing or if any | |
70 | * failures occur while trying to access the value. | |
71 | */ | |
72 | ||
9a97f49e | 73 | extern char *git_config__get_string_force( |
9f77b3f6 RB |
74 | const git_config *cfg, const char *key, const char *fallback_value); |
75 | ||
76 | extern int git_config__get_bool_force( | |
77 | const git_config *cfg, const char *key, int fallback_value); | |
78 | ||
79 | extern int git_config__get_int_force( | |
80 | const git_config *cfg, const char *key, int fallback_value); | |
f4be8209 | 81 | |
2b52a0bf RB |
82 | /* API for repository cvar-style lookups from config - not cached, but |
83 | * uses cvar value maps and fallbacks | |
84 | */ | |
85 | extern int git_config__cvar( | |
86 | int *out, git_config *config, git_cvar_cached cvar); | |
87 | ||
15c38103 CMN |
88 | /** |
89 | * The opposite of git_config_lookup_map_value, we take an enum value | |
90 | * and map it to the string or bool value on the config. | |
91 | */ | |
92 | int git_config_lookup_map_enum(git_cvar_t *type_out, const char **str_out, | |
93 | const git_cvar_map *maps, size_t map_n, int enum_val); | |
5340d63d CMN |
94 | |
95 | /** | |
96 | * Unlock the backend with the highest priority | |
97 | * | |
98 | * Unlocking will allow other writers to updat the configuration | |
99 | * file. Optionally, any changes performed since the lock will be | |
100 | * applied to the configuration. | |
101 | * | |
102 | * @param cfg the configuration | |
103 | * @param commit boolean which indicates whether to commit any changes | |
104 | * done since locking | |
105 | * @return 0 or an error code | |
106 | */ | |
107 | GIT_EXTERN(int) git_config_unlock(git_config *cfg, int commit); | |
108 | ||
5d4cd003 | 109 | #endif |