]>
Commit | Line | Data |
---|---|---|
ac3d33df JK |
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_file_h__ | |
8 | #define INCLUDE_config_file_h__ | |
9 | ||
10 | #include "common.h" | |
11 | ||
12 | #include "git2/sys/config.h" | |
13 | #include "git2/config.h" | |
14 | ||
15 | /** | |
16 | * Create a configuration file backend for ondisk files | |
17 | * | |
18 | * These are the normal `.gitconfig` files that Core Git | |
19 | * processes. Note that you first have to add this file to a | |
20 | * configuration object before you can query it for configuration | |
21 | * variables. | |
22 | * | |
23 | * @param out the new backend | |
24 | * @param path where the config file is located | |
25 | */ | |
26 | extern int git_config_backend_from_file(git_config_backend **out, const char *path); | |
27 | ||
0c9c969a UG |
28 | /** |
29 | * Create a readonly configuration file backend from another backend | |
30 | * | |
31 | * This copies the complete contents of the source backend to the | |
32 | * new backend. The new backend will be completely read-only and | |
33 | * cannot be modified. | |
34 | * | |
35 | * @param out the new snapshotted backend | |
36 | * @param source the backend to copy | |
37 | */ | |
38 | extern int git_config_backend_snapshot(git_config_backend **out, git_config_backend *source); | |
39 | ||
ac3d33df JK |
40 | /** |
41 | * Create an in-memory configuration file backend | |
42 | * | |
43 | * @param out the new backend | |
44 | * @param cfg the configuration that is to be parsed | |
45 | * @param len the length of the string pointed to by `cfg` | |
46 | */ | |
47 | extern int git_config_backend_from_string(git_config_backend **out, const char *cfg, size_t len); | |
48 | ||
49 | GIT_INLINE(int) git_config_backend_open(git_config_backend *cfg, unsigned int level, const git_repository *repo) | |
50 | { | |
51 | return cfg->open(cfg, level, repo); | |
52 | } | |
53 | ||
54 | GIT_INLINE(void) git_config_backend_free(git_config_backend *cfg) | |
55 | { | |
56 | if (cfg) | |
57 | cfg->free(cfg); | |
58 | } | |
59 | ||
60 | GIT_INLINE(int) git_config_backend_get_string( | |
61 | git_config_entry **out, git_config_backend *cfg, const char *name) | |
62 | { | |
63 | return cfg->get(cfg, name, out); | |
64 | } | |
65 | ||
66 | GIT_INLINE(int) git_config_backend_set_string( | |
67 | git_config_backend *cfg, const char *name, const char *value) | |
68 | { | |
69 | return cfg->set(cfg, name, value); | |
70 | } | |
71 | ||
72 | GIT_INLINE(int) git_config_backend_delete( | |
73 | git_config_backend *cfg, const char *name) | |
74 | { | |
75 | return cfg->del(cfg, name); | |
76 | } | |
77 | ||
78 | GIT_INLINE(int) git_config_backend_foreach( | |
79 | git_config_backend *cfg, | |
80 | int (*fn)(const git_config_entry *entry, void *data), | |
81 | void *data) | |
82 | { | |
83 | return git_config_backend_foreach_match(cfg, NULL, fn, data); | |
84 | } | |
85 | ||
86 | GIT_INLINE(int) git_config_backend_lock(git_config_backend *cfg) | |
87 | { | |
88 | return cfg->lock(cfg); | |
89 | } | |
90 | ||
91 | GIT_INLINE(int) git_config_backend_unlock(git_config_backend *cfg, int success) | |
92 | { | |
93 | return cfg->unlock(cfg, success); | |
94 | } | |
95 | ||
96 | #endif |