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