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 /** 8 * License: GPL-2.0(Linking Exception) 9 */ 10 module libgit2.odb; 11 12 13 private static import libgit2.indexer; 14 private static import libgit2.oid; 15 private static import libgit2.types; 16 private import libgit2.common: GIT_EXTERN; 17 18 /* 19 * @file git2/odb.h 20 * @brief Git object database routines 21 * @defgroup git_odb Git object database routines 22 * @ingroup Git 23 * @{ 24 */ 25 extern (C): 26 nothrow @nogc: 27 public: 28 29 /** 30 * Flags controlling the behavior of ODB lookup operations 31 */ 32 enum git_odb_lookup_flags_t 33 { 34 /** 35 * Don't call `git_odb_refresh` if the lookup fails. Useful when doing 36 * a batch of lookup operations for objects that may legitimately not 37 * exist. When using this flag, you may wish to manually call 38 * `git_odb_refresh` before processing a batch of objects. 39 */ 40 GIT_ODB_LOOKUP_NO_REFRESH = 1 << 0, 41 } 42 43 enum 44 { 45 GIT_ODB_LOOKUP_NO_REFRESH = .git_odb_lookup_flags_t.GIT_ODB_LOOKUP_NO_REFRESH, 46 } 47 48 /** 49 * Function type for callbacks from git_odb_foreach. 50 */ 51 alias git_odb_foreach_cb = int function(const (libgit2.oid.git_oid)* id, void* payload); 52 53 /** 54 * Options for configuring a loose object backend. 55 */ 56 struct git_odb_options 57 { 58 /** 59 * version for the struct 60 */ 61 uint version_; 62 63 /** 64 * Type of object IDs to use for this object database, or 65 * 0 for default (currently SHA1). 66 */ 67 libgit2.oid.git_oid_t oid_type; 68 } 69 70 /** 71 * The current version of the diff options structure 72 */ 73 enum GIT_ODB_OPTIONS_VERSION = 1; 74 75 /** 76 * Stack initializer for odb options. Alternatively use 77 * `git_odb_options_init` programmatic initialization. 78 */ 79 pragma(inline, true) 80 pure nothrow @safe @nogc @live 81 .git_odb_options GIT_ODB_OPTIONS_INIT() 82 83 do 84 { 85 .git_odb_options OUTPUT = 86 { 87 version_: .GIT_ODB_OPTIONS_VERSION, 88 }; 89 90 return OUTPUT; 91 } 92 93 version (GIT_EXPERIMENTAL_SHA256) { 94 /** 95 * Create a new object database with no backends. 96 * 97 * Before the ODB can be used for read/writing, a custom database 98 * backend must be manually added using `git_odb_add_backend()` 99 * 100 * Params: 101 * out_ = location to store the database pointer, if opened. Set to null if the open failed. 102 * opts = the options for this object database or NULL for defaults 103 * 104 * Returns: 0 or an error code 105 */ 106 @GIT_EXTERN 107 int git_odb_new(libgit2.types.git_odb** out_, const (.git_odb_options)* opts); 108 } else { 109 /** 110 * Create a new object database with no backends. 111 * 112 * Before the ODB can be used for read/writing, a custom database 113 * backend must be manually added using `git_odb_add_backend()` 114 * 115 * Params: 116 * out_ = location to store the database pointer, if opened. Set to null if the open failed. 117 * 118 * Returns: 0 or an error code 119 */ 120 @GIT_EXTERN 121 int git_odb_new(libgit2.types.git_odb** out_); 122 } 123 124 version (GIT_EXPERIMENTAL_SHA256) { 125 /** 126 * Create a new object database and automatically add 127 * the two default backends: 128 * 129 * - git_odb_backend_loose: read and write loose object files 130 * from disk, assuming `objects_dir` as the Objects folder 131 * 132 * - git_odb_backend_pack: read objects from packfiles, 133 * assuming `objects_dir` as the Objects folder which 134 * contains a 'pack/' folder with the corresponding data 135 * 136 * Params: 137 * out_ = location to store the database pointer, if opened. Set to null if the open failed. 138 * objects_dir = path of the backends' "objects" directory. 139 * opts = the options for this object database or NULL for defaults 140 * 141 * Returns: 0 or an error code 142 */ 143 @GIT_EXTERN 144 int git_odb_open(libgit2.types.git_odb** out_, const (char)* objects_dir, const (.git_odb_options)* opts); 145 } else { 146 /** 147 * Create a new object database and automatically add 148 * the two default backends: 149 * 150 * - git_odb_backend_loose: read and write loose object files 151 * from disk, assuming `objects_dir` as the Objects folder 152 * 153 * - git_odb_backend_pack: read objects from packfiles, 154 * assuming `objects_dir` as the Objects folder which 155 * contains a 'pack/' folder with the corresponding data 156 * 157 * Params: 158 * out_ = location to store the database pointer, if opened. Set to null if the open failed. 159 * objects_dir = path of the backends' "objects" directory. 160 * 161 * Returns: 0 or an error code 162 */ 163 @GIT_EXTERN 164 int git_odb_open(libgit2.types.git_odb** out_, const (char)* objects_dir); 165 } 166 167 /** 168 * Add an on-disk alternate to an existing Object DB. 169 * 170 * Note that the added path must point to an `objects`, not 171 * to a full repository, to use it as an alternate store. 172 * 173 * Alternate backends are always checked for objects *after* 174 * all the main backends have been exhausted. 175 * 176 * Writing is disabled on alternate backends. 177 * 178 * Params: 179 * odb = database to add the backend to 180 * path = path to the objects folder for the alternate 181 * 182 * Returns: 0 on success, error code otherwise 183 */ 184 @GIT_EXTERN 185 int git_odb_add_disk_alternate(libgit2.types.git_odb* odb, const (char)* path); 186 187 /** 188 * Close an open object database. 189 * 190 * Params: 191 * db = database pointer to close. If null no action is taken. 192 */ 193 @GIT_EXTERN 194 void git_odb_free(libgit2.types.git_odb* db); 195 196 /** 197 * Read an object from the database. 198 * 199 * This method queries all available ODB backends 200 * trying to read the given OID. 201 * 202 * The returned object is reference counted and 203 * internally cached, so it should be closed 204 * by the user once it's no longer in use. 205 * 206 * Params: 207 * out_ = pointer where to store the read object 208 * db = database to search for the object in. 209 * id = identity of the object to read. 210 * 211 * Returns: 0 if the object was read, GIT_ENOTFOUND if the object is not in the database. 212 */ 213 @GIT_EXTERN 214 int git_odb_read(libgit2.types.git_odb_object** out_, libgit2.types.git_odb* db, const (libgit2.oid.git_oid)* id); 215 216 /** 217 * Read an object from the database, given a prefix 218 * of its identifier. 219 * 220 * This method queries all available ODB backends 221 * trying to match the 'len' first hexadecimal 222 * characters of the 'short_id'. 223 * The remaining (GIT_OID_SHA1_HEXSIZE-len)*4 bits of 224 * 'short_id' must be 0s. 225 * 'len' must be at least GIT_OID_MINPREFIXLEN, 226 * and the prefix must be long enough to identify 227 * a unique object in all the backends; the 228 * method will fail otherwise. 229 * 230 * The returned object is reference counted and 231 * internally cached, so it should be closed 232 * by the user once it's no longer in use. 233 * 234 * Params: 235 * out_ = pointer where to store the read object 236 * db = database to search for the object in. 237 * short_id = a prefix of the id of the object to read. 238 * len = the length of the prefix 239 * 240 * Returns: 0 if the object was read, GIT_ENOTFOUND if the object is not in the database. GIT_EAMBIGUOUS if the prefix is ambiguous(several objects match the prefix) 241 */ 242 @GIT_EXTERN 243 int git_odb_read_prefix(libgit2.types.git_odb_object** out_, libgit2.types.git_odb* db, const (libgit2.oid.git_oid)* short_id, size_t len); 244 245 /** 246 * Read the header of an object from the database, without 247 * reading its full contents. 248 * 249 * The header includes the length and the type of an object. 250 * 251 * Note that most backends do not support reading only the header 252 * of an object, so the whole object will be read and then the 253 * header will be returned. 254 * 255 * Params: 256 * len_out = pointer where to store the length 257 * type_out = pointer where to store the type 258 * db = database to search for the object in. 259 * id = identity of the object to read. 260 * 261 * Returns: 0 if the object was read, GIT_ENOTFOUND if the object is not in the database. 262 */ 263 @GIT_EXTERN 264 int git_odb_read_header(size_t* len_out, libgit2.types.git_object_t* type_out, libgit2.types.git_odb* db, const (libgit2.oid.git_oid)* id); 265 266 /** 267 * Determine if the given object can be found in the object database. 268 * 269 * Params: 270 * db = database to be searched for the given object. 271 * id = the object to search for. 272 * 273 * Returns: 1 if the object was found, 0 otherwise 274 */ 275 @GIT_EXTERN 276 int git_odb_exists(libgit2.types.git_odb* db, const (libgit2.oid.git_oid)* id); 277 278 /** 279 * Determine if the given object can be found in the object database, with 280 * extended options. 281 * 282 * Params: 283 * db = database to be searched for the given object. 284 * id = the object to search for. 285 * flags = flags affecting the lookup (see `git_odb_lookup_flags_t`) 286 * 287 * Returns: 1 if the object was found, 0 otherwise 288 */ 289 @GIT_EXTERN 290 int git_odb_exists_ext(libgit2.types.git_odb* db, const (libgit2.oid.git_oid)* id, uint flags); 291 292 /** 293 * Determine if an object can be found in the object database by an 294 * abbreviated object ID. 295 * 296 * Params: 297 * out_ = The full OID of the found object if just one is found. 298 * db = The database to be searched for the given object. 299 * short_id = A prefix of the id of the object to read. 300 * len = The length of the prefix. 301 * 302 * Returns: 0 if found, git_error_code.GIT_ENOTFOUND if not found, git_error_code.GIT_EAMBIGUOUS if multiple matches were found, other value < 0 if there was a read error. 303 */ 304 @GIT_EXTERN 305 int git_odb_exists_prefix(libgit2.oid.git_oid* out_, libgit2.types.git_odb* db, const (libgit2.oid.git_oid)* short_id, size_t len); 306 307 /** 308 * The information about object IDs to query in `git_odb_expand_ids`, 309 * which will be populated upon return. 310 */ 311 struct git_odb_expand_id 312 { 313 /** 314 * The object ID to expand 315 */ 316 libgit2.oid.git_oid id; 317 318 /** 319 * The length of the object ID (in nibbles, or packets of 4 bits; the 320 * number of hex characters) 321 * */ 322 ushort length; 323 324 /** 325 * The (optional) type of the object to search for; leave as `0` or set 326 * to `git_object_t.GIT_OBJECT_ANY` to query for any object matching the ID. 327 */ 328 libgit2.types.git_object_t type = cast(libgit2.types.git_object_t)(0); 329 } 330 331 /** 332 * Determine if one or more objects can be found in the object database 333 * by their abbreviated object ID and type. 334 * 335 * The given array will be updated in place: for each abbreviated ID that is 336 * unique in the database, and of the given type (if specified), 337 * the full object ID, object ID length (`GIT_OID_SHA1_HEXSIZE`) and type will be 338 * written back to the array. For IDs that are not found (or are ambiguous), 339 * the array entry will be zeroed. 340 * 341 * Note that since this function operates on multiple objects, the 342 * underlying database will not be asked to be reloaded if an object is 343 * not found (which is unlike other object database operations.) 344 * 345 * Params: 346 * db = The database to be searched for the given objects. 347 * ids = An array of short object IDs to search for 348 * count = The length of the `ids` array 349 * 350 * Returns: 0 on success or an error code on failure 351 */ 352 @GIT_EXTERN 353 int git_odb_expand_ids(libgit2.types.git_odb* db, .git_odb_expand_id* ids, size_t count); 354 355 /** 356 * Refresh the object database to load newly added files. 357 * 358 * If the object databases have changed on disk while the library 359 * is running, this function will force a reload of the underlying 360 * indexes. 361 * 362 * Use this function when you're confident that an external 363 * application has tampered with the ODB. 364 * 365 * NOTE that it is not necessary to call this function at all. The 366 * library will automatically attempt to refresh the ODB 367 * when a lookup fails, to see if the looked up object exists 368 * on disk but hasn't been loaded yet. 369 * 370 * Params: 371 * db = database to refresh 372 * 373 * Returns: 0 on success, error code otherwise 374 */ 375 @GIT_EXTERN 376 int git_odb_refresh(libgit2.types.git_odb* db); 377 378 /** 379 * List all objects available in the database 380 * 381 * The callback will be called for each object available in the 382 * database. Note that the objects are likely to be returned in the index 383 * order, which would make accessing the objects in that order inefficient. 384 * Return a non-zero value from the callback to stop looping. 385 * 386 * Params: 387 * db = database to use 388 * cb = the callback to call for each object 389 * payload = data to pass to the callback 390 * 391 * Returns: 0 on success, non-zero callback return value, or error code 392 */ 393 @GIT_EXTERN 394 int git_odb_foreach(libgit2.types.git_odb* db, .git_odb_foreach_cb cb, void* payload); 395 396 /** 397 * Write an object directly into the ODB 398 * 399 * This method writes a full object straight into the ODB. 400 * For most cases, it is preferred to write objects through a write 401 * stream, which is both faster and less memory intensive, specially 402 * for big objects. 403 * 404 * This method is provided for compatibility with custom backends 405 * which are not able to support streaming writes 406 * 407 * Params: 408 * out_ = pointer to store the OID result of the write 409 * odb = object database where to store the object 410 * data = buffer with the data to store 411 * len = size of the buffer 412 * type = type of the data to store 413 * 414 * Returns: 0 or an error code 415 */ 416 @GIT_EXTERN 417 int git_odb_write(libgit2.oid.git_oid* out_, libgit2.types.git_odb* odb, const (void)* data, size_t len, libgit2.types.git_object_t type); 418 419 /** 420 * Open a stream to write an object into the ODB 421 * 422 * The type and final length of the object must be specified 423 * when opening the stream. 424 * 425 * The returned stream will be of type `git_odb_stream_t.GIT_STREAM_WRONLY`, and it 426 * won't be effective until `git_odb_stream_finalize_write` is called 427 * and returns without an error 428 * 429 * The stream must always be freed when done with `git_odb_stream_free` or 430 * will leak memory. 431 * 432 * @see git_odb_stream 433 * 434 * Params: 435 * out_ = pointer where to store the stream 436 * db = object database where the stream will write 437 * size = final size of the object that will be written 438 * type = type of the object that will be written 439 * 440 * Returns: 0 if the stream was created; error code otherwise 441 */ 442 @GIT_EXTERN 443 int git_odb_open_wstream(libgit2.types.git_odb_stream** out_, libgit2.types.git_odb* db, libgit2.types.git_object_size_t size, libgit2.types.git_object_t type); 444 445 /** 446 * Write to an odb stream 447 * 448 * This method will fail if the total number of received bytes exceeds the 449 * size declared with `git_odb_open_wstream()` 450 * 451 * Params: 452 * stream = the stream 453 * buffer = the data to write 454 * len = the buffer's length 455 * 456 * Returns: 0 if the write succeeded, error code otherwise 457 */ 458 @GIT_EXTERN 459 int git_odb_stream_write(libgit2.types.git_odb_stream* stream, const (char)* buffer, size_t len); 460 461 /** 462 * Finish writing to an odb stream 463 * 464 * The object will take its final name and will be available to the 465 * odb. 466 * 467 * This method will fail if the total number of received bytes 468 * differs from the size declared with `git_odb_open_wstream()` 469 * 470 * Params: 471 * out_ = pointer to store the resulting object's id 472 * stream = the stream 473 * 474 * Returns: 0 on success, an error code otherwise 475 */ 476 @GIT_EXTERN 477 int git_odb_stream_finalize_write(libgit2.oid.git_oid* out_, libgit2.types.git_odb_stream* stream); 478 479 /** 480 * Read from an odb stream 481 * 482 * Most backends don't implement streaming reads 483 * 484 * Params: 485 * stream = the stream 486 * buffer = a user-allocated buffer to store the data in. 487 * len = the buffer's length 488 * 489 * Returns: 0 if the read succeeded, error code otherwise 490 */ 491 @GIT_EXTERN 492 int git_odb_stream_read(libgit2.types.git_odb_stream* stream, char* buffer, size_t len); 493 494 /** 495 * Free an odb stream 496 * 497 * Params: 498 * stream = the stream to free 499 */ 500 @GIT_EXTERN 501 void git_odb_stream_free(libgit2.types.git_odb_stream* stream); 502 503 /** 504 * Open a stream to read an object from the ODB 505 * 506 * Note that most backends do *not* support streaming reads 507 * because they store their objects as compressed/delta'ed blobs. 508 * 509 * It's recommended to use `git_odb_read` instead, which is 510 * assured to work on all backends. 511 * 512 * The returned stream will be of type `git_odb_stream_t.GIT_STREAM_RDONLY` and 513 * will have the following methods: 514 * 515 * - stream->read: read `n` bytes from the stream 516 * - stream->free: free the stream 517 * 518 * The stream must always be free'd or will leak memory. 519 * 520 * @see git_odb_stream 521 * 522 * Params: 523 * out_ = pointer where to store the stream 524 * len = pointer where to store the length of the object 525 * type = pointer where to store the type of the object 526 * db = object database where the stream will read from 527 * oid = oid of the object the stream will read from 528 * 529 * Returns: 0 if the stream was created, error code otherwise 530 */ 531 @GIT_EXTERN 532 int git_odb_open_rstream(libgit2.types.git_odb_stream** out_, size_t* len, libgit2.types.git_object_t* type, libgit2.types.git_odb* db, const (libgit2.oid.git_oid)* oid); 533 534 /** 535 * Open a stream for writing a pack file to the ODB. 536 * 537 * If the ODB layer understands pack files, then the given 538 * packfile will likely be streamed directly to disk (and a 539 * corresponding index created). If the ODB layer does not 540 * understand pack files, the objects will be stored in whatever 541 * format the ODB layer uses. 542 * 543 * @see git_odb_writepack 544 * 545 * Params: 546 * out_ = pointer to the writepack functions 547 * db = object database where the stream will read from 548 * progress_cb = function to call with progress information. Be aware that this is called inline with network and indexing operations, so performance may be affected. 549 * progress_payload = payload for the progress callback 550 * 551 * Returns: 0 or an error code. 552 */ 553 @GIT_EXTERN 554 int git_odb_write_pack(libgit2.types.git_odb_writepack** out_, libgit2.types.git_odb* db, libgit2.indexer.git_indexer_progress_cb progress_cb, void* progress_payload); 555 556 /** 557 * Write a `multi-pack-index` file from all the `.pack` files in the ODB. 558 * 559 * If the ODB layer understands pack files, then this will create a file called 560 * `multi-pack-index` next to the `.pack` and `.idx` files, which will contain 561 * an index of all objects stored in `.pack` files. This will allow for 562 * O(log n) lookup for n objects (regardless of how many packfiles there 563 * exist). 564 * 565 * Params: 566 * db = object database where the `multi-pack-index` file will be written. 567 * 568 * Returns: 0 or an error code. 569 */ 570 @GIT_EXTERN 571 int git_odb_write_multi_pack_index(libgit2.types.git_odb* db); 572 573 version (GIT_EXPERIMENTAL_SHA256) { 574 /** 575 * Determine the object-ID (sha1 or sha256 hash) of a data buffer 576 * 577 * The resulting OID will be the identifier for the data buffer as if 578 * the data buffer it were to written to the ODB. 579 * 580 * Params: 581 * out_ = the resulting object-ID. 582 * data = data to hash 583 * len = size of the data 584 * object_type = of the data to hash 585 * oid_type = the oid type to hash to 586 * 587 * Returns: 0 or an error code 588 */ 589 @GIT_EXTERN 590 int git_odb_hash(libgit2.oid.git_oid* out_, const (void)* data, size_t len, libgit2.types.git_object_t object_type, libgit2.oid.git_oid_t oid_type); 591 } else { 592 /** 593 * Determine the object-ID (sha1 or sha256 hash) of a data buffer 594 * 595 * The resulting OID will be the identifier for the data buffer as if 596 * the data buffer it were to written to the ODB. 597 * 598 * Params: 599 * out_ = the resulting object-ID. 600 * data = data to hash 601 * len = size of the data 602 * type = of the data to hash 603 * 604 * Returns: 0 or an error code 605 */ 606 @GIT_EXTERN 607 int git_odb_hash(libgit2.oid.git_oid* out_, const (void)* data, size_t len, libgit2.types.git_object_t type); 608 } 609 610 version (GIT_EXPERIMENTAL_SHA256) { 611 /** 612 * Read a file from disk and fill a git_oid with the object id 613 * that the file would have if it were written to the Object 614 * Database as an object of the given type (w/o applying filters). 615 * Similar functionality to git.git's `git hash-object` without 616 * the `-w` flag, however, with the --no-filters flag. 617 * If you need filters, see git_repository_hashfile. 618 * 619 * Params: 620 * out_ = oid structure the result is written into. 621 * path = file to read and determine object id for 622 * object_type = of the data to hash 623 * oid_type = the oid type to hash to 624 * 625 * Returns: 0 or an error code 626 */ 627 @GIT_EXTERN 628 int git_odb_hashfile(libgit2.oid.git_oid* out_, const (char)* path, libgit2.types.git_object_t object_type, libgit2.oid.git_oid_t oid_type); 629 } else { 630 /** 631 * Read a file from disk and fill a git_oid with the object id 632 * that the file would have if it were written to the Object 633 * Database as an object of the given type (w/o applying filters). 634 * Similar functionality to git.git's `git hash-object` without 635 * the `-w` flag, however, with the --no-filters flag. 636 * If you need filters, see git_repository_hashfile. 637 * 638 * Params: 639 * out_ = oid structure the result is written into. 640 * path = file to read and determine object id for 641 * type = the type of the object that will be hashed 642 * 643 * Returns: 0 or an error code 644 */ 645 @GIT_EXTERN 646 int git_odb_hashfile(libgit2.oid.git_oid* out_, const (char)* path, libgit2.types.git_object_t type); 647 } 648 649 /** 650 * Create a copy of an odb_object 651 * 652 * The returned copy must be manually freed with `git_odb_object_free`. 653 * Note that because of an implementation detail, the returned copy will be 654 * the same pointer as `source`: the object is internally refcounted, so the 655 * copy still needs to be freed twice. 656 * 657 * Params: 658 * dest = pointer where to store the copy 659 * source = object to copy 660 * 661 * Returns: 0 or an error code 662 */ 663 @GIT_EXTERN 664 int git_odb_object_dup(libgit2.types.git_odb_object** dest, libgit2.types.git_odb_object* source); 665 666 /** 667 * Close an ODB object 668 * 669 * This method must always be called once a `git_odb_object` is no 670 * longer needed, otherwise memory will leak. 671 * 672 * Params: 673 * object = object to close 674 */ 675 @GIT_EXTERN 676 void git_odb_object_free(libgit2.types.git_odb_object* object); 677 678 /** 679 * Return the OID of an ODB object 680 * 681 * This is the OID from which the object was read from 682 * 683 * Params: 684 * object = the object 685 * 686 * Returns: a pointer to the OID 687 */ 688 @GIT_EXTERN 689 const (libgit2.oid.git_oid)* git_odb_object_id(libgit2.types.git_odb_object* object); 690 691 /** 692 * Return the data of an ODB object 693 * 694 * This is the uncompressed, raw data as read from the ODB, 695 * without the leading header. 696 * 697 * This pointer is owned by the object and shall not be free'd. 698 * 699 * Params: 700 * object = the object 701 * 702 * Returns: a pointer to the data 703 */ 704 @GIT_EXTERN 705 const (void)* git_odb_object_data(libgit2.types.git_odb_object* object); 706 707 /** 708 * Return the size of an ODB object 709 * 710 * This is the real size of the `data` buffer, not the 711 * actual size of the object. 712 * 713 * Params: 714 * object = the object 715 * 716 * Returns: the size 717 */ 718 @GIT_EXTERN 719 size_t git_odb_object_size(libgit2.types.git_odb_object* object); 720 721 /** 722 * Return the type of an ODB object 723 * 724 * Params: 725 * object = the object 726 * 727 * Returns: the type 728 */ 729 @GIT_EXTERN 730 libgit2.types.git_object_t git_odb_object_type(libgit2.types.git_odb_object* object); 731 732 /** 733 * Add a custom backend to an existing Object DB 734 * 735 * The backends are checked in relative ordering, based on the 736 * value of the `priority` parameter. 737 * 738 * Read <sys/odb_backend.h> for more information. 739 * 740 * Params: 741 * odb = database to add the backend to 742 * backend = pointer to a git_odb_backend instance 743 * priority = Value for ordering the backends queue 744 * 745 * Returns: 0 on success, error code otherwise 746 */ 747 @GIT_EXTERN 748 int git_odb_add_backend(libgit2.types.git_odb* odb, libgit2.types.git_odb_backend* backend, int priority); 749 750 /** 751 * Add a custom backend to an existing Object DB; this 752 * backend will work as an alternate. 753 * 754 * Alternate backends are always checked for objects *after* 755 * all the main backends have been exhausted. 756 * 757 * The backends are checked in relative ordering, based on the 758 * value of the `priority` parameter. 759 * 760 * Writing is disabled on alternate backends. 761 * 762 * Read <sys/odb_backend.h> for more information. 763 * 764 * Params: 765 * odb = database to add the backend to 766 * backend = pointer to a git_odb_backend instance 767 * priority = Value for ordering the backends queue 768 * 769 * Returns: 0 on success, error code otherwise 770 */ 771 @GIT_EXTERN 772 int git_odb_add_alternate(libgit2.types.git_odb* odb, libgit2.types.git_odb_backend* backend, int priority); 773 774 /** 775 * Get the number of ODB backend objects 776 * 777 * Params: 778 * odb = object database 779 * 780 * Returns: number of backends in the ODB 781 */ 782 @GIT_EXTERN 783 size_t git_odb_num_backends(libgit2.types.git_odb* odb); 784 785 /** 786 * Lookup an ODB backend object by index 787 * 788 * Params: 789 * out_ = output pointer to ODB backend at pos 790 * odb = object database 791 * pos = index into object database backend list 792 * 793 * Returns: 0 on success, git_error_code.GIT_ENOTFOUND if pos is invalid, other errors < 0 794 */ 795 @GIT_EXTERN 796 int git_odb_get_backend(libgit2.types.git_odb_backend** out_, libgit2.types.git_odb* odb, size_t pos); 797 798 /** 799 * Set the git commit-graph for the ODB. 800 * 801 * After a successful call, the ownership of the cgraph parameter will be 802 * transferred to libgit2, and the caller should not free it. 803 * 804 * The commit-graph can also be unset by explicitly passing null as the cgraph 805 * parameter. 806 * 807 * Params: 808 * odb = object database 809 * cgraph = the git commit-graph 810 * 811 * Returns: 0 on success; error code otherwise 812 */ 813 @GIT_EXTERN 814 int git_odb_set_commit_graph(libgit2.types.git_odb* odb, libgit2.types.git_commit_graph* cgraph); 815 816 /* @} */