Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/odb.h # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / odb.h` 808 lines ยท 26018 bytes Raw Blame History 1 #ifndef ODB_H 2 #define ODB_H 3 4 #include "hashmap.h" 5 #include "object.h" 6 #include "oid-array.h" 7 #include "oidset.h" 8 #include "oidmap.h" 9 #include "repository.h" 10 #include "string-list.h" 11 #include "thread-utils.h" 12 13 struct cached_object_entry; 14 struct list_objects_filter_options; 15 struct odb_source_inmemory; 16 struct odb_files_dir; 17 struct packed_git; 18 struct repository; 19 struct strbuf; 20 struct strvec; 21 22 /* 23 * Compute the exact path an alternate is at and returns it. In case of 24 * error NULL is returned and the human readable error is added to `err` 25 * `path` may be relative and should point to $GIT_DIR. 26 * `err` must not be null. 27 */ 28 char *compute_alternate_path(const char *path, struct strbuf *err); 29 30 /* 31 * Parse the given URI in the format "[://]" and return the 32 * object storage format identified by the schema. If `payload` is non-NULL it 33 * will be set to a newly allocated copy of the payload, or NULL if the URI has 34 * no or an empty payload. Returns `OBJECT_STORAGE_FORMAT_UNKNOWN` for unknown 35 * schemas. 36 */ 37 enum object_storage_format object_storage_format_by_uri(const char *uri, char **payload); 38 39 enum object_storage_format object_storage_format_by_name(const char *name); 40 const char *object_storage_format_to_name(enum object_storage_format format); 41 42 /* 43 * The object database encapsulates access to objects in a repository. It 44 * manages the object source as well as auxiliary data structures required to 45 * manage objects. 46 */ 47 struct object_database { 48 /* Repository that owns this database. */ 49 struct repository *repo; 50 51 /* The source backing this object database. */ 52 struct odb_source *source; 53 54 /* 55 * State of current object database transaction. Only one 56 * transaction may be pending at a time. Is NULL when no transaction is 57 * configured. 58 */ 59 struct odb_transaction *transaction; 60 61 /* 62 * Objects that should be substituted by other objects 63 * (see git-replace(1)). 64 */ 65 struct oidmap replace_map; 66 unsigned replace_map_initialized : 1; 67 pthread_mutex_t replace_mutex; /* protect object replace functions */ 68 69 struct commit_graph *commit_graph; 70 unsigned commit_graph_attempted : 1; /* if loading has been attempted */ 71 72 /* 73 * This is meant to hold a *small* number of objects that you would 74 * want odb_read_object() to be able to return, but yet you do not want 75 * to write them into the object store (e.g. a browse-only 76 * application). 77 */ 78 struct odb_source *inmemory_objects; 79 80 /* 81 * A fast, rough count of the number of objects in the repository. 82 * These two fields are not meant for direct access. Use 83 * odb_count_objects() instead. 84 */ 85 unsigned long object_count; 86 unsigned object_count_flags; 87 unsigned object_count_valid : 1; 88 }; 89 90 enum odb_new_flags { 91 /* 92 * Honor environment variables when constructing the object database 93 * sources. This makes us respect the following environment variables: 94 * 95 * - GIT_OBJECT_DIRECTORY to override the primary object directory. 96 * 97 * - GIT_ALTERNATE_OBJECT_DIRECTORIES to override alternates. 98 * 99 * Environment variables may be backend-specific. 100 */ 101 ODB_NEW_HONOR_ENV = (1 << 0), 102 }; 103 104 /* 105 * Create a new object database for the given repository. 106 * 107 * If the primary source parameter is set it will override the usual primary 108 * object directory derived from the repository's common directory. The 109 * alternate sources are expected to be a PATH_SEP-separated list of secondary 110 * sources. Note that these alternate sources will be added in addition to, not 111 * instead of, the alternates identified by the primary source. 112 * 113 * Returns the newly created object database. 114 */ 115 struct object_database *odb_new(struct repository *repo, 116 enum odb_new_flags flags); 117 118 /* Free the object database and release all resources. */ 119 void odb_free(struct object_database *o); 120 121 enum odb_optimize_strategy { 122 ODB_OPTIMIZE_INCREMENTAL, 123 ODB_OPTIMIZE_GEOMETRIC, 124 }; 125 126 enum odb_optimize_flags { 127 /* Enable verbose logging and progress reporting. */ 128 ODB_OPTIMIZE_VERBOSE = (1 << 0), 129 130 /* Perform auto-maintenance, only optimizing objects as required. */ 131 ODB_OPTIMIZE_AUTO = (1 << 1), 132 133 /* Recompute existing deltas. */ 134 ODB_OPTIMIZE_NO_REUSE_DELTAS = (1 << 2), 135 }; 136 137 struct odb_optimize_options { 138 enum odb_optimize_strategy strategy; 139 enum odb_optimize_flags flags; 140 const char *prune_expire; 141 const char *expire_to; 142 int depth; 143 int window; 144 145 /* Backend-specific options. */ 146 int keep_largest_pack; 147 int cruft_packs; 148 unsigned long max_cruft_size; 149 }; 150 151 /* 152 * Optimize the object database. Returns 0 on success, a negative error code 153 * otherwise. 154 */ 155 int odb_optimize(struct object_database *odb, 156 const struct odb_optimize_options *opts); 157 158 /* 159 * Check whether optimization of the object database is required given the 160 * provided options. Returns true if optimization should be performed, false 161 * otherwise. 162 */ 163 bool odb_optimize_required(struct object_database *odb, 164 const struct odb_optimize_options *opts); 165 166 /* 167 * Close the object database and all of its sources so that any held resources 168 * will be released. The database can still be used after closing it, in which 169 * case these resources may be reallocated. 170 */ 171 void odb_close(struct object_database *o); 172 173 enum odb_prepare_flags { 174 /* 175 * Flush caches, reload alternates and then re-prepare each object 176 * source so that new objects may become accessible. 177 */ 178 ODB_PREPARE_FLUSH_CACHES = (1 << 0), 179 }; 180 181 /* 182 * Prepare the object database for use. Calling this function is generally not 183 * needed, but can be useful in case the caller wants to pre-open individual 184 * sources. 185 */ 186 void odb_prepare(struct object_database *o, enum odb_prepare_flags flags); 187 188 /* Equivalent to `odb_prepare(o, ODB_PREPARE_FLUSH_CACHES)`. */ 189 void odb_reprepare(struct object_database *o); 190 191 enum odb_fsck_flags { 192 /* 193 * If set, perform a full consistency check for the full object 194 * database, including all of its sources and the contents of their 195 * optimized formats. Otherwise, only check the local source, and 196 * restrict checks of its optimized formats to cheap structural 197 * verification of their metadata. 198 */ 199 ODB_FSCK_FULL = (1 << 0), 200 201 /* Display a progress meter, if sensible. */ 202 ODB_FSCK_PROGRESS = (1 << 1), 203 204 /* Be extra verbose when checking the database. */ 205 ODB_FSCK_VERBOSE = (1 << 2), 206 }; 207 208 /* Options that shall be passed to `odb_fsck()`. */ 209 struct odb_fsck_options { 210 enum odb_fsck_flags flags; 211 212 int (*object_cb)(const struct object_id *oid, enum object_type type, 213 unsigned long size, void *buffer, int *eaten, void *cb_data); 214 void *object_payload; 215 }; 216 217 /* 218 * Run backend-specific integrity checks on all object sources. Each source 219 * performs the checks appropriate to its type. Returns 0 on success, a 220 * negative error code otherwise. 221 */ 222 int odb_fsck(struct object_database *odb, struct odb_fsck_options *opts); 223 224 /* 225 * Iterate through all alternates of the database and execute the provided 226 * callback function for each of them. Stop iterating once the callback 227 * function returns a non-zero value, in which case the value is bubbled up 228 * from the callback. 229 */ 230 typedef int odb_for_each_alternate_fn(struct odb_files_dir *, void *); 231 int odb_for_each_alternate(struct object_database *odb, 232 odb_for_each_alternate_fn cb, void *payload); 233 234 /* 235 * Iterate through all alternates of the database and yield their respective 236 * references. 237 */ 238 typedef void odb_for_each_alternate_ref_fn(const struct object_id *oid, void *); 239 void odb_for_each_alternate_ref(struct object_database *odb, 240 odb_for_each_alternate_ref_fn cb, void *payload); 241 242 /* 243 * Create a temporary file rooted in the primary alternate's directory, or die 244 * on failure. The filename is taken from "pattern", which should have the 245 * usual "XXXXXX" trailer, and the resulting filename is written into the 246 * "template" buffer. Returns the open descriptor. 247 */ 248 int odb_mkstemp(struct object_database *odb, 249 struct strbuf *temp_filename, const char *pattern); 250 251 /* 252 * Check whether the object database has any alternates. The primary object 253 * source does not count as alternate. 254 */ 255 int odb_has_alternates(struct object_database *odb); 256 257 /* 258 * Read an object from the database. Returns the object data and assigns object 259 * type and size to the `type` and `size` pointers, if these pointers are 260 * non-NULL. Returns a `NULL` pointer in case the object does not exist. 261 * 262 * This function dies on corrupt objects; the callers who want to deal with 263 * them should arrange to call odb_read_object_info_extended() and give error 264 * messages themselves. 265 */ 266 void *odb_read_object(struct object_database *odb, 267 const struct object_id *oid, 268 enum object_type *type, 269 size_t *size); 270 271 void *odb_read_object_peeled(struct object_database *odb, 272 const struct object_id *oid, 273 enum object_type required_type, 274 size_t *size, 275 struct object_id *oid_ret); 276 277 /* 278 * Add an object file to the in-memory object store, without writing it 279 * to disk. 280 * 281 * Callers are responsible for calling write_object_file to record the 282 * object in persistent storage before writing any other new objects 283 * that reference it. 284 */ 285 int odb_pretend_object(struct object_database *odb, 286 void *buf, size_t len, enum object_type type, 287 struct object_id *oid); 288 289 /* 290 * Object database source information that can be used to uniquely identify an 291 * object and learn more about how exactly it is stored. 292 */ 293 struct odb_source_info { 294 /* The source that this object has been looked up from. */ 295 struct odb_source *source; 296 297 /* 298 * Backend-specific information about the specific object. This can be 299 * used for example to uniquely identify a given object in case it 300 * exists multiple times. 301 */ 302 union { 303 /* 304 * struct { 305 * ... Nothing to expose in this case 306 * } cached; 307 * struct { 308 * ... Nothing to expose in this case 309 * } loose; 310 */ 311 struct { 312 struct packed_git *pack; 313 off_t offset; 314 enum packed_object_type { 315 PACKED_OBJECT_TYPE_UNKNOWN, 316 PACKED_OBJECT_TYPE_FULL, 317 PACKED_OBJECT_TYPE_OFS_DELTA, 318 PACKED_OBJECT_TYPE_REF_DELTA, 319 } type; 320 } packed; 321 } u; 322 }; 323 324 /* 325 * The object info contains the query and response that is to be used for 326 * functions that end up reading object information. Callers are expected to 327 * populate pointers whose information they want to request. 328 */ 329 struct object_info { 330 /* The object type. */ 331 enum object_type *typep; 332 333 /* The inflated object size in bytes. */ 334 size_t *sizep; 335 336 /* The object size as stored on disk. */ 337 off_t *disk_sizep; 338 339 /* 340 * The base the object is deltified against, in case it is stored as a 341 * delta. 342 */ 343 struct object_id *delta_base_oid; 344 345 /* The object contents. Ownership of memory goes over to the caller. */ 346 void **contentp; 347 348 /* 349 * The time the given looked-up object has been last modified. 350 * 351 * Note: the mtime may be ambiguous in case the object exists multiple 352 * times in the object database. It is thus _not_ recommended to use 353 * this field outside of contexts where you would read every instance 354 * of the object, like for example with `odb_for_each_object()`. As it 355 * is impossible to say at the ODB level what the intent of the caller 356 * is (e.g. whether to find the oldest or newest object), it is the 357 * responsibility of the caller to disambiguate the mtimes. 358 */ 359 time_t *mtimep; 360 361 /* 362 * Backend-specific information that tells the caller where exactly an 363 * object was looked up from. This information should help disambiguate 364 * object lookups in case the same object exists in multiple sources, 365 * or multiple times in the same source. 366 */ 367 struct odb_source_info *source_infop; 368 369 /* 370 * object-info protocol specific. Set by the protocol when the remote 371 * does not recognize the requested object. 372 */ 373 unsigned int unrecognized:1; 374 }; 375 376 /* 377 * Initializer for a "struct object_info" that wants no items. You may 378 * also memset() the memory to all-zeroes. 379 */ 380 #define OBJECT_INFO_INIT { 0 } 381 382 /* Flags that can be passed to `odb_read_object_info_extended()`. */ 383 enum object_info_flags { 384 /* Invoke lookup_replace_object() on the given hash. */ 385 OBJECT_INFO_LOOKUP_REPLACE = (1 << 0), 386 387 /* Do not reprepare object sources when the first lookup has failed. */ 388 OBJECT_INFO_QUICK = (1 << 1), 389 390 /* 391 * Do not attempt to fetch the object if missing (even if fetch_is_missing is 392 * nonzero). 393 */ 394 OBJECT_INFO_SKIP_FETCH_OBJECT = (1 << 2), 395 396 /* Die if object corruption (not just an object being missing) was detected. */ 397 OBJECT_INFO_DIE_IF_CORRUPT = (1 << 3), 398 399 /* 400 * This is meant for bulk prefetching of missing blobs in a partial 401 * clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK. 402 */ 403 OBJECT_INFO_FOR_PREFETCH = (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK), 404 }; 405 406 enum odb_read_status { 407 /* The read was successful. */ 408 ODB_READ_OK = 0, 409 /* The read resulted in a generic error. */ 410 ODB_READ_ERROR = -1, 411 /* The object could not be found. */ 412 ODB_READ_NOT_FOUND = -2, 413 }; 414 415 /* 416 * Read object info from the object database and populate the `object_info` 417 * structure. Returns 0 on success, a negative error code otherwise. 418 */ 419 enum odb_read_status odb_read_object_info_extended(struct object_database *odb, 420 const struct object_id *oid, 421 struct object_info *oi, 422 enum object_info_flags flags); 423 424 /* 425 * Read a subset of object info for the given object ID. Returns an `enum 426 * object_type` on success, a negative error code otherwise. If successful and 427 * `sizep` is non-NULL, then the size of the object will be written to the 428 * pointer. 429 */ 430 int odb_read_object_info(struct object_database *odb, 431 const struct object_id *oid, 432 size_t *sizep); 433 434 enum odb_has_object_flags { 435 /* Retry packed storage after checking packed and loose storage */ 436 ODB_HAS_OBJECT_RECHECK_PACKED = (1 << 0), 437 /* Allow fetching the object in case the repository has a promisor remote. */ 438 ODB_HAS_OBJECT_FETCH_PROMISOR = (1 << 1), 439 }; 440 441 /* 442 * Returns 1 if the object exists. This function will not lazily fetch objects 443 * in a partial clone by default. 444 */ 445 int odb_has_object(struct object_database *odb, 446 const struct object_id *oid, 447 enum odb_has_object_flags flags); 448 449 int odb_freshen_object(struct object_database *odb, 450 const struct object_id *oid); 451 452 void odb_assert_oid_type(struct object_database *odb, 453 const struct object_id *oid, enum object_type expect); 454 455 /* 456 * Enabling the object read lock allows multiple threads to safely call the 457 * following functions in parallel: odb_read_object(), 458 * odb_read_object_peeled(), odb_read_object_info() and odb(). 459 * 460 * obj_read_lock() and obj_read_unlock() may also be used to protect other 461 * section which cannot execute in parallel with object reading. Since the used 462 * lock is a recursive mutex, these sections can even contain calls to object 463 * reading functions. However, beware that in these cases zlib inflation won't 464 * be performed in parallel, losing performance. 465 * 466 * TODO: odb_read_object_info_extended()'s call stack has a recursive behavior. If 467 * any of its callees end up calling it, this recursive call won't benefit from 468 * parallel inflation. 469 */ 470 void enable_obj_read_lock(void); 471 void disable_obj_read_lock(void); 472 473 extern int obj_read_use_lock; 474 extern pthread_mutex_t obj_read_mutex; 475 476 static inline void obj_read_lock(void) 477 { 478 if(obj_read_use_lock) 479 pthread_mutex_lock(&obj_read_mutex); 480 } 481 482 static inline void obj_read_unlock(void) 483 { 484 if(obj_read_use_lock) 485 pthread_mutex_unlock(&obj_read_mutex); 486 } 487 488 /* Flags for for_each_*_object(). */ 489 enum odb_for_each_object_flags { 490 /* Iterate only over local objects, not alternates. */ 491 ODB_FOR_EACH_OBJECT_LOCAL_ONLY = (1<<0), 492 493 /* Only iterate over packs obtained from the promisor remote. */ 494 ODB_FOR_EACH_OBJECT_PROMISOR_ONLY = (1<<1), 495 496 /* 497 * Visit objects within a pack in packfile order rather than .idx order 498 */ 499 ODB_FOR_EACH_OBJECT_PACK_ORDER = (1<<2), 500 501 /* Only iterate over packs that are not marked as kept in-core. */ 502 ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS = (1<<3), 503 504 /* Only iterate over packs that do not have .keep files. */ 505 ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4), 506 }; 507 508 /* 509 * A callback function that can be used to iterate through objects. If given, 510 * the optional `oi` parameter will be populated the same as if you would call 511 * `odb_read_object_info()`. 512 * 513 * Returning a non-zero error code will cause iteration to abort. The error 514 * code will be propagated. 515 */ 516 typedef int (*odb_for_each_object_cb)(const struct object_id *oid, 517 struct object_info *oi, 518 void *cb_data); 519 520 /* 521 * Options that can be passed to `odb_for_each_object()` and its 522 * backend-specific implementations. 523 */ 524 struct odb_for_each_object_options { 525 /* A bitfield of `odb_for_each_object_flags`. */ 526 enum odb_for_each_object_flags flags; 527 528 /* 529 * If set, only iterate through objects whose first `prefix_hex_len` 530 * hex characters matches the given prefix. 531 */ 532 const struct object_id *prefix; 533 size_t prefix_hex_len; 534 535 /* 536 * Optional object filter that allows backends to skip yielding 537 * objects that are excluded by the filter as an optimization. The 538 * filter is a best-effort hint: backends may use it to skip 539 * excluded objects (e.g. by consulting a reachability bitmap), but 540 * are also free to ignore it entirely and yield every object. As a 541 * consequence, callers must re-apply the filter on yielded objects 542 * if they require strict filtering semantics. 543 */ 544 const struct list_objects_filter_options *filter; 545 }; 546 547 /* 548 * Iterate through all objects contained in the object database. Note that 549 * objects may be iterated over multiple times in case they are either stored 550 * in different backends or in case they are stored in multiple sources. 551 * If an object info request is given, then the object info will be read and 552 * passed to the callback as if `odb_read_object_info()` was called for the 553 * object. 554 * 555 * Returning a non-zero error code from the callback function will cause 556 * iteration to abort. The error code will be propagated. 557 * 558 * Returns 0 on success, a negative error code in case a failure occurred, or 559 * an arbitrary non-zero error code returned by the callback itself. 560 */ 561 int odb_for_each_object_ext(struct object_database *odb, 562 const struct object_info *request, 563 odb_for_each_object_cb cb, 564 void *cb_data, 565 const struct odb_for_each_object_options *opts); 566 567 /* Same as `odb_for_each_object_ext()` with `opts.flags` set to the given flags. */ 568 int odb_for_each_object(struct object_database *odb, 569 const struct object_info *request, 570 odb_for_each_object_cb cb, 571 void *cb_data, 572 enum odb_for_each_object_flags flags); 573 574 enum odb_count_objects_flags { 575 /* 576 * Instead of providing an accurate count, allow the number of objects 577 * to be approximated. Details of how this approximation works are 578 * subject to the specific source's implementation. 579 */ 580 ODB_COUNT_OBJECTS_APPROXIMATE = (1 << 0), 581 }; 582 583 /* 584 * Count the number of objects in the given object database. This object count 585 * may double-count objects that are stored in multiple backends, or which are 586 * stored multiple times in a single backend. 587 * 588 * Returns 0 on success, a negative error code otherwise. The number of objects 589 * will be assigned to the `out` pointer on success. 590 */ 591 int odb_count_objects(struct object_database *odb, 592 enum odb_count_objects_flags flags, 593 unsigned long *out); 594 595 /* 596 * Given an object ID, find the minimum required length required to make the 597 * object ID unique across the whole object database. 598 * 599 * The `min_len` determines the minimum abbreviated length that'll be returned 600 * by this function. If `min_len < 0`, then the function will set a sensible 601 * default minimum abbreviation length. 602 * 603 * Returns 0 on success, a negative error code otherwise. The computed length 604 * will be assigned to `*out`. 605 */ 606 int odb_find_abbrev_len(struct object_database *odb, 607 const struct object_id *oid, 608 int min_len, 609 unsigned *out); 610 611 enum odb_write_object_flags { 612 /* 613 * By default, `odb_write_object()` does not actually write anything 614 * into the object store, but only computes the object ID. This flag 615 * changes that so that the object will be written as a loose object 616 * and persisted. 617 */ 618 ODB_WRITE_OBJECT_PERSIST = (1 << 0), 619 620 /* 621 * Do not print an error in case something goes wrong. 622 */ 623 ODB_WRITE_OBJECT_SILENT = (1 << 1), 624 }; 625 626 /* 627 * Write an object into the object database. The object is being written into 628 * the local alternate of the repository. If provided, the object ID of the 629 * final object is written into `oid`. 630 * 631 * If the caller provides a `compat_oid`, then this compatibility object hash 632 * will be stored instead of computing the compatibility hash ad-hoc. 633 * 634 * Returns 0 on success, a negative error code otherwise. 635 */ 636 int odb_write_object_ext(struct object_database *odb, 637 const void *buf, unsigned long len, 638 enum object_type type, 639 struct object_id *oid, 640 const struct object_id *compat_oid, 641 enum odb_write_object_flags flags); 642 643 static inline int odb_write_object(struct object_database *odb, 644 const void *buf, unsigned long len, 645 enum object_type type, 646 struct object_id *oid) 647 { 648 return odb_write_object_ext(odb, buf, len, type, oid, NULL, 0); 649 } 650 651 struct odb_stream; 652 653 int odb_write_object_stream(struct object_database *odb, 654 struct odb_stream *stream, 655 struct object_id *oid); 656 657 /* 658 * Options for generating a packfile via `odb_generate_pack()`. 659 */ 660 struct odb_generate_pack_options { 661 /* Tips of the object graph that shall be packed. */ 662 struct oid_array wants; 663 664 /* 665 * Boundary of the object graph. Objects reachable from any of these 666 * tips are expected to already be available to whoever consumes the 667 * pack and shall thus not be packed. 668 */ 669 struct oid_array haves; 670 671 /* 672 * The shallow boundary that shall be used when computing object 673 * reachability. When set, any shallow information of the repository 674 * itself shall be ignored in favor of these objects. 675 */ 676 struct oid_array shallows; 677 678 /* 679 * Pre-expanded object filter specification that limits the set of 680 * objects that shall be packed. May be `NULL` in case no filter shall 681 * be applied. 682 */ 683 const char *filter_spec; 684 685 /* 686 * Protocols that may be used to offload objects via packfile URIs. 687 * May be `NULL` in case packfile URIs shall not be used. 688 */ 689 const struct string_list *uri_protocols; 690 691 /* 692 * Hook command that shall be executed instead of the internal 693 * machinery to generate the pack. It is up to the specific backend 694 * whether or not this hook is supported. May be `NULL` in case no 695 * hook shall be executed. 696 */ 697 const char *pack_objects_hook; 698 699 /* 700 * File descriptor that the generated pack shall be written to. If set 701 * to `-1`, a pipe will be created and exposed via the pack generator's 702 * `out` field. If set to `0`, the pack will be written to the standard 703 * output stream. Otherwise, the provided descriptor will be written to 704 * and is consumed by the generator. 705 */ 706 int pack_fd; 707 708 /* 709 * File descriptor that progress output shall be written to. The same 710 * semantics as for `pack_fd` apply, except that `0` will cause the 711 * generator to write to stderr instead of stdout. 712 */ 713 int progress_fd; 714 715 /* Whether to print progress or not. */ 716 enum { 717 /* Don't print progress output. */ 718 ODB_GENERATE_PACK_PROGRESS_NONE, 719 720 /* 721 * Print progress while computing the packfile, but stop 722 * printing progress once starting to write it. 723 */ 724 ODB_GENERATE_PACK_PROGRESS_STANDARD, 725 726 /* 727 * Similar to STANDARD, but also print progress when writing 728 * the packfile. 729 */ 730 ODB_GENERATE_PACK_PROGRESS_VERBOSE, 731 } progress; 732 733 /* Allow the pack to contain deltas against unpacked objects. */ 734 unsigned thin:1; 735 736 /* Use offset deltas instead of reference deltas. */ 737 unsigned ofs_delta:1; 738 739 /* Include unasked-for annotated tags of packed objects. */ 740 unsigned include_tag:1; 741 742 /* The generated pack is destined for a shallow consumer. */ 743 unsigned shallow:1; 744 745 /* Allow objects that may be missing due to a promisor remote. */ 746 unsigned missing_allow_promisor:1; 747 748 /* Do not use bitmap indices when computing reachability. */ 749 unsigned disable_bitmaps:1; 750 }; 751 752 #define ODB_GENERATE_PACK_OPTIONS_INIT { \ 753 .wants = OID_ARRAY_INIT, \ 754 .haves = OID_ARRAY_INIT, \ 755 .shallows = OID_ARRAY_INIT, \ 756 .pack_fd = -1, \ 757 } 758 759 /* Release resources associated with the options. */ 760 void odb_generate_pack_options_release(struct odb_generate_pack_options *opts); 761 762 /* 763 * A handle for an ongoing packfile generation as started via 764 * `odb_generate_pack()`. 765 */ 766 struct odb_pack_generator { 767 /* 768 * File descriptor from which the generated pack can be read. Only set 769 * when the pack generation was started with `pack_fd == -1`. The 770 * caller is responsible for closing the descriptor. 771 */ 772 int out; 773 774 /* 775 * File descriptor from which progress output can be read. Only set 776 * when the pack generation was started with `progress_fd == -1`. The 777 * caller is responsible for closing the descriptor. 778 */ 779 int err; 780 781 /* 782 * Callback function to finish this generator. This callback is 783 * expected to wait for the packfile generation to complete and to then 784 * free the generator itself. 785 */ 786 int (*finish)(struct odb_pack_generator *); 787 }; 788 789 /* 790 * Start generating a packfile from the object database with the given 791 * options. The pack is generated asynchronously; the caller is expected to 792 * consume the file descriptors exposed via the pack generator and to then 793 * wait for completion via `odb_pack_generator_finish()`. 794 * 795 * Returns 0 on success and populates the `out` pointer with the pack 796 * generator. Returns a negative error code otherwise. 797 */ 798 int odb_generate_pack(struct object_database *odb, 799 struct odb_pack_generator **out, 800 const struct odb_generate_pack_options *opts); 801 802 /* 803 * Wait for the packfile generation to complete and free the pack generator. 804 * Returns 0 on success, a negative error code otherwise. 805 */ 806 int odb_pack_generator_finish(struct odb_pack_generator *generator); 807 808 #endif /* ODB_H */