]> git.proxmox.com Git - libgit2.git/blob - include/git2/common.h
Merge pull request #3636 from nerdishbynature/fix-non-modular-header-in-module
[libgit2.git] / include / git2 / common.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_git_common_h__
8 #define INCLUDE_git_common_h__
9
10 #include <time.h>
11 #include <stdlib.h>
12
13 #ifdef __cplusplus
14 # define GIT_BEGIN_DECL extern "C" {
15 # define GIT_END_DECL }
16 #else
17 /** Start declarations in C mode */
18 # define GIT_BEGIN_DECL /* empty */
19 /** End declarations in C mode */
20 # define GIT_END_DECL /* empty */
21 #endif
22
23 #if defined(_MSC_VER) && _MSC_VER < 1800
24 GIT_BEGIN_DECL
25 # include "inttypes.h"
26 GIT_END_DECL
27 /** This check is needed for importing this file in an iOS/OS X framework throws an error in Xcode otherwise.*/
28 #elif !defined(__CLANG_INTTYPES_H)
29 # include <inttypes.h>
30 #endif
31
32 /** Declare a public function exported for application use. */
33 #if __GNUC__ >= 4
34 # define GIT_EXTERN(type) extern \
35 __attribute__((visibility("default"))) \
36 type
37 #elif defined(_MSC_VER)
38 # define GIT_EXTERN(type) __declspec(dllexport) type
39 #else
40 # define GIT_EXTERN(type) extern type
41 #endif
42
43 /** Declare a function's takes printf style arguments. */
44 #ifdef __GNUC__
45 # define GIT_FORMAT_PRINTF(a,b) __attribute__((format (printf, a, b)))
46 #else
47 # define GIT_FORMAT_PRINTF(a,b) /* empty */
48 #endif
49
50 #if (defined(_WIN32)) && !defined(__CYGWIN__)
51 #define GIT_WIN32 1
52 #endif
53
54 #ifdef __amigaos4__
55 #include <netinet/in.h>
56 #endif
57
58 /**
59 * @file git2/common.h
60 * @brief Git common platform definitions
61 * @defgroup git_common Git common platform definitions
62 * @ingroup Git
63 * @{
64 */
65
66 GIT_BEGIN_DECL
67
68 /**
69 * The separator used in path list strings (ie like in the PATH
70 * environment variable). A semi-colon ";" is used on Windows, and
71 * a colon ":" for all other systems.
72 */
73 #ifdef GIT_WIN32
74 #define GIT_PATH_LIST_SEPARATOR ';'
75 #else
76 #define GIT_PATH_LIST_SEPARATOR ':'
77 #endif
78
79 /**
80 * The maximum length of a valid git path.
81 */
82 #define GIT_PATH_MAX 4096
83
84 /**
85 * The string representation of the null object ID.
86 */
87 #define GIT_OID_HEX_ZERO "0000000000000000000000000000000000000000"
88
89 /**
90 * Return the version of the libgit2 library
91 * being currently used.
92 *
93 * @param major Store the major version number
94 * @param minor Store the minor version number
95 * @param rev Store the revision (patch) number
96 */
97 GIT_EXTERN(void) git_libgit2_version(int *major, int *minor, int *rev);
98
99 /**
100 * Combinations of these values describe the features with which libgit2
101 * was compiled
102 */
103 typedef enum {
104 GIT_FEATURE_THREADS = (1 << 0),
105 GIT_FEATURE_HTTPS = (1 << 1),
106 GIT_FEATURE_SSH = (1 << 2),
107 GIT_FEATURE_NSEC = (1 << 3),
108 } git_feature_t;
109
110 /**
111 * Query compile time options for libgit2.
112 *
113 * @return A combination of GIT_FEATURE_* values.
114 *
115 * - GIT_FEATURE_THREADS
116 * Libgit2 was compiled with thread support. Note that thread support is
117 * still to be seen as a 'work in progress' - basic object lookups are
118 * believed to be threadsafe, but other operations may not be.
119 *
120 * - GIT_FEATURE_HTTPS
121 * Libgit2 supports the https:// protocol. This requires the openssl
122 * library to be found when compiling libgit2.
123 *
124 * - GIT_FEATURE_SSH
125 * Libgit2 supports the SSH protocol for network operations. This requires
126 * the libssh2 library to be found when compiling libgit2
127 */
128 GIT_EXTERN(int) git_libgit2_features(void);
129
130 /**
131 * Global library options
132 *
133 * These are used to select which global option to set or get and are
134 * used in `git_libgit2_opts()`.
135 */
136 typedef enum {
137 GIT_OPT_GET_MWINDOW_SIZE,
138 GIT_OPT_SET_MWINDOW_SIZE,
139 GIT_OPT_GET_MWINDOW_MAPPED_LIMIT,
140 GIT_OPT_SET_MWINDOW_MAPPED_LIMIT,
141 GIT_OPT_GET_SEARCH_PATH,
142 GIT_OPT_SET_SEARCH_PATH,
143 GIT_OPT_SET_CACHE_OBJECT_LIMIT,
144 GIT_OPT_SET_CACHE_MAX_SIZE,
145 GIT_OPT_ENABLE_CACHING,
146 GIT_OPT_GET_CACHED_MEMORY,
147 GIT_OPT_GET_TEMPLATE_PATH,
148 GIT_OPT_SET_TEMPLATE_PATH,
149 GIT_OPT_SET_SSL_CERT_LOCATIONS,
150 GIT_OPT_SET_USER_AGENT,
151 GIT_OPT_ENABLE_STRICT_OBJECT_CREATION,
152 } git_libgit2_opt_t;
153
154 /**
155 * Set or query a library global option
156 *
157 * Available options:
158 *
159 * * opts(GIT_OPT_GET_MWINDOW_SIZE, size_t *):
160 *
161 * > Get the maximum mmap window size
162 *
163 * * opts(GIT_OPT_SET_MWINDOW_SIZE, size_t):
164 *
165 * > Set the maximum mmap window size
166 *
167 * * opts(GIT_OPT_GET_MWINDOW_MAPPED_LIMIT, size_t *):
168 *
169 * > Get the maximum memory that will be mapped in total by the library
170 *
171 * * opts(GIT_OPT_SET_MWINDOW_MAPPED_LIMIT, size_t):
172 *
173 * >Set the maximum amount of memory that can be mapped at any time
174 * by the library
175 *
176 * * opts(GIT_OPT_GET_SEARCH_PATH, int level, git_buf *buf)
177 *
178 * > Get the search path for a given level of config data. "level" must
179 * > be one of `GIT_CONFIG_LEVEL_SYSTEM`, `GIT_CONFIG_LEVEL_GLOBAL`,
180 * > `GIT_CONFIG_LEVEL_XDG`, or `GIT_CONFIG_LEVEL_PROGRAMDATA`.
181 * > The search path is written to the `out` buffer.
182 *
183 * * opts(GIT_OPT_SET_SEARCH_PATH, int level, const char *path)
184 *
185 * > Set the search path for a level of config data. The search path
186 * > applied to shared attributes and ignore files, too.
187 * >
188 * > - `path` lists directories delimited by GIT_PATH_LIST_SEPARATOR.
189 * > Pass NULL to reset to the default (generally based on environment
190 * > variables). Use magic path `$PATH` to include the old value
191 * > of the path (if you want to prepend or append, for instance).
192 * >
193 * > - `level` must be `GIT_CONFIG_LEVEL_SYSTEM`,
194 * > `GIT_CONFIG_LEVEL_GLOBAL`, `GIT_CONFIG_LEVEL_XDG`, or
195 * > `GIT_CONFIG_LEVEL_PROGRAMDATA`.
196 *
197 * * opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, git_otype type, size_t size)
198 *
199 * > Set the maximum data size for the given type of object to be
200 * > considered eligible for caching in memory. Setting to value to
201 * > zero means that that type of object will not be cached.
202 * > Defaults to 0 for GIT_OBJ_BLOB (i.e. won't cache blobs) and 4k
203 * > for GIT_OBJ_COMMIT, GIT_OBJ_TREE, and GIT_OBJ_TAG.
204 *
205 * * opts(GIT_OPT_SET_CACHE_MAX_SIZE, ssize_t max_storage_bytes)
206 *
207 * > Set the maximum total data size that will be cached in memory
208 * > across all repositories before libgit2 starts evicting objects
209 * > from the cache. This is a soft limit, in that the library might
210 * > briefly exceed it, but will start aggressively evicting objects
211 * > from cache when that happens. The default cache size is 256MB.
212 *
213 * * opts(GIT_OPT_ENABLE_CACHING, int enabled)
214 *
215 * > Enable or disable caching completely.
216 * >
217 * > Because caches are repository-specific, disabling the cache
218 * > cannot immediately clear all cached objects, but each cache will
219 * > be cleared on the next attempt to update anything in it.
220 *
221 * * opts(GIT_OPT_GET_CACHED_MEMORY, ssize_t *current, ssize_t *allowed)
222 *
223 * > Get the current bytes in cache and the maximum that would be
224 * > allowed in the cache.
225 *
226 * * opts(GIT_OPT_GET_TEMPLATE_PATH, git_buf *out)
227 *
228 * > Get the default template path.
229 * > The path is written to the `out` buffer.
230 *
231 * * opts(GIT_OPT_SET_TEMPLATE_PATH, const char *path)
232 *
233 * > Set the default template path.
234 * >
235 * > - `path` directory of template.
236 *
237 * * opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, const char *file, const char *path)
238 *
239 * > Set the SSL certificate-authority locations.
240 * >
241 * > - `file` is the location of a file containing several
242 * > certificates concatenated together.
243 * > - `path` is the location of a directory holding several
244 * > certificates, one per file.
245 * >
246 * > Either parameter may be `NULL`, but not both.
247 *
248 * * opts(GIT_OPT_SET_USER_AGENT, const char *user_agent)
249 *
250 * > Set the value of the User-Agent header. This value will be
251 * > appended to "git/1.0", for compatibility with other git clients.
252 * >
253 * > - `user_agent` is the value that will be delivered as the
254 * > User-Agent header on HTTP requests.
255 *
256 * * opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, int enabled)
257 *
258 * > Enable strict input validation when creating new objects
259 * > to ensure that all inputs to the new objects are valid. For
260 * > example, when this is enabled, the parent(s) and tree inputs
261 * > will be validated when creating a new commit. This defaults
262 * > to disabled.
263 *
264 * @param option Option key
265 * @param ... value to set the option
266 * @return 0 on success, <0 on failure
267 */
268 GIT_EXTERN(int) git_libgit2_opts(int option, ...);
269
270 /** @} */
271 GIT_END_DECL
272
273 #endif