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 /** 120 * Query compile time options for libgit2. 121 * 122 * Returns: A combination of GIT_FEATURE_* values. 123 * 124 * - git_feature_t.GIT_FEATURE_THREADS 125 * Libgit2 was compiled with thread support. Note that thread support is 126 * still to be seen as a 'work in progress' - basic object lookups are 127 * believed to be threadsafe, but other operations may not be. 128 * 129 * - git_feature_t.GIT_FEATURE_HTTPS 130 * Libgit2 supports the https:// protocol. This requires the openssl 131 * library to be found when compiling libgit2. 132 * 133 * - git_feature_t.GIT_FEATURE_SSH 134 * Libgit2 supports the SSH protocol for network operations. This requires 135 * the libssh2 library to be found when compiling libgit2 136 */ 137 //GIT_EXTERN 138 int git_libgit2_features(); 139 140 /** 141 * Global library options 142 * 143 * These are used to select which global option to set or get and are 144 * used in `git_libgit2_opts()`. 145 */ 146 enum git_libgit2_opt_t 147 { 148 GIT_OPT_GET_MWINDOW_SIZE, 149 GIT_OPT_SET_MWINDOW_SIZE, 150 GIT_OPT_GET_MWINDOW_MAPPED_LIMIT, 151 GIT_OPT_SET_MWINDOW_MAPPED_LIMIT, 152 GIT_OPT_GET_SEARCH_PATH, 153 GIT_OPT_SET_SEARCH_PATH, 154 GIT_OPT_SET_CACHE_OBJECT_LIMIT, 155 GIT_OPT_SET_CACHE_MAX_SIZE, 156 GIT_OPT_ENABLE_CACHING, 157 GIT_OPT_GET_CACHED_MEMORY, 158 GIT_OPT_GET_TEMPLATE_PATH, 159 GIT_OPT_SET_TEMPLATE_PATH, 160 GIT_OPT_SET_SSL_CERT_LOCATIONS, 161 GIT_OPT_SET_USER_AGENT, 162 GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, 163 GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION, 164 GIT_OPT_SET_SSL_CIPHERS, 165 GIT_OPT_GET_USER_AGENT, 166 GIT_OPT_ENABLE_OFS_DELTA, 167 GIT_OPT_ENABLE_FSYNC_GITDIR, 168 GIT_OPT_GET_WINDOWS_SHAREMODE, 169 GIT_OPT_SET_WINDOWS_SHAREMODE, 170 GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 171 GIT_OPT_SET_ALLOCATOR, 172 GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY, 173 GIT_OPT_GET_PACK_MAX_OBJECTS, 174 GIT_OPT_SET_PACK_MAX_OBJECTS, 175 GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS, 176 GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE, 177 } 178 179 /** 180 * Set or query a library global option 181 * 182 * Available options: 183 * 184 * * opts(GIT_OPT_GET_MWINDOW_SIZE, size_t *): 185 * 186 * > Get the maximum mmap window size 187 * 188 * * opts(GIT_OPT_SET_MWINDOW_SIZE, size_t): 189 * 190 * > Set the maximum mmap window size 191 * 192 * * opts(GIT_OPT_GET_MWINDOW_MAPPED_LIMIT, size_t *): 193 * 194 * > Get the maximum memory that will be mapped in total by the library 195 * 196 * * opts(GIT_OPT_SET_MWINDOW_MAPPED_LIMIT, size_t): 197 * 198 * >Set the maximum amount of memory that can be mapped at any time 199 * by the library 200 * 201 * * opts(GIT_OPT_GET_SEARCH_PATH, int level, git_buf *buf) 202 * 203 * > Get the search path for a given level of config data. "level" must 204 * > be one of `GIT_CONFIG_LEVEL_SYSTEM`, `GIT_CONFIG_LEVEL_GLOBAL`, 205 * > `GIT_CONFIG_LEVEL_XDG`, or `GIT_CONFIG_LEVEL_PROGRAMDATA`. 206 * > The search path is written to the `out` buffer. 207 * 208 * * opts(GIT_OPT_SET_SEARCH_PATH, int level, const char *path) 209 * 210 * > Set the search path for a level of config data. The search path 211 * > applied to shared attributes and ignore files, too. 212 * > 213 * > - `path` lists directories delimited by GIT_PATH_LIST_SEPARATOR. 214 * > Pass NULL to reset to the default (generally based on environment 215 * > variables). Use magic path `$PATH` to include the old value 216 * > of the path (if you want to prepend or append, for instance). 217 * > 218 * > - `level` must be `GIT_CONFIG_LEVEL_SYSTEM`, 219 * > `GIT_CONFIG_LEVEL_GLOBAL`, `GIT_CONFIG_LEVEL_XDG`, or 220 * > `GIT_CONFIG_LEVEL_PROGRAMDATA`. 221 * 222 * * opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, git_object_t type, size_t size) 223 * 224 * > Set the maximum data size for the given type of object to be 225 * > considered eligible for caching in memory. Setting to value to 226 * > zero means that that type of object will not be cached. 227 * > Defaults to 0 for GIT_OBJECT_BLOB (i.e. won't cache blobs) and 4k 228 * > for GIT_OBJECT_COMMIT, GIT_OBJECT_TREE, and GIT_OBJECT_TAG. 229 * 230 * * opts(GIT_OPT_SET_CACHE_MAX_SIZE, ssize_t max_storage_bytes) 231 * 232 * > Set the maximum total data size that will be cached in memory 233 * > across all repositories before libgit2 starts evicting objects 234 * > from the cache. This is a soft limit, in that the library might 235 * > briefly exceed it, but will start aggressively evicting objects 236 * > from cache when that happens. The default cache size is 256MB. 237 * 238 * * opts(GIT_OPT_ENABLE_CACHING, int enabled) 239 * 240 * > Enable or disable caching completely. 241 * > 242 * > Because caches are repository-specific, disabling the cache 243 * > cannot immediately clear all cached objects, but each cache will 244 * > be cleared on the next attempt to update anything in it. 245 * 246 * * opts(GIT_OPT_GET_CACHED_MEMORY, ssize_t *current, ssize_t *allowed) 247 * 248 * > Get the current bytes in cache and the maximum that would be 249 * > allowed in the cache. 250 * 251 * * opts(GIT_OPT_GET_TEMPLATE_PATH, git_buf *out) 252 * 253 * > Get the default template path. 254 * > The path is written to the `out` buffer. 255 * 256 * * opts(GIT_OPT_SET_TEMPLATE_PATH, const char *path) 257 * 258 * > Set the default template path. 259 * > 260 * > - `path` directory of template. 261 * 262 * * opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, const char *file, const char *path) 263 * 264 * > Set the SSL certificate-authority locations. 265 * > 266 * > - `file` is the location of a file containing several 267 * > certificates concatenated together. 268 * > - `path` is the location of a directory holding several 269 * > certificates, one per file. 270 * > 271 * > Either parameter may be `NULL`, but not both. 272 * 273 * * opts(GIT_OPT_SET_USER_AGENT, const char *user_agent) 274 * 275 * > Set the value of the User-Agent header. This value will be 276 * > appended to "git/1.0", for compatibility with other git clients. 277 * > 278 * > - `user_agent` is the value that will be delivered as the 279 * > User-Agent header on HTTP requests. 280 * 281 * * opts(GIT_OPT_SET_WINDOWS_SHAREMODE, core.stdc.config.c_ulong value) 282 * 283 * > Set the share mode used when opening files on Windows. 284 * > For more information, see the documentation for CreateFile. 285 * > The default is: FILE_SHARE_READ | FILE_SHARE_WRITE. This is 286 * > ignored and unused on non-Windows platforms. 287 * 288 * * opts(GIT_OPT_GET_WINDOWS_SHAREMODE, core.stdc.config.c_ulong *value) 289 * 290 * > Get the share mode used when opening files on Windows. 291 * 292 * * opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, int enabled) 293 * 294 * > Enable strict input validation when creating new objects 295 * > to ensure that all inputs to the new objects are valid. For 296 * > example, when this is enabled, the parent(s) and tree inputs 297 * > will be validated when creating a new commit. This defaults 298 * > to enabled. 299 * 300 * * opts(GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION, int enabled) 301 * 302 * > Validate the target of a symbolic ref when creating it. For 303 * > example, `foobar` is not a valid ref, therefore `foobar` is 304 * > not a valid target for a symbolic ref by default, whereas 305 * > `refs/heads/foobar` is. Disabling this bypasses validation 306 * > so that an arbitrary strings such as `foobar` can be used 307 * > for a symbolic ref target. This defaults to enabled. 308 * 309 * * opts(GIT_OPT_SET_SSL_CIPHERS, const char *ciphers) 310 * 311 * > Set the SSL ciphers use for HTTPS connections. 312 * > 313 * > - `ciphers` is the list of ciphers that are eanbled. 314 * 315 * * opts(GIT_OPT_ENABLE_OFS_DELTA, int enabled) 316 * 317 * > Enable or disable the use of "offset deltas" when creating packfiles, 318 * > and the negotiation of them when talking to a remote server. 319 * > Offset deltas store a delta base location as an offset into the 320 * > packfile from the current location, which provides a shorter encoding 321 * > and thus smaller resultant packfiles. 322 * > Packfiles containing offset deltas can still be read. 323 * > This defaults to enabled. 324 * 325 * * opts(GIT_OPT_ENABLE_FSYNC_GITDIR, int enabled) 326 * 327 * > Enable synchronized writes of files in the gitdir using `fsync` 328 * > (or the platform equivalent) to ensure that new object data 329 * > is written to permanent storage, not simply cached. This 330 * > defaults to disabled. 331 * 332 * opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, int enabled) 333 * 334 * > Enable strict verification of object hashsums when reading 335 * > objects from disk. This may impact performance due to an 336 * > additional checksum calculation on each object. This defaults 337 * > to enabled. 338 * 339 * opts(GIT_OPT_SET_ALLOCATOR, git_allocator *allocator) 340 * 341 * > Set the memory allocator to a different memory allocator. This 342 * > allocator will then be used to make all memory allocations for 343 * > libgit2 operations. If the given `allocator` is NULL, then the 344 * > system default will be restored. 345 * 346 * opts(GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY, int enabled) 347 * 348 * > Ensure that there are no unsaved changes in the index before 349 * > beginning any operation that reloads the index from disk (eg, 350 * > checkout). If there are unsaved changes, the instruction will 351 * > fail. (Using the FORCE flag to checkout will still overwrite 352 * > these changes.) 353 * 354 * opts(GIT_OPT_GET_PACK_MAX_OBJECTS, size_t *out) 355 * 356 * > Get the maximum number of objects libgit2 will allow in a pack 357 * > file when downloading a pack file from a remote. This can be 358 * > used to limit maximum memory usage when fetching from an untrusted 359 * > remote. 360 * 361 * opts(GIT_OPT_SET_PACK_MAX_OBJECTS, size_t objects) 362 * 363 * > Set the maximum number of objects libgit2 will allow in a pack 364 * > file when downloading a pack file from a remote. 365 * 366 * opts(GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS, int enabled) 367 * > This will cause .keep file existence checks to be skipped when 368 * > accessing packfiles, which can help performance with remote filesystems. 369 * 370 * opts(GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE, int enabled) 371 * > When connecting to a server using NTLM or Negotiate 372 * > authentication, use expect/continue when POSTing data. 373 * > This option is not available on Windows. 374 * 375 * Params: 376 * option = Option key 377 * ... = value to set the option 378 * 379 * Returns: 0 on success, <0 on failure 380 */ 381 //GIT_EXTERN 382 int git_libgit2_opts(int option, ...); 383 384 /** @} */