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 module libgit2_d.sys.config;
8 
9 
10 private static import libgit2_d.config;
11 private static import libgit2_d.types;
12 
13 /**
14  * @file git2/sys/config.h
15  * @brief Git config backend routines
16  * @defgroup git_backend Git custom backend APIs
17  * @ingroup Git
18  * @{
19  */
20 extern (C):
21 nothrow @nogc:
22 package(libgit2_d):
23 
24 /**
25  * Every iterator must have this struct as its first element, so the
26  * API can talk to it. You'd define your iterator as
27  *
28  *     struct my_iterator {
29  *             .git_config_iterator parent;
30  *             ...
31  *     }
32  *
33  * and assign `iter->parent.backend` to your `git_config_backend`.
34  */
35 struct git_config_iterator
36 {
37 	.git_config_backend* backend;
38 	uint flags;
39 
40 	/**
41 	 * Return the current entry and advance the iterator. The
42 	 * memory belongs to the library.
43 	 */
44 	int function(libgit2_d.config.git_config_entry** entry, .git_config_iterator* iter) next;
45 
46 	/**
47 	 * Free the iterator
48 	 */
49 	void function(.git_config_iterator* iter) free;
50 }
51 
52 /**
53  * Generic backend that implements the interface to
54  * access a configuration file
55  */
56 struct git_config_backend
57 {
58 	uint version_;
59 
60 	/**
61 	 * True if this backend is for a snapshot
62 	 */
63 	int readonly;
64 
65 	libgit2_d.types.git_config* cfg;
66 
67 	/* Open means open the file/database and parse if necessary */
68 	int function(.git_config_backend*, libgit2_d.config.git_config_level_t level, const (libgit2_d.types.git_repository)* repo) open;
69 	int function(.git_config_backend*, const (char)* key, libgit2_d.config.git_config_entry** entry) get;
70 	int function(.git_config_backend*, const (char)* key, const (char)* value) set;
71 	int function(.git_config_backend* cfg, const (char)* name, const (char)* regexp, const (char)* value) set_multivar;
72 	int function(.git_config_backend*, const (char)* key) del;
73 	int function(.git_config_backend*, const (char)* key, const (char)* regexp) del_multivar;
74 	int function(.git_config_iterator**,  .git_config_backend*) iterator;
75 
76 	/**
77 	 * Produce a read-only version of this backend
78 	 */
79 	int function(.git_config_backend**,  .git_config_backend*) snapshot;
80 
81 	/**
82 	 * Lock this backend.
83 	 *
84 	 * Prevent any writes to the data store backing this
85 	 * backend. Any updates must not be visible to any other
86 	 * readers.
87 	 */
88 	int function(.git_config_backend*) lock;
89 
90 	/**
91 	 * Unlock the data store backing this backend. If success is
92 	 * true, the changes should be committed, otherwise rolled
93 	 * back.
94 	 */
95 	int function(.git_config_backend*, int success) unlock;
96 
97 	void function(.git_config_backend*) free;
98 }
99 
100 enum GIT_CONFIG_BACKEND_VERSION = 1;
101 
102 pragma(inline, true)
103 pure nothrow @safe @nogc
104 .git_config_backend GIT_CONFIG_BACKEND_INIT()
105 
106 	do
107 	{
108 		.git_config_backend OUTPUT =
109 		{
110 			version_: .GIT_CONFIG_BACKEND_VERSION,
111 		};
112 
113 		return OUTPUT;
114 	}
115 
116 /**
117  * Initializes a `git_config_backend` with default values. Equivalent to
118  * creating an instance with GIT_CONFIG_BACKEND_INIT.
119  *
120  * @param backend the `git_config_backend` struct to initialize.
121  * @param version Version of struct; pass `GIT_CONFIG_BACKEND_VERSION`
122  * @return Zero on success; -1 on failure.
123  */
124 //GIT_EXTERN
125 int git_config_init_backend(.git_config_backend* backend, uint version_);
126 
127 /**
128  * Add a generic config file instance to an existing config
129  *
130  * Note that the configuration object will free the file
131  * automatically.
132  *
133  * Further queries on this config object will access each
134  * of the config file instances in order (instances with
135  * a higher priority level will be accessed first).
136  *
137  * @param cfg the configuration to add the file to
138  * @param file the configuration file (backend) to add
139  * @param level the priority level of the backend
140  * @param repo optional repository to allow parsing of
141  *  conditional includes
142  * @param force if a config file already exists for the given
143  *  priority level, replace it
144  * @return 0 on success, git_error_code.GIT_EEXISTS when adding more than one file
145  *  for a given priority level (and force_replace set to 0), or error code
146  */
147 //GIT_EXTERN
148 int git_config_add_backend(libgit2_d.types.git_config* cfg, .git_config_backend* file, libgit2_d.config.git_config_level_t level, const (libgit2_d.types.git_repository)* repo, int force);
149 
150 /** @} */