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