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.common;
8 
9 
10 private static import core.stdc.config;
11 
12 //#include <time.h>
13 
14 //#if defined(_MSC_VER) && _MSC_VER < 1800
15 	//public import core.stdc.stdint;
16 //#elif !defined(__CLANG_INTTYPES_H)
17 	//#include <inttypes.h>
18 //#endif
19 
20 /** Declare a function's takes printf style arguments. */
21 //#if defined(__GNUC__)
22 	//#define GIT_FORMAT_PRINTF(a, b) __attribute__((format(printf, a, b)))
23 //#else
24 	//#define GIT_FORMAT_PRINTF(a, b) /* empty */
25 //#endif
26 
27 version (Cygwin) {
28 	enum GIT_WIN32 = 0;
29 } else version (Windows) {
30 	enum GIT_WIN32 = 1;
31 } else {
32 	enum GIT_WIN32 = 0;
33 }
34 
35 //#if defined(__amigaos4__)
36 	//#include <netinet/in.h>
37 //#endif
38 
39 /**
40  * @file git2/common.h
41  * @brief Git common platform definitions
42  * @defgroup git_common Git common platform definitions
43  * @ingroup Git
44  * @{
45  */
46 
47 extern (C):
48 nothrow @nogc:
49 public:
50 
51 /**
52  * The separator used in path list strings (ie like in the PATH
53  * environment variable). A semi-colon ";" is used on Windows, and
54  * a colon ":" for all other systems.
55  */
56 static if (.GIT_WIN32) {
57 	enum GIT_PATH_LIST_SEPARATOR = ';';
58 } else {
59 	enum GIT_PATH_LIST_SEPARATOR = ':';
60 }
61 
62 /**
63  * The maximum length of a valid git path.
64  */
65 enum GIT_PATH_MAX = 4096;
66 
67 /**
68  * The string representation of the null object ID.
69  */
70 enum GIT_OID_HEX_ZERO = "0000000000000000000000000000000000000000";
71 
72 /**
73  * Return the version of the libgit2 library
74  * being currently used.
75  *
76  * Params:
77  *      major = Store the major version number
78  *      minor = Store the minor version number
79  *      rev = Store the revision (patch) number
80  *
81  * Returns: 0 on success or an error code on failure
82  */
83 //GIT_EXTERN
84 int git_libgit2_version(int* major, int* minor, int* rev);
85 
86 /**
87  * Combinations of these values describe the features with which libgit2
88  * was compiled
89  */
90 enum git_feature_t
91 {
92 	/**
93 	 * If set, libgit2 was built thread-aware and can be safely used from multiple
94 	 * threads.
95 	 */
96 	GIT_FEATURE_THREADS = 1 << 0,
97 
98 	/**
99 	 * If set, libgit2 was built with and linked against a TLS implementation.
100 	 * Custom TLS streams may still be added by the user to support HTTPS
101 	 * regardless of this.
102 	 */
103 	GIT_FEATURE_HTTPS = 1 << 1,
104 
105 	/**
106 	 * If set, libgit2 was built with and linked against libssh2. A custom
107 	 * transport may still be added by the user to support libssh2 regardless of
108 	 * this.
109 	 */
110 	GIT_FEATURE_SSH = 1 << 2,
111 
112 	/**
113 	 * If set, libgit2 was built with support for sub-second resolution in file
114 	 * modification times.
115 	 */
116 	GIT_FEATURE_NSEC = 1 << 3,
117 }
118 
119 //Declaration name in C language
120 enum
121 {
122 	GIT_FEATURE_THREADS = .git_feature_t.GIT_FEATURE_THREADS,
123 	GIT_FEATURE_HTTPS = .git_feature_t.GIT_FEATURE_HTTPS,
124 	GIT_FEATURE_SSH = .git_feature_t.GIT_FEATURE_SSH,
125 	GIT_FEATURE_NSEC = .git_feature_t.GIT_FEATURE_NSEC,
126 }
127 
128 /**
129  * Query compile time options for libgit2.
130  *
131  * Returns: A combination of GIT_FEATURE_* values.
132  *
133  * - git_feature_t.GIT_FEATURE_THREADS
134  *   Libgit2 was compiled with thread support. Note that thread support is
135  *   still to be seen as a 'work in progress' - basic object lookups are
136  *   believed to be threadsafe, but other operations may not be.
137  *
138  * - git_feature_t.GIT_FEATURE_HTTPS
139  *   Libgit2 supports the https:// protocol. This requires the openssl
140  *   library to be found when compiling libgit2.
141  *
142  * - git_feature_t.GIT_FEATURE_SSH
143  *   Libgit2 supports the SSH protocol for network operations. This requires
144  *   the libssh2 library to be found when compiling libgit2
145  */
146 //GIT_EXTERN
147 int git_libgit2_features();
148 
149 /**
150  * Global library options
151  *
152  * These are used to select which global option to set or get and are
153  * used in `git_libgit2_opts()`.
154  */
155 enum git_libgit2_opt_t
156 {
157 	GIT_OPT_GET_MWINDOW_SIZE,
158 	GIT_OPT_SET_MWINDOW_SIZE,
159 	GIT_OPT_GET_MWINDOW_MAPPED_LIMIT,
160 	GIT_OPT_SET_MWINDOW_MAPPED_LIMIT,
161 	GIT_OPT_GET_SEARCH_PATH,
162 	GIT_OPT_SET_SEARCH_PATH,
163 	GIT_OPT_SET_CACHE_OBJECT_LIMIT,
164 	GIT_OPT_SET_CACHE_MAX_SIZE,
165 	GIT_OPT_ENABLE_CACHING,
166 	GIT_OPT_GET_CACHED_MEMORY,
167 	GIT_OPT_GET_TEMPLATE_PATH,
168 	GIT_OPT_SET_TEMPLATE_PATH,
169 	GIT_OPT_SET_SSL_CERT_LOCATIONS,
170 	GIT_OPT_SET_USER_AGENT,
171 	GIT_OPT_ENABLE_STRICT_OBJECT_CREATION,
172 	GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION,
173 	GIT_OPT_SET_SSL_CIPHERS,
174 	GIT_OPT_GET_USER_AGENT,
175 	GIT_OPT_ENABLE_OFS_DELTA,
176 	GIT_OPT_ENABLE_FSYNC_GITDIR,
177 	GIT_OPT_GET_WINDOWS_SHAREMODE,
178 	GIT_OPT_SET_WINDOWS_SHAREMODE,
179 	GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION,
180 	GIT_OPT_SET_ALLOCATOR,
181 	GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY,
182 	GIT_OPT_GET_PACK_MAX_OBJECTS,
183 	GIT_OPT_SET_PACK_MAX_OBJECTS,
184 	GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS,
185 	GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE,
186 	GIT_OPT_GET_MWINDOW_FILE_LIMIT,
187 	GIT_OPT_SET_MWINDOW_FILE_LIMIT,
188 }
189 
190 //Declaration name in C language
191 enum
192 {
193 	GIT_OPT_GET_MWINDOW_SIZE = .git_libgit2_opt_t.GIT_OPT_GET_MWINDOW_SIZE,
194 	GIT_OPT_SET_MWINDOW_SIZE = .git_libgit2_opt_t.GIT_OPT_SET_MWINDOW_SIZE,
195 	GIT_OPT_GET_MWINDOW_MAPPED_LIMIT = .git_libgit2_opt_t.GIT_OPT_GET_MWINDOW_MAPPED_LIMIT,
196 	GIT_OPT_SET_MWINDOW_MAPPED_LIMIT = .git_libgit2_opt_t.GIT_OPT_SET_MWINDOW_MAPPED_LIMIT,
197 	GIT_OPT_GET_SEARCH_PATH = .git_libgit2_opt_t.GIT_OPT_GET_SEARCH_PATH,
198 	GIT_OPT_SET_SEARCH_PATH = .git_libgit2_opt_t.GIT_OPT_SET_SEARCH_PATH,
199 	GIT_OPT_SET_CACHE_OBJECT_LIMIT = .git_libgit2_opt_t.GIT_OPT_SET_CACHE_OBJECT_LIMIT,
200 	GIT_OPT_SET_CACHE_MAX_SIZE = .git_libgit2_opt_t.GIT_OPT_SET_CACHE_MAX_SIZE,
201 	GIT_OPT_ENABLE_CACHING = .git_libgit2_opt_t.GIT_OPT_ENABLE_CACHING,
202 	GIT_OPT_GET_CACHED_MEMORY = .git_libgit2_opt_t.GIT_OPT_GET_CACHED_MEMORY,
203 	GIT_OPT_GET_TEMPLATE_PATH = .git_libgit2_opt_t.GIT_OPT_GET_TEMPLATE_PATH,
204 	GIT_OPT_SET_TEMPLATE_PATH = .git_libgit2_opt_t.GIT_OPT_SET_TEMPLATE_PATH,
205 	GIT_OPT_SET_SSL_CERT_LOCATIONS = .git_libgit2_opt_t.GIT_OPT_SET_SSL_CERT_LOCATIONS,
206 	GIT_OPT_SET_USER_AGENT = .git_libgit2_opt_t.GIT_OPT_SET_USER_AGENT,
207 	GIT_OPT_ENABLE_STRICT_OBJECT_CREATION = .git_libgit2_opt_t.GIT_OPT_ENABLE_STRICT_OBJECT_CREATION,
208 	GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION = .git_libgit2_opt_t.GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION,
209 	GIT_OPT_SET_SSL_CIPHERS = .git_libgit2_opt_t.GIT_OPT_SET_SSL_CIPHERS,
210 	GIT_OPT_GET_USER_AGENT = .git_libgit2_opt_t.GIT_OPT_GET_USER_AGENT,
211 	GIT_OPT_ENABLE_OFS_DELTA = .git_libgit2_opt_t.GIT_OPT_ENABLE_OFS_DELTA,
212 	GIT_OPT_ENABLE_FSYNC_GITDIR = .git_libgit2_opt_t.GIT_OPT_ENABLE_FSYNC_GITDIR,
213 	GIT_OPT_GET_WINDOWS_SHAREMODE = .git_libgit2_opt_t.GIT_OPT_GET_WINDOWS_SHAREMODE,
214 	GIT_OPT_SET_WINDOWS_SHAREMODE = .git_libgit2_opt_t.GIT_OPT_SET_WINDOWS_SHAREMODE,
215 	GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION = .git_libgit2_opt_t.GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION,
216 	GIT_OPT_SET_ALLOCATOR = .git_libgit2_opt_t.GIT_OPT_SET_ALLOCATOR,
217 	GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY = .git_libgit2_opt_t.GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY,
218 	GIT_OPT_GET_PACK_MAX_OBJECTS = .git_libgit2_opt_t.GIT_OPT_GET_PACK_MAX_OBJECTS,
219 	GIT_OPT_SET_PACK_MAX_OBJECTS = .git_libgit2_opt_t.GIT_OPT_SET_PACK_MAX_OBJECTS,
220 	GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS = .git_libgit2_opt_t.GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS,
221 	GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE = .git_libgit2_opt_t.GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE,
222 	GIT_OPT_GET_MWINDOW_FILE_LIMIT = .git_libgit2_opt_t.GIT_OPT_GET_MWINDOW_FILE_LIMIT,
223 	GIT_OPT_SET_MWINDOW_FILE_LIMIT = .git_libgit2_opt_t.GIT_OPT_SET_MWINDOW_FILE_LIMIT,
224 }
225 
226 /**
227  * Set or query a library global option
228  *
229  * Available options:
230  *
231  *	* opts(GIT_OPT_GET_MWINDOW_SIZE, size_t *):
232  *
233  *		> Get the maximum mmap window size
234  *
235  *	* opts(GIT_OPT_SET_MWINDOW_SIZE, size_t):
236  *
237  *		> Set the maximum mmap window size
238  *
239  *	* opts(GIT_OPT_GET_MWINDOW_MAPPED_LIMIT, size_t *):
240  *
241  *		> Get the maximum memory that will be mapped in total by the library
242  *
243  *	* opts(GIT_OPT_SET_MWINDOW_MAPPED_LIMIT, size_t):
244  *
245  *		> Set the maximum amount of memory that can be mapped at any time
246  *		> by the library
247  *
248  *	* opts(GIT_OPT_GET_MWINDOW_FILE_LIMIT, size_t *):
249  *
250  *		> Get the maximum number of files that will be mapped at any time by the
251  *		> library
252  *
253  *	* opts(GIT_OPT_SET_MWINDOW_FILE_LIMIT, size_t):
254  *
255  *		> Set the maximum number of files that can be mapped at any time
256  *		> by the library. The default (0) is unlimited.
257  *
258  *	* opts(GIT_OPT_GET_SEARCH_PATH, int level, git_buf *buf)
259  *
260  *		> Get the search path for a given level of config data.  "level" must
261  *		> be one of `GIT_CONFIG_LEVEL_SYSTEM`, `GIT_CONFIG_LEVEL_GLOBAL`,
262  *		> `GIT_CONFIG_LEVEL_XDG`, or `GIT_CONFIG_LEVEL_PROGRAMDATA`.
263  *		> The search path is written to the `out` buffer.
264  *
265  *	* opts(GIT_OPT_SET_SEARCH_PATH, int level, const char *path)
266  *
267  *		> Set the search path for a level of config data.  The search path
268  *		> applied to shared attributes and ignore files, too.
269  *		>
270  *		> - `path` lists directories delimited by GIT_PATH_LIST_SEPARATOR.
271  *		>   Pass NULL to reset to the default (generally based on environment
272  *		>   variables).  Use magic path `$PATH` to include the old value
273  *		>   of the path (if you want to prepend or append, for instance).
274  *		>
275  *		> - `level` must be `GIT_CONFIG_LEVEL_SYSTEM`,
276  *		>   `GIT_CONFIG_LEVEL_GLOBAL`, `GIT_CONFIG_LEVEL_XDG`, or
277  *		>   `GIT_CONFIG_LEVEL_PROGRAMDATA`.
278  *
279  *	* opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, git_object_t type, size_t size)
280  *
281  *		> Set the maximum data size for the given type of object to be
282  *		> considered eligible for caching in memory.  Setting to value to
283  *		> zero means that that type of object will not be cached.
284  *		> Defaults to 0 for GIT_OBJECT_BLOB (i.e. won't cache blobs) and 4k
285  *		> for GIT_OBJECT_COMMIT, GIT_OBJECT_TREE, and GIT_OBJECT_TAG.
286  *
287  *	* opts(GIT_OPT_SET_CACHE_MAX_SIZE, ssize_t max_storage_bytes)
288  *
289  *		> Set the maximum total data size that will be cached in memory
290  *		> across all repositories before libgit2 starts evicting objects
291  *		> from the cache.  This is a soft limit, in that the library might
292  *		> briefly exceed it, but will start aggressively evicting objects
293  *		> from cache when that happens.  The default cache size is 256MB.
294  *
295  *	* opts(GIT_OPT_ENABLE_CACHING, int enabled)
296  *
297  *		> Enable or disable caching completely.
298  *		>
299  *		> Because caches are repository-specific, disabling the cache
300  *		> cannot immediately clear all cached objects, but each cache will
301  *		> be cleared on the next attempt to update anything in it.
302  *
303  *	* opts(GIT_OPT_GET_CACHED_MEMORY, ssize_t *current, ssize_t *allowed)
304  *
305  *		> Get the current bytes in cache and the maximum that would be
306  *		> allowed in the cache.
307  *
308  *	* opts(GIT_OPT_GET_TEMPLATE_PATH, git_buf *out)
309  *
310  *		> Get the default template path.
311  *		> The path is written to the `out` buffer.
312  *
313  *	* opts(GIT_OPT_SET_TEMPLATE_PATH, const char *path)
314  *
315  *		> Set the default template path.
316  *		>
317  *		> - `path` directory of template.
318  *
319  *	* opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, const char *file, const char *path)
320  *
321  *		> Set the SSL certificate-authority locations.
322  *		>
323  *		> - `file` is the location of a file containing several
324  *		>   certificates concatenated together.
325  *		> - `path` is the location of a directory holding several
326  *		>   certificates, one per file.
327  *		>
328  * 		> Either parameter may be `NULL`, but not both.
329  *
330  *	* opts(GIT_OPT_SET_USER_AGENT, const char *user_agent)
331  *
332  *		> Set the value of the User-Agent header.  This value will be
333  *		> appended to "git/1.0", for compatibility with other git clients.
334  *		>
335  *		> - `user_agent` is the value that will be delivered as the
336  *		>   User-Agent header on HTTP requests.
337  *
338  *	* opts(GIT_OPT_SET_WINDOWS_SHAREMODE, core.stdc.config.c_ulong value)
339  *
340  *		> Set the share mode used when opening files on Windows.
341  *		> For more information, see the documentation for CreateFile.
342  *		> The default is: FILE_SHARE_READ | FILE_SHARE_WRITE.  This is
343  *		> ignored and unused on non-Windows platforms.
344  *
345  *	* opts(GIT_OPT_GET_WINDOWS_SHAREMODE, core.stdc.config.c_ulong *value)
346  *
347  *		> Get the share mode used when opening files on Windows.
348  *
349  *	* opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, int enabled)
350  *
351  *		> Enable strict input validation when creating new objects
352  *		> to ensure that all inputs to the new objects are valid.  For
353  *		> example, when this is enabled, the parent(s) and tree inputs
354  *		> will be validated when creating a new commit.  This defaults
355  *		> to enabled.
356  *
357  *	* opts(GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION, int enabled)
358  *
359  *		> Validate the target of a symbolic ref when creating it.  For
360  *		> example, `foobar` is not a valid ref, therefore `foobar` is
361  *		> not a valid target for a symbolic ref by default, whereas
362  *		> `refs/heads/foobar` is.  Disabling this bypasses validation
363  *		> so that an arbitrary strings such as `foobar` can be used
364  *		> for a symbolic ref target.  This defaults to enabled.
365  *
366  *	* opts(GIT_OPT_SET_SSL_CIPHERS, const char *ciphers)
367  *
368  *		> Set the SSL ciphers use for HTTPS connections.
369  *		>
370  *		> - `ciphers` is the list of ciphers that are eanbled.
371  *
372  *	* opts(GIT_OPT_ENABLE_OFS_DELTA, int enabled)
373  *
374  *		> Enable or disable the use of "offset deltas" when creating packfiles,
375  *		> and the negotiation of them when talking to a remote server.
376  *		> Offset deltas store a delta base location as an offset into the
377  *		> packfile from the current location, which provides a shorter encoding
378  *		> and thus smaller resultant packfiles.
379  *		> Packfiles containing offset deltas can still be read.
380  *		> This defaults to enabled.
381  *
382  *	* opts(GIT_OPT_ENABLE_FSYNC_GITDIR, int enabled)
383  *
384  *		> Enable synchronized writes of files in the gitdir using `fsync`
385  *		> (or the platform equivalent) to ensure that new object data
386  *		> is written to permanent storage, not simply cached.  This
387  *		> defaults to disabled.
388  *
389  *	 opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, int enabled)
390  *
391  *		> Enable strict verification of object hashsums when reading
392  *		> objects from disk. This may impact performance due to an
393  *		> additional checksum calculation on each object. This defaults
394  *		> to enabled.
395  *
396  *	 opts(GIT_OPT_SET_ALLOCATOR, git_allocator *allocator)
397  *
398  *		> Set the memory allocator to a different memory allocator. This
399  *		> allocator will then be used to make all memory allocations for
400  *		> libgit2 operations.  If the given `allocator` is NULL, then the
401  *		> system default will be restored.
402  *
403  *	 opts(GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY, int enabled)
404  *
405  *		> Ensure that there are no unsaved changes in the index before
406  *		> beginning any operation that reloads the index from disk (eg,
407  *		> checkout).  If there are unsaved changes, the instruction will
408  *		> fail.  (Using the FORCE flag to checkout will still overwrite
409  *		> these changes.)
410  *
411  *	 opts(GIT_OPT_GET_PACK_MAX_OBJECTS, size_t *out)
412  *
413  *		> Get the maximum number of objects libgit2 will allow in a pack
414  *		> file when downloading a pack file from a remote. This can be
415  *		> used to limit maximum memory usage when fetching from an untrusted
416  *		> remote.
417  *
418  *	 opts(GIT_OPT_SET_PACK_MAX_OBJECTS, size_t objects)
419  *
420  *		> Set the maximum number of objects libgit2 will allow in a pack
421  *		> file when downloading a pack file from a remote.
422  *
423  *	 opts(GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS, int enabled)
424  *		> This will cause .keep file existence checks to be skipped when
425  *		> accessing packfiles, which can help performance with remote filesystems.
426  *
427  *	 opts(GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE, int enabled)
428  *		> When connecting to a server using NTLM or Negotiate
429  *		> authentication, use expect/continue when POSTing data.
430  *		> This option is not available on Windows.
431  *
432  * Params:
433  *      option = Option key
434  *      ... = value to set the option
435  *
436  * Returns: 0 on success, <0 on failure
437  */
438 //GIT_EXTERN
439 int git_libgit2_opts(int option, ...);
440 
441 /** @} */