]> git.proxmox.com Git - libgit2.git/blob - src/config.h
New upstream version 1.4.3+dfsg.1
[libgit2.git] / src / config.h
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 #ifndef INCLUDE_config_h__
8 #define INCLUDE_config_h__
9
10 #include "common.h"
11
12 #include "git2.h"
13 #include "git2/config.h"
14 #include "vector.h"
15 #include "repository.h"
16
17 #define GIT_CONFIG_FILENAME_PROGRAMDATA "config"
18 #define GIT_CONFIG_FILENAME_SYSTEM "gitconfig"
19 #define GIT_CONFIG_FILENAME_GLOBAL ".gitconfig"
20 #define GIT_CONFIG_FILENAME_XDG "config"
21
22 #define GIT_CONFIG_FILENAME_INREPO "config"
23 #define GIT_CONFIG_FILE_MODE 0666
24
25 struct git_config {
26 git_refcount rc;
27 git_vector backends;
28 };
29
30 extern int git_config__global_location(git_str *buf);
31
32 extern int git_config__find_global(git_str *path);
33 extern int git_config__find_xdg(git_str *path);
34 extern int git_config__find_system(git_str *path);
35 extern int git_config__find_programdata(git_str *path);
36
37 extern int git_config_rename_section(
38 git_repository *repo,
39 const char *old_section_name, /* eg "branch.dummy" */
40 const char *new_section_name); /* NULL to drop the old section */
41
42 extern int git_config__normalize_name(const char *in, char **out);
43
44 /* internal only: does not normalize key and sets out to NULL if not found */
45 extern int git_config__lookup_entry(
46 git_config_entry **out,
47 const git_config *cfg,
48 const char *key,
49 bool no_errors);
50
51 /* internal only: update and/or delete entry string with constraints */
52 extern int git_config__update_entry(
53 git_config *cfg,
54 const char *key,
55 const char *value,
56 bool overwrite_existing,
57 bool only_if_existing);
58
59 int git_config__get_path(
60 git_str *out,
61 const git_config *cfg,
62 const char *name);
63
64 int git_config__get_string_buf(
65 git_str *out, const git_config *cfg, const char *name);
66
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
73 extern char *git_config__get_string_force(
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);
81
82 /* API for repository configmap-style lookups from config - not cached, but
83 * uses configmap value maps and fallbacks
84 */
85 extern int git_config__configmap_lookup(
86 int *out, git_config *config, git_configmap_item item);
87
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_configmap_t *type_out,
93 const char **str_out, const git_configmap *maps,
94 size_t map_n, int enum_val);
95
96 /**
97 * Unlock the backend with the highest priority
98 *
99 * Unlocking will allow other writers to update the configuration
100 * file. Optionally, any changes performed since the lock will be
101 * applied to the configuration.
102 *
103 * @param cfg the configuration
104 * @param commit boolean which indicates whether to commit any changes
105 * done since locking
106 * @return 0 or an error code
107 */
108 GIT_EXTERN(int) git_config_unlock(git_config *cfg, int commit);
109
110 #endif