1#include"../cache.h" 2#include"../config.h" 3#include"../refs.h" 4#include"refs-internal.h" 5#include"packed-backend.h" 6#include"../iterator.h" 7#include"../lockfile.h" 8 9enum mmap_strategy { 10/* 11 * Don't use mmap() at all for reading `packed-refs`. 12 */ 13 MMAP_NONE, 14 15/* 16 * Can use mmap() for reading `packed-refs`, but the file must 17 * not remain mmapped. This is the usual option on Windows, 18 * where you cannot rename a new version of a file onto a file 19 * that is currently mmapped. 20 */ 21 MMAP_TEMPORARY, 22 23/* 24 * It is OK to leave the `packed-refs` file mmapped while 25 * arbitrary other code is running. 26 */ 27 MMAP_OK 28}; 29 30#if defined(NO_MMAP) 31static enum mmap_strategy mmap_strategy = MMAP_NONE; 32#elif defined(MMAP_PREVENTS_DELETE) 33static enum mmap_strategy mmap_strategy = MMAP_TEMPORARY; 34#else 35static enum mmap_strategy mmap_strategy = MMAP_OK; 36#endif 37 38struct packed_ref_store; 39 40/* 41 * A `snapshot` represents one snapshot of a `packed-refs` file. 42 * 43 * Normally, this will be a mmapped view of the contents of the 44 * `packed-refs` file at the time the snapshot was created. However, 45 * if the `packed-refs` file was not sorted, this might point at heap 46 * memory holding the contents of the `packed-refs` file with its 47 * records sorted by refname. 48 * 49 * `snapshot` instances are reference counted (via 50 * `acquire_snapshot()` and `release_snapshot()`). This is to prevent 51 * an instance from disappearing while an iterator is still iterating 52 * over it. Instances are garbage collected when their `referrers` 53 * count goes to zero. 54 * 55 * The most recent `snapshot`, if available, is referenced by the 56 * `packed_ref_store`. Its freshness is checked whenever 57 * `get_snapshot()` is called; if the existing snapshot is obsolete, a 58 * new snapshot is taken. 59 */ 60struct snapshot { 61/* 62 * A back-pointer to the packed_ref_store with which this 63 * snapshot is associated: 64 */ 65struct packed_ref_store *refs; 66 67/* Is the `packed-refs` file currently mmapped? */ 68int mmapped; 69 70/* 71 * The contents of the `packed-refs` file. If the file was 72 * already sorted, this points at the mmapped contents of the 73 * file. If not, this points at heap-allocated memory 74 * containing the contents, sorted. If there were no contents 75 * (e.g., because the file didn't exist), `buf` and `eof` are 76 * both NULL. 77 */ 78char*buf, *eof; 79 80/* The size of the header line, if any; otherwise, 0: */ 81size_t header_len; 82 83/* 84 * What is the peeled state of the `packed-refs` file that 85 * this snapshot represents? (This is usually determined from 86 * the file's header.) 87 */ 88enum{ PEELED_NONE, PEELED_TAGS, PEELED_FULLY } peeled; 89 90/* 91 * Count of references to this instance, including the pointer 92 * from `packed_ref_store::snapshot`, if any. The instance 93 * will not be freed as long as the reference count is 94 * nonzero. 95 */ 96unsigned int referrers; 97 98/* 99 * The metadata of the `packed-refs` file from which this 100 * snapshot was created, used to tell if the file has been 101 * replaced since we read it. 102 */ 103struct stat_validity validity; 104}; 105 106/* 107 * A `ref_store` representing references stored in a `packed-refs` 108 * file. It implements the `ref_store` interface, though it has some 109 * limitations: 110 * 111 * - It cannot store symbolic references. 112 * 113 * - It cannot store reflogs. 114 * 115 * - It does not support reference renaming (though it could). 116 * 117 * On the other hand, it can be locked outside of a reference 118 * transaction. In that case, it remains locked even after the 119 * transaction is done and the new `packed-refs` file is activated. 120 */ 121struct packed_ref_store { 122struct ref_store base; 123 124unsigned int store_flags; 125 126/* The path of the "packed-refs" file: */ 127char*path; 128 129/* 130 * A snapshot of the values read from the `packed-refs` file, 131 * if it might still be current; otherwise, NULL. 132 */ 133struct snapshot *snapshot; 134 135/* 136 * Lock used for the "packed-refs" file. Note that this (and 137 * thus the enclosing `packed_ref_store`) must not be freed. 138 */ 139struct lock_file lock; 140 141/* 142 * Temporary file used when rewriting new contents to the 143 * "packed-refs" file. Note that this (and thus the enclosing 144 * `packed_ref_store`) must not be freed. 145 */ 146struct tempfile *tempfile; 147}; 148 149/* 150 * Increment the reference count of `*snapshot`. 151 */ 152static voidacquire_snapshot(struct snapshot *snapshot) 153{ 154 snapshot->referrers++; 155} 156 157/* 158 * If the buffer in `snapshot` is active, then either munmap the 159 * memory and close the file, or free the memory. Then set the buffer 160 * pointers to NULL. 161 */ 162static voidclear_snapshot_buffer(struct snapshot *snapshot) 163{ 164if(snapshot->mmapped) { 165if(munmap(snapshot->buf, snapshot->eof - snapshot->buf)) 166die_errno("error ummapping packed-refs file%s", 167 snapshot->refs->path); 168 snapshot->mmapped =0; 169}else{ 170free(snapshot->buf); 171} 172 snapshot->buf = snapshot->eof = NULL; 173 snapshot->header_len =0; 174} 175 176/* 177 * Decrease the reference count of `*snapshot`. If it goes to zero, 178 * free `*snapshot` and return true; otherwise return false. 179 */ 180static intrelease_snapshot(struct snapshot *snapshot) 181{ 182if(!--snapshot->referrers) { 183stat_validity_clear(&snapshot->validity); 184clear_snapshot_buffer(snapshot); 185free(snapshot); 186return1; 187}else{ 188return0; 189} 190} 191 192struct ref_store *packed_ref_store_create(const char*path, 193unsigned int store_flags) 194{ 195struct packed_ref_store *refs =xcalloc(1,sizeof(*refs)); 196struct ref_store *ref_store = (struct ref_store *)refs; 197 198base_ref_store_init(ref_store, &refs_be_packed); 199 refs->store_flags = store_flags; 200 201 refs->path =xstrdup(path); 202return ref_store; 203} 204 205/* 206 * Downcast `ref_store` to `packed_ref_store`. Die if `ref_store` is 207 * not a `packed_ref_store`. Also die if `packed_ref_store` doesn't 208 * support at least the flags specified in `required_flags`. `caller` 209 * is used in any necessary error messages. 210 */ 211static struct packed_ref_store *packed_downcast(struct ref_store *ref_store, 212unsigned int required_flags, 213const char*caller) 214{ 215struct packed_ref_store *refs; 216 217if(ref_store->be != &refs_be_packed) 218die("BUG: ref_store is type\"%s\"not\"packed\"in%s", 219 ref_store->be->name, caller); 220 221 refs = (struct packed_ref_store *)ref_store; 222 223if((refs->store_flags & required_flags) != required_flags) 224die("BUG: unallowed operation (%s), requires%x, has%x\n", 225 caller, required_flags, refs->store_flags); 226 227return refs; 228} 229 230static voidclear_snapshot(struct packed_ref_store *refs) 231{ 232if(refs->snapshot) { 233struct snapshot *snapshot = refs->snapshot; 234 235 refs->snapshot = NULL; 236release_snapshot(snapshot); 237} 238} 239 240static NORETURN voiddie_unterminated_line(const char*path, 241const char*p,size_t len) 242{ 243if(len <80) 244die("unterminated line in%s: %.*s", path, (int)len, p); 245else 246die("unterminated line in%s: %.75s...", path, p); 247} 248 249static NORETURN voiddie_invalid_line(const char*path, 250const char*p,size_t len) 251{ 252const char*eol =memchr(p,'\n', len); 253 254if(!eol) 255die_unterminated_line(path, p, len); 256else if(eol - p <80) 257die("unexpected line in%s: %.*s", path, (int)(eol - p), p); 258else 259die("unexpected line in%s: %.75s...", path, p); 260 261} 262 263struct snapshot_record { 264const char*start; 265size_t len; 266}; 267 268static intcmp_packed_ref_records(const void*v1,const void*v2) 269{ 270const struct snapshot_record *e1 = v1, *e2 = v2; 271const char*r1 = e1->start + GIT_SHA1_HEXSZ +1; 272const char*r2 = e2->start + GIT_SHA1_HEXSZ +1; 273 274while(1) { 275if(*r1 =='\n') 276return*r2 =='\n'?0: -1; 277if(*r1 != *r2) { 278if(*r2 =='\n') 279return1; 280else 281return(unsigned char)*r1 < (unsigned char)*r2 ? -1: +1; 282} 283 r1++; 284 r2++; 285} 286} 287 288/* 289 * Compare a snapshot record at `rec` to the specified NUL-terminated 290 * refname. 291 */ 292static intcmp_record_to_refname(const char*rec,const char*refname) 293{ 294const char*r1 = rec + GIT_SHA1_HEXSZ +1; 295const char*r2 = refname; 296 297while(1) { 298if(*r1 =='\n') 299return*r2 ? -1:0; 300if(!*r2) 301return1; 302if(*r1 != *r2) 303return(unsigned char)*r1 < (unsigned char)*r2 ? -1: +1; 304 r1++; 305 r2++; 306} 307} 308 309/* 310 * `snapshot->buf` is not known to be sorted. Check whether it is, and 311 * if not, sort it into new memory and munmap/free the old storage. 312 */ 313static voidsort_snapshot(struct snapshot *snapshot) 314{ 315struct snapshot_record *records = NULL; 316size_t alloc =0, nr =0; 317int sorted =1; 318const char*pos, *eof, *eol; 319size_t len, i; 320char*new_buffer, *dst; 321 322 pos = snapshot->buf + snapshot->header_len; 323 eof = snapshot->eof; 324 len = eof - pos; 325 326if(!len) 327return; 328 329/* 330 * Initialize records based on a crude estimate of the number 331 * of references in the file (we'll grow it below if needed): 332 */ 333ALLOC_GROW(records, len /80+20, alloc); 334 335while(pos < eof) { 336 eol =memchr(pos,'\n', eof - pos); 337if(!eol) 338/* The safety check should prevent this. */ 339BUG("unterminated line found in packed-refs"); 340if(eol - pos < GIT_SHA1_HEXSZ +2) 341die_invalid_line(snapshot->refs->path, 342 pos, eof - pos); 343 eol++; 344if(eol < eof && *eol =='^') { 345/* 346 * Keep any peeled line together with its 347 * reference: 348 */ 349const char*peeled_start = eol; 350 351 eol =memchr(peeled_start,'\n', eof - peeled_start); 352if(!eol) 353/* The safety check should prevent this. */ 354BUG("unterminated peeled line found in packed-refs"); 355 eol++; 356} 357 358ALLOC_GROW(records, nr +1, alloc); 359 records[nr].start = pos; 360 records[nr].len = eol - pos; 361 nr++; 362 363if(sorted && 364 nr >1&& 365cmp_packed_ref_records(&records[nr -2], 366&records[nr -1]) >=0) 367 sorted =0; 368 369 pos = eol; 370} 371 372if(sorted) 373goto cleanup; 374 375/* We need to sort the memory. First we sort the records array: */ 376QSORT(records, nr, cmp_packed_ref_records); 377 378/* 379 * Allocate a new chunk of memory, and copy the old memory to 380 * the new in the order indicated by `records` (not bothering 381 * with the header line): 382 */ 383 new_buffer =xmalloc(len); 384for(dst = new_buffer, i =0; i < nr; i++) { 385memcpy(dst, records[i].start, records[i].len); 386 dst += records[i].len; 387} 388 389/* 390 * Now munmap the old buffer and use the sorted buffer in its 391 * place: 392 */ 393clear_snapshot_buffer(snapshot); 394 snapshot->buf = new_buffer; 395 snapshot->eof = new_buffer + len; 396 snapshot->header_len =0; 397 398cleanup: 399free(records); 400} 401 402/* 403 * Return a pointer to the start of the record that contains the 404 * character `*p` (which must be within the buffer). If no other 405 * record start is found, return `buf`. 406 */ 407static const char*find_start_of_record(const char*buf,const char*p) 408{ 409while(p > buf && (p[-1] !='\n'|| p[0] =='^')) 410 p--; 411return p; 412} 413 414/* 415 * Return a pointer to the start of the record following the record 416 * that contains `*p`. If none is found before `end`, return `end`. 417 */ 418static const char*find_end_of_record(const char*p,const char*end) 419{ 420while(++p < end && (p[-1] !='\n'|| p[0] =='^')) 421; 422return p; 423} 424 425/* 426 * We want to be able to compare mmapped reference records quickly, 427 * without totally parsing them. We can do so because the records are 428 * LF-terminated, and the refname should start exactly (GIT_SHA1_HEXSZ 429 * + 1) bytes past the beginning of the record. 430 * 431 * But what if the `packed-refs` file contains garbage? We're willing 432 * to tolerate not detecting the problem, as long as we don't produce 433 * totally garbled output (we can't afford to check the integrity of 434 * the whole file during every Git invocation). But we do want to be 435 * sure that we never read past the end of the buffer in memory and 436 * perform an illegal memory access. 437 * 438 * Guarantee that minimum level of safety by verifying that the last 439 * record in the file is LF-terminated, and that it has at least 440 * (GIT_SHA1_HEXSZ + 1) characters before the LF. Die if either of 441 * these checks fails. 442 */ 443static voidverify_buffer_safe(struct snapshot *snapshot) 444{ 445const char*buf = snapshot->buf + snapshot->header_len; 446const char*eof = snapshot->eof; 447const char*last_line; 448 449if(buf == eof) 450return; 451 452 last_line =find_start_of_record(buf, eof -1); 453if(*(eof -1) !='\n'|| eof - last_line < GIT_SHA1_HEXSZ +2) 454die_invalid_line(snapshot->refs->path, 455 last_line, eof - last_line); 456} 457 458/* 459 * Depending on `mmap_strategy`, either mmap or read the contents of 460 * the `packed-refs` file into the snapshot. Return 1 if the file 461 * existed and was read, or 0 if the file was absent. Die on errors. 462 */ 463static intload_contents(struct snapshot *snapshot) 464{ 465int fd; 466struct stat st; 467size_t size; 468 ssize_t bytes_read; 469 470 fd =open(snapshot->refs->path, O_RDONLY); 471if(fd <0) { 472if(errno == ENOENT) { 473/* 474 * This is OK; it just means that no 475 * "packed-refs" file has been written yet, 476 * which is equivalent to it being empty, 477 * which is its state when initialized with 478 * zeros. 479 */ 480return0; 481}else{ 482die_errno("couldn't read%s", snapshot->refs->path); 483} 484} 485 486stat_validity_update(&snapshot->validity, fd); 487 488if(fstat(fd, &st) <0) 489die_errno("couldn't stat%s", snapshot->refs->path); 490 size =xsize_t(st.st_size); 491 492switch(mmap_strategy) { 493case MMAP_NONE: 494 snapshot->buf =xmalloc(size); 495 bytes_read =read_in_full(fd, snapshot->buf, size); 496if(bytes_read <0|| bytes_read != size) 497die_errno("couldn't read%s", snapshot->refs->path); 498 snapshot->eof = snapshot->buf + size; 499 snapshot->mmapped =0; 500break; 501case MMAP_TEMPORARY: 502case MMAP_OK: 503 snapshot->buf =xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd,0); 504 snapshot->eof = snapshot->buf + size; 505 snapshot->mmapped =1; 506break; 507} 508close(fd); 509 510return1; 511} 512 513/* 514 * Find the place in `snapshot->buf` where the start of the record for 515 * `refname` starts. If `mustexist` is true and the reference doesn't 516 * exist, then return NULL. If `mustexist` is false and the reference 517 * doesn't exist, then return the point where that reference would be 518 * inserted. In the latter mode, `refname` doesn't have to be a proper 519 * reference name; for example, one could search for "refs/replace/" 520 * to find the start of any replace references. 521 * 522 * The record is sought using a binary search, so `snapshot->buf` must 523 * be sorted. 524 */ 525static const char*find_reference_location(struct snapshot *snapshot, 526const char*refname,int mustexist) 527{ 528/* 529 * This is not *quite* a garden-variety binary search, because 530 * the data we're searching is made up of records, and we 531 * always need to find the beginning of a record to do a 532 * comparison. A "record" here is one line for the reference 533 * itself and zero or one peel lines that start with '^'. Our 534 * loop invariant is described in the next two comments. 535 */ 536 537/* 538 * A pointer to the character at the start of a record whose 539 * preceding records all have reference names that come 540 * *before* `refname`. 541 */ 542const char*lo = snapshot->buf + snapshot->header_len; 543 544/* 545 * A pointer to a the first character of a record whose 546 * reference name comes *after* `refname`. 547 */ 548const char*hi = snapshot->eof; 549 550while(lo < hi) { 551const char*mid, *rec; 552int cmp; 553 554 mid = lo + (hi - lo) /2; 555 rec =find_start_of_record(lo, mid); 556 cmp =cmp_record_to_refname(rec, refname); 557if(cmp <0) { 558 lo =find_end_of_record(mid, hi); 559}else if(cmp >0) { 560 hi = rec; 561}else{ 562return rec; 563} 564} 565 566if(mustexist) 567return NULL; 568else 569return lo; 570} 571 572/* 573 * Create a newly-allocated `snapshot` of the `packed-refs` file in 574 * its current state and return it. The return value will already have 575 * its reference count incremented. 576 * 577 * A comment line of the form "# pack-refs with: " may contain zero or 578 * more traits. We interpret the traits as follows: 579 * 580 * Neither `peeled` nor `fully-peeled`: 581 * 582 * Probably no references are peeled. But if the file contains a 583 * peeled value for a reference, we will use it. 584 * 585 * `peeled`: 586 * 587 * References under "refs/tags/", if they *can* be peeled, *are* 588 * peeled in this file. References outside of "refs/tags/" are 589 * probably not peeled even if they could have been, but if we find 590 * a peeled value for such a reference we will use it. 591 * 592 * `fully-peeled`: 593 * 594 * All references in the file that can be peeled are peeled. 595 * Inversely (and this is more important), any references in the 596 * file for which no peeled value is recorded is not peelable. This 597 * trait should typically be written alongside "peeled" for 598 * compatibility with older clients, but we do not require it 599 * (i.e., "peeled" is a no-op if "fully-peeled" is set). 600 * 601 * `sorted`: 602 * 603 * The references in this file are known to be sorted by refname. 604 */ 605static struct snapshot *create_snapshot(struct packed_ref_store *refs) 606{ 607struct snapshot *snapshot =xcalloc(1,sizeof(*snapshot)); 608int sorted =0; 609 610 snapshot->refs = refs; 611acquire_snapshot(snapshot); 612 snapshot->peeled = PEELED_NONE; 613 614if(!load_contents(snapshot)) 615return snapshot; 616 617/* If the file has a header line, process it: */ 618if(snapshot->buf < snapshot->eof && *snapshot->buf =='#') { 619struct strbuf tmp = STRBUF_INIT; 620char*p; 621const char*eol; 622struct string_list traits = STRING_LIST_INIT_NODUP; 623 624 eol =memchr(snapshot->buf,'\n', 625 snapshot->eof - snapshot->buf); 626if(!eol) 627die_unterminated_line(refs->path, 628 snapshot->buf, 629 snapshot->eof - snapshot->buf); 630 631strbuf_add(&tmp, snapshot->buf, eol - snapshot->buf); 632 633if(!skip_prefix(tmp.buf,"# pack-refs with:", (const char**)&p)) 634die_invalid_line(refs->path, 635 snapshot->buf, 636 snapshot->eof - snapshot->buf); 637 638string_list_split_in_place(&traits, p,' ', -1); 639 640if(unsorted_string_list_has_string(&traits,"fully-peeled")) 641 snapshot->peeled = PEELED_FULLY; 642else if(unsorted_string_list_has_string(&traits,"peeled")) 643 snapshot->peeled = PEELED_TAGS; 644 645 sorted =unsorted_string_list_has_string(&traits,"sorted"); 646 647/* perhaps other traits later as well */ 648 649/* The "+ 1" is for the LF character. */ 650 snapshot->header_len = eol +1- snapshot->buf; 651 652string_list_clear(&traits,0); 653strbuf_release(&tmp); 654} 655 656verify_buffer_safe(snapshot); 657 658if(!sorted) { 659sort_snapshot(snapshot); 660 661/* 662 * Reordering the records might have moved a short one 663 * to the end of the buffer, so verify the buffer's 664 * safety again: 665 */ 666verify_buffer_safe(snapshot); 667} 668 669if(mmap_strategy != MMAP_OK && snapshot->mmapped) { 670/* 671 * We don't want to leave the file mmapped, so we are 672 * forced to make a copy now: 673 */ 674size_t size = snapshot->eof - 675(snapshot->buf + snapshot->header_len); 676char*buf_copy =xmalloc(size); 677 678memcpy(buf_copy, snapshot->buf + snapshot->header_len, size); 679clear_snapshot_buffer(snapshot); 680 snapshot->buf = buf_copy; 681 snapshot->eof = buf_copy + size; 682} 683 684return snapshot; 685} 686 687/* 688 * Check that `refs->snapshot` (if present) still reflects the 689 * contents of the `packed-refs` file. If not, clear the snapshot. 690 */ 691static voidvalidate_snapshot(struct packed_ref_store *refs) 692{ 693if(refs->snapshot && 694!stat_validity_check(&refs->snapshot->validity, refs->path)) 695clear_snapshot(refs); 696} 697 698/* 699 * Get the `snapshot` for the specified packed_ref_store, creating and 700 * populating it if it hasn't been read before or if the file has been 701 * changed (according to its `validity` field) since it was last read. 702 * On the other hand, if we hold the lock, then assume that the file 703 * hasn't been changed out from under us, so skip the extra `stat()` 704 * call in `stat_validity_check()`. This function does *not* increase 705 * the snapshot's reference count on behalf of the caller. 706 */ 707static struct snapshot *get_snapshot(struct packed_ref_store *refs) 708{ 709if(!is_lock_file_locked(&refs->lock)) 710validate_snapshot(refs); 711 712if(!refs->snapshot) 713 refs->snapshot =create_snapshot(refs); 714 715return refs->snapshot; 716} 717 718static intpacked_read_raw_ref(struct ref_store *ref_store, 719const char*refname,struct object_id *oid, 720struct strbuf *referent,unsigned int*type) 721{ 722struct packed_ref_store *refs = 723packed_downcast(ref_store, REF_STORE_READ,"read_raw_ref"); 724struct snapshot *snapshot =get_snapshot(refs); 725const char*rec; 726 727*type =0; 728 729 rec =find_reference_location(snapshot, refname,1); 730 731if(!rec) { 732/* refname is not a packed reference. */ 733 errno = ENOENT; 734return-1; 735} 736 737if(get_oid_hex(rec, oid)) 738die_invalid_line(refs->path, rec, snapshot->eof - rec); 739 740*type = REF_ISPACKED; 741return0; 742} 743 744/* 745 * This value is set in `base.flags` if the peeled value of the 746 * current reference is known. In that case, `peeled` contains the 747 * correct peeled value for the reference, which might be `null_oid` 748 * if the reference is not a tag or if it is broken. 749 */ 750#define REF_KNOWS_PEELED 0x40 751 752/* 753 * An iterator over a snapshot of a `packed-refs` file. 754 */ 755struct packed_ref_iterator { 756struct ref_iterator base; 757 758struct snapshot *snapshot; 759 760/* The current position in the snapshot's buffer: */ 761const char*pos; 762 763/* The end of the part of the buffer that will be iterated over: */ 764const char*eof; 765 766/* Scratch space for current values: */ 767struct object_id oid, peeled; 768struct strbuf refname_buf; 769 770unsigned int flags; 771}; 772 773/* 774 * Move the iterator to the next record in the snapshot, without 775 * respect for whether the record is actually required by the current 776 * iteration. Adjust the fields in `iter` and return `ITER_OK` or 777 * `ITER_DONE`. This function does not free the iterator in the case 778 * of `ITER_DONE`. 779 */ 780static intnext_record(struct packed_ref_iterator *iter) 781{ 782const char*p = iter->pos, *eol; 783 784strbuf_reset(&iter->refname_buf); 785 786if(iter->pos == iter->eof) 787return ITER_DONE; 788 789 iter->base.flags = REF_ISPACKED; 790 791if(iter->eof - p < GIT_SHA1_HEXSZ +2|| 792parse_oid_hex(p, &iter->oid, &p) || 793!isspace(*p++)) 794die_invalid_line(iter->snapshot->refs->path, 795 iter->pos, iter->eof - iter->pos); 796 797 eol =memchr(p,'\n', iter->eof - p); 798if(!eol) 799die_unterminated_line(iter->snapshot->refs->path, 800 iter->pos, iter->eof - iter->pos); 801 802strbuf_add(&iter->refname_buf, p, eol - p); 803 iter->base.refname = iter->refname_buf.buf; 804 805if(check_refname_format(iter->base.refname, REFNAME_ALLOW_ONELEVEL)) { 806if(!refname_is_safe(iter->base.refname)) 807die("packed refname is dangerous:%s", 808 iter->base.refname); 809oidclr(&iter->oid); 810 iter->base.flags |= REF_BAD_NAME | REF_ISBROKEN; 811} 812if(iter->snapshot->peeled == PEELED_FULLY || 813(iter->snapshot->peeled == PEELED_TAGS && 814starts_with(iter->base.refname,"refs/tags/"))) 815 iter->base.flags |= REF_KNOWS_PEELED; 816 817 iter->pos = eol +1; 818 819if(iter->pos < iter->eof && *iter->pos =='^') { 820 p = iter->pos +1; 821if(iter->eof - p < GIT_SHA1_HEXSZ +1|| 822parse_oid_hex(p, &iter->peeled, &p) || 823*p++ !='\n') 824die_invalid_line(iter->snapshot->refs->path, 825 iter->pos, iter->eof - iter->pos); 826 iter->pos = p; 827 828/* 829 * Regardless of what the file header said, we 830 * definitely know the value of *this* reference. But 831 * we suppress it if the reference is broken: 832 */ 833if((iter->base.flags & REF_ISBROKEN)) { 834oidclr(&iter->peeled); 835 iter->base.flags &= ~REF_KNOWS_PEELED; 836}else{ 837 iter->base.flags |= REF_KNOWS_PEELED; 838} 839}else{ 840oidclr(&iter->peeled); 841} 842 843return ITER_OK; 844} 845 846static intpacked_ref_iterator_advance(struct ref_iterator *ref_iterator) 847{ 848struct packed_ref_iterator *iter = 849(struct packed_ref_iterator *)ref_iterator; 850int ok; 851 852while((ok =next_record(iter)) == ITER_OK) { 853if(iter->flags & DO_FOR_EACH_PER_WORKTREE_ONLY && 854ref_type(iter->base.refname) != REF_TYPE_PER_WORKTREE) 855continue; 856 857if(!(iter->flags & DO_FOR_EACH_INCLUDE_BROKEN) && 858!ref_resolves_to_object(iter->base.refname, &iter->oid, 859 iter->flags)) 860continue; 861 862return ITER_OK; 863} 864 865if(ref_iterator_abort(ref_iterator) != ITER_DONE) 866 ok = ITER_ERROR; 867 868return ok; 869} 870 871static intpacked_ref_iterator_peel(struct ref_iterator *ref_iterator, 872struct object_id *peeled) 873{ 874struct packed_ref_iterator *iter = 875(struct packed_ref_iterator *)ref_iterator; 876 877if((iter->base.flags & REF_KNOWS_PEELED)) { 878oidcpy(peeled, &iter->peeled); 879returnis_null_oid(&iter->peeled) ? -1:0; 880}else if((iter->base.flags & (REF_ISBROKEN | REF_ISSYMREF))) { 881return-1; 882}else{ 883return!!peel_object(&iter->oid, peeled); 884} 885} 886 887static intpacked_ref_iterator_abort(struct ref_iterator *ref_iterator) 888{ 889struct packed_ref_iterator *iter = 890(struct packed_ref_iterator *)ref_iterator; 891int ok = ITER_DONE; 892 893strbuf_release(&iter->refname_buf); 894release_snapshot(iter->snapshot); 895base_ref_iterator_free(ref_iterator); 896return ok; 897} 898 899static struct ref_iterator_vtable packed_ref_iterator_vtable = { 900 packed_ref_iterator_advance, 901 packed_ref_iterator_peel, 902 packed_ref_iterator_abort 903}; 904 905static struct ref_iterator *packed_ref_iterator_begin( 906struct ref_store *ref_store, 907const char*prefix,unsigned int flags) 908{ 909struct packed_ref_store *refs; 910struct snapshot *snapshot; 911const char*start; 912struct packed_ref_iterator *iter; 913struct ref_iterator *ref_iterator; 914unsigned int required_flags = REF_STORE_READ; 915 916if(!(flags & DO_FOR_EACH_INCLUDE_BROKEN)) 917 required_flags |= REF_STORE_ODB; 918 refs =packed_downcast(ref_store, required_flags,"ref_iterator_begin"); 919 920/* 921 * Note that `get_snapshot()` internally checks whether the 922 * snapshot is up to date with what is on disk, and re-reads 923 * it if not. 924 */ 925 snapshot =get_snapshot(refs); 926 927if(!snapshot->buf) 928returnempty_ref_iterator_begin(); 929 930 iter =xcalloc(1,sizeof(*iter)); 931 ref_iterator = &iter->base; 932base_ref_iterator_init(ref_iterator, &packed_ref_iterator_vtable,1); 933 934 iter->snapshot = snapshot; 935acquire_snapshot(snapshot); 936 937if(prefix && *prefix) 938 start =find_reference_location(snapshot, prefix,0); 939else 940 start = snapshot->buf + snapshot->header_len; 941 942 iter->pos = start; 943 iter->eof = snapshot->eof; 944strbuf_init(&iter->refname_buf,0); 945 946 iter->base.oid = &iter->oid; 947 948 iter->flags = flags; 949 950if(prefix && *prefix) 951/* Stop iteration after we've gone *past* prefix: */ 952 ref_iterator =prefix_ref_iterator_begin(ref_iterator, prefix,0); 953 954return ref_iterator; 955} 956 957/* 958 * Write an entry to the packed-refs file for the specified refname. 959 * If peeled is non-NULL, write it as the entry's peeled value. On 960 * error, return a nonzero value and leave errno set at the value left 961 * by the failing call to `fprintf()`. 962 */ 963static intwrite_packed_entry(FILE*fh,const char*refname, 964const struct object_id *oid, 965const struct object_id *peeled) 966{ 967if(fprintf(fh,"%s %s\n",oid_to_hex(oid), refname) <0|| 968(peeled &&fprintf(fh,"^%s\n",oid_to_hex(peeled)) <0)) 969return-1; 970 971return0; 972} 973 974intpacked_refs_lock(struct ref_store *ref_store,int flags,struct strbuf *err) 975{ 976struct packed_ref_store *refs = 977packed_downcast(ref_store, REF_STORE_WRITE | REF_STORE_MAIN, 978"packed_refs_lock"); 979static int timeout_configured =0; 980static int timeout_value =1000; 981 982if(!timeout_configured) { 983git_config_get_int("core.packedrefstimeout", &timeout_value); 984 timeout_configured =1; 985} 986 987/* 988 * Note that we close the lockfile immediately because we 989 * don't write new content to it, but rather to a separate 990 * tempfile. 991 */ 992if(hold_lock_file_for_update_timeout( 993&refs->lock, 994 refs->path, 995 flags, timeout_value) <0) { 996unable_to_lock_message(refs->path, errno, err); 997return-1; 998} 9991000if(close_lock_file_gently(&refs->lock)) {1001strbuf_addf(err,"unable to close%s:%s", refs->path,strerror(errno));1002rollback_lock_file(&refs->lock);1003return-1;1004}10051006/*1007 * Now that we hold the `packed-refs` lock, make sure that our1008 * snapshot matches the current version of the file. Normally1009 * `get_snapshot()` does that for us, but that function1010 * assumes that when the file is locked, any existing snapshot1011 * is still valid. We've just locked the file, but it might1012 * have changed the moment *before* we locked it.1013 */1014validate_snapshot(refs);10151016/*1017 * Now make sure that the packed-refs file as it exists in the1018 * locked state is loaded into the snapshot:1019 */1020get_snapshot(refs);1021return0;1022}10231024voidpacked_refs_unlock(struct ref_store *ref_store)1025{1026struct packed_ref_store *refs =packed_downcast(1027 ref_store,1028 REF_STORE_READ | REF_STORE_WRITE,1029"packed_refs_unlock");10301031if(!is_lock_file_locked(&refs->lock))1032die("BUG: packed_refs_unlock() called when not locked");1033rollback_lock_file(&refs->lock);1034}10351036intpacked_refs_is_locked(struct ref_store *ref_store)1037{1038struct packed_ref_store *refs =packed_downcast(1039 ref_store,1040 REF_STORE_READ | REF_STORE_WRITE,1041"packed_refs_is_locked");10421043returnis_lock_file_locked(&refs->lock);1044}10451046/*1047 * The packed-refs header line that we write out. Perhaps other traits1048 * will be added later.1049 *1050 * Note that earlier versions of Git used to parse these traits by1051 * looking for " trait " in the line. For this reason, the space after1052 * the colon and the trailing space are required.1053 */1054static const char PACKED_REFS_HEADER[] =1055"# pack-refs with: peeled fully-peeled sorted\n";10561057static intpacked_init_db(struct ref_store *ref_store,struct strbuf *err)1058{1059/* Nothing to do. */1060return0;1061}10621063/*1064 * Write the packed refs from the current snapshot to the packed-refs1065 * tempfile, incorporating any changes from `updates`. `updates` must1066 * be a sorted string list whose keys are the refnames and whose util1067 * values are `struct ref_update *`. On error, rollback the tempfile,1068 * write an error message to `err`, and return a nonzero value.1069 *1070 * The packfile must be locked before calling this function and will1071 * remain locked when it is done.1072 */1073static intwrite_with_updates(struct packed_ref_store *refs,1074struct string_list *updates,1075struct strbuf *err)1076{1077struct ref_iterator *iter = NULL;1078size_t i;1079int ok;1080FILE*out;1081struct strbuf sb = STRBUF_INIT;1082char*packed_refs_path;10831084if(!is_lock_file_locked(&refs->lock))1085die("BUG: write_with_updates() called while unlocked");10861087/*1088 * If packed-refs is a symlink, we want to overwrite the1089 * symlinked-to file, not the symlink itself. Also, put the1090 * staging file next to it:1091 */1092 packed_refs_path =get_locked_file_path(&refs->lock);1093strbuf_addf(&sb,"%s.new", packed_refs_path);1094free(packed_refs_path);1095 refs->tempfile =create_tempfile(sb.buf);1096if(!refs->tempfile) {1097strbuf_addf(err,"unable to create file%s:%s",1098 sb.buf,strerror(errno));1099strbuf_release(&sb);1100return-1;1101}1102strbuf_release(&sb);11031104 out =fdopen_tempfile(refs->tempfile,"w");1105if(!out) {1106strbuf_addf(err,"unable to fdopen packed-refs tempfile:%s",1107strerror(errno));1108goto error;1109}11101111if(fprintf(out,"%s", PACKED_REFS_HEADER) <0)1112goto write_error;11131114/*1115 * We iterate in parallel through the current list of refs and1116 * the list of updates, processing an entry from at least one1117 * of the lists each time through the loop. When the current1118 * list of refs is exhausted, set iter to NULL. When the list1119 * of updates is exhausted, leave i set to updates->nr.1120 */1121 iter =packed_ref_iterator_begin(&refs->base,"",1122 DO_FOR_EACH_INCLUDE_BROKEN);1123if((ok =ref_iterator_advance(iter)) != ITER_OK)1124 iter = NULL;11251126 i =0;11271128while(iter || i < updates->nr) {1129struct ref_update *update = NULL;1130int cmp;11311132if(i >= updates->nr) {1133 cmp = -1;1134}else{1135 update = updates->items[i].util;11361137if(!iter)1138 cmp = +1;1139else1140 cmp =strcmp(iter->refname, update->refname);1141}11421143if(!cmp) {1144/*1145 * There is both an old value and an update1146 * for this reference. Check the old value if1147 * necessary:1148 */1149if((update->flags & REF_HAVE_OLD)) {1150if(is_null_oid(&update->old_oid)) {1151strbuf_addf(err,"cannot update ref '%s': "1152"reference already exists",1153 update->refname);1154goto error;1155}else if(oidcmp(&update->old_oid, iter->oid)) {1156strbuf_addf(err,"cannot update ref '%s': "1157"is at%sbut expected%s",1158 update->refname,1159oid_to_hex(iter->oid),1160oid_to_hex(&update->old_oid));1161goto error;1162}1163}11641165/* Now figure out what to use for the new value: */1166if((update->flags & REF_HAVE_NEW)) {1167/*1168 * The update takes precedence. Skip1169 * the iterator over the unneeded1170 * value.1171 */1172if((ok =ref_iterator_advance(iter)) != ITER_OK)1173 iter = NULL;1174 cmp = +1;1175}else{1176/*1177 * The update doesn't actually want to1178 * change anything. We're done with it.1179 */1180 i++;1181 cmp = -1;1182}1183}else if(cmp >0) {1184/*1185 * There is no old value but there is an1186 * update for this reference. Make sure that1187 * the update didn't expect an existing value:1188 */1189if((update->flags & REF_HAVE_OLD) &&1190!is_null_oid(&update->old_oid)) {1191strbuf_addf(err,"cannot update ref '%s': "1192"reference is missing but expected%s",1193 update->refname,1194oid_to_hex(&update->old_oid));1195goto error;1196}1197}11981199if(cmp <0) {1200/* Pass the old reference through. */12011202struct object_id peeled;1203int peel_error =ref_iterator_peel(iter, &peeled);12041205if(write_packed_entry(out, iter->refname,1206 iter->oid,1207 peel_error ? NULL : &peeled))1208goto write_error;12091210if((ok =ref_iterator_advance(iter)) != ITER_OK)1211 iter = NULL;1212}else if(is_null_oid(&update->new_oid)) {1213/*1214 * The update wants to delete the reference,1215 * and the reference either didn't exist or we1216 * have already skipped it. So we're done with1217 * the update (and don't have to write1218 * anything).1219 */1220 i++;1221}else{1222struct object_id peeled;1223int peel_error =peel_object(&update->new_oid,1224&peeled);12251226if(write_packed_entry(out, update->refname,1227&update->new_oid,1228 peel_error ? NULL : &peeled))1229goto write_error;12301231 i++;1232}1233}12341235if(ok != ITER_DONE) {1236strbuf_addstr(err,"unable to write packed-refs file: "1237"error iterating over old contents");1238goto error;1239}12401241if(close_tempfile_gently(refs->tempfile)) {1242strbuf_addf(err,"error closing file%s:%s",1243get_tempfile_path(refs->tempfile),1244strerror(errno));1245strbuf_release(&sb);1246delete_tempfile(&refs->tempfile);1247return-1;1248}12491250return0;12511252write_error:1253strbuf_addf(err,"error writing to%s:%s",1254get_tempfile_path(refs->tempfile),strerror(errno));12551256error:1257if(iter)1258ref_iterator_abort(iter);12591260delete_tempfile(&refs->tempfile);1261return-1;1262}12631264intis_packed_transaction_needed(struct ref_store *ref_store,1265struct ref_transaction *transaction)1266{1267struct packed_ref_store *refs =packed_downcast(1268 ref_store,1269 REF_STORE_READ,1270"is_packed_transaction_needed");1271struct strbuf referent = STRBUF_INIT;1272size_t i;1273int ret;12741275if(!is_lock_file_locked(&refs->lock))1276BUG("is_packed_transaction_needed() called while unlocked");12771278/*1279 * We're only going to bother returning false for the common,1280 * trivial case that references are only being deleted, their1281 * old values are not being checked, and the old `packed-refs`1282 * file doesn't contain any of those reference(s). This gives1283 * false positives for some other cases that could1284 * theoretically be optimized away:1285 *1286 * 1. It could be that the old value is being verified without1287 * setting a new value. In this case, we could verify the1288 * old value here and skip the update if it agrees. If it1289 * disagrees, we could either let the update go through1290 * (the actual commit would re-detect and report the1291 * problem), or come up with a way of reporting such an1292 * error to *our* caller.1293 *1294 * 2. It could be that a new value is being set, but that it1295 * is identical to the current packed value of the1296 * reference.1297 *1298 * Neither of these cases will come up in the current code,1299 * because the only caller of this function passes to it a1300 * transaction that only includes `delete` updates with no1301 * `old_id`. Even if that ever changes, false positives only1302 * cause an optimization to be missed; they do not affect1303 * correctness.1304 */13051306/*1307 * Start with the cheap checks that don't require old1308 * reference values to be read:1309 */1310for(i =0; i < transaction->nr; i++) {1311struct ref_update *update = transaction->updates[i];13121313if(update->flags & REF_HAVE_OLD)1314/* Have to check the old value -> needed. */1315return1;13161317if((update->flags & REF_HAVE_NEW) && !is_null_oid(&update->new_oid))1318/* Have to set a new value -> needed. */1319return1;1320}13211322/*1323 * The transaction isn't checking any old values nor is it1324 * setting any nonzero new values, so it still might be able1325 * to be skipped. Now do the more expensive check: the update1326 * is needed if any of the updates is a delete, and the old1327 * `packed-refs` file contains a value for that reference.1328 */1329 ret =0;1330for(i =0; i < transaction->nr; i++) {1331struct ref_update *update = transaction->updates[i];1332unsigned int type;1333struct object_id oid;13341335if(!(update->flags & REF_HAVE_NEW))1336/*1337 * This reference isn't being deleted -> not1338 * needed.1339 */1340continue;13411342if(!refs_read_raw_ref(ref_store, update->refname,1343&oid, &referent, &type) ||1344 errno != ENOENT) {1345/*1346 * We have to actually delete that reference1347 * -> this transaction is needed.1348 */1349 ret =1;1350break;1351}1352}13531354strbuf_release(&referent);1355return ret;1356}13571358struct packed_transaction_backend_data {1359/* True iff the transaction owns the packed-refs lock. */1360int own_lock;13611362struct string_list updates;1363};13641365static voidpacked_transaction_cleanup(struct packed_ref_store *refs,1366struct ref_transaction *transaction)1367{1368struct packed_transaction_backend_data *data = transaction->backend_data;13691370if(data) {1371string_list_clear(&data->updates,0);13721373if(is_tempfile_active(refs->tempfile))1374delete_tempfile(&refs->tempfile);13751376if(data->own_lock &&is_lock_file_locked(&refs->lock)) {1377packed_refs_unlock(&refs->base);1378 data->own_lock =0;1379}13801381free(data);1382 transaction->backend_data = NULL;1383}13841385 transaction->state = REF_TRANSACTION_CLOSED;1386}13871388static intpacked_transaction_prepare(struct ref_store *ref_store,1389struct ref_transaction *transaction,1390struct strbuf *err)1391{1392struct packed_ref_store *refs =packed_downcast(1393 ref_store,1394 REF_STORE_READ | REF_STORE_WRITE | REF_STORE_ODB,1395"ref_transaction_prepare");1396struct packed_transaction_backend_data *data;1397size_t i;1398int ret = TRANSACTION_GENERIC_ERROR;13991400/*1401 * Note that we *don't* skip transactions with zero updates,1402 * because such a transaction might be executed for the side1403 * effect of ensuring that all of the references are peeled or1404 * ensuring that the `packed-refs` file is sorted. If the1405 * caller wants to optimize away empty transactions, it should1406 * do so itself.1407 */14081409 data =xcalloc(1,sizeof(*data));1410string_list_init(&data->updates,0);14111412 transaction->backend_data = data;14131414/*1415 * Stick the updates in a string list by refname so that we1416 * can sort them:1417 */1418for(i =0; i < transaction->nr; i++) {1419struct ref_update *update = transaction->updates[i];1420struct string_list_item *item =1421string_list_append(&data->updates, update->refname);14221423/* Store a pointer to update in item->util: */1424 item->util = update;1425}1426string_list_sort(&data->updates);14271428if(ref_update_reject_duplicates(&data->updates, err))1429goto failure;14301431if(!is_lock_file_locked(&refs->lock)) {1432if(packed_refs_lock(ref_store,0, err))1433goto failure;1434 data->own_lock =1;1435}14361437if(write_with_updates(refs, &data->updates, err))1438goto failure;14391440 transaction->state = REF_TRANSACTION_PREPARED;1441return0;14421443failure:1444packed_transaction_cleanup(refs, transaction);1445return ret;1446}14471448static intpacked_transaction_abort(struct ref_store *ref_store,1449struct ref_transaction *transaction,1450struct strbuf *err)1451{1452struct packed_ref_store *refs =packed_downcast(1453 ref_store,1454 REF_STORE_READ | REF_STORE_WRITE | REF_STORE_ODB,1455"ref_transaction_abort");14561457packed_transaction_cleanup(refs, transaction);1458return0;1459}14601461static intpacked_transaction_finish(struct ref_store *ref_store,1462struct ref_transaction *transaction,1463struct strbuf *err)1464{1465struct packed_ref_store *refs =packed_downcast(1466 ref_store,1467 REF_STORE_READ | REF_STORE_WRITE | REF_STORE_ODB,1468"ref_transaction_finish");1469int ret = TRANSACTION_GENERIC_ERROR;1470char*packed_refs_path;14711472clear_snapshot(refs);14731474 packed_refs_path =get_locked_file_path(&refs->lock);1475if(rename_tempfile(&refs->tempfile, packed_refs_path)) {1476strbuf_addf(err,"error replacing%s:%s",1477 refs->path,strerror(errno));1478goto cleanup;1479}14801481 ret =0;14821483cleanup:1484free(packed_refs_path);1485packed_transaction_cleanup(refs, transaction);1486return ret;1487}14881489static intpacked_initial_transaction_commit(struct ref_store *ref_store,1490struct ref_transaction *transaction,1491struct strbuf *err)1492{1493returnref_transaction_commit(transaction, err);1494}14951496static intpacked_delete_refs(struct ref_store *ref_store,const char*msg,1497struct string_list *refnames,unsigned int flags)1498{1499struct packed_ref_store *refs =1500packed_downcast(ref_store, REF_STORE_WRITE,"delete_refs");1501struct strbuf err = STRBUF_INIT;1502struct ref_transaction *transaction;1503struct string_list_item *item;1504int ret;15051506(void)refs;/* We need the check above, but don't use the variable */15071508if(!refnames->nr)1509return0;15101511/*1512 * Since we don't check the references' old_oids, the1513 * individual updates can't fail, so we can pack all of the1514 * updates into a single transaction.1515 */15161517 transaction =ref_store_transaction_begin(ref_store, &err);1518if(!transaction)1519return-1;15201521for_each_string_list_item(item, refnames) {1522if(ref_transaction_delete(transaction, item->string, NULL,1523 flags, msg, &err)) {1524warning(_("could not delete reference%s:%s"),1525 item->string, err.buf);1526strbuf_reset(&err);1527}1528}15291530 ret =ref_transaction_commit(transaction, &err);15311532if(ret) {1533if(refnames->nr ==1)1534error(_("could not delete reference%s:%s"),1535 refnames->items[0].string, err.buf);1536else1537error(_("could not delete references:%s"), err.buf);1538}15391540ref_transaction_free(transaction);1541strbuf_release(&err);1542return ret;1543}15441545static intpacked_pack_refs(struct ref_store *ref_store,unsigned int flags)1546{1547/*1548 * Packed refs are already packed. It might be that loose refs1549 * are packed *into* a packed refs store, but that is done by1550 * updating the packed references via a transaction.1551 */1552return0;1553}15541555static intpacked_create_symref(struct ref_store *ref_store,1556const char*refname,const char*target,1557const char*logmsg)1558{1559die("BUG: packed reference store does not support symrefs");1560}15611562static intpacked_rename_ref(struct ref_store *ref_store,1563const char*oldrefname,const char*newrefname,1564const char*logmsg)1565{1566die("BUG: packed reference store does not support renaming references");1567}15681569static intpacked_copy_ref(struct ref_store *ref_store,1570const char*oldrefname,const char*newrefname,1571const char*logmsg)1572{1573die("BUG: packed reference store does not support copying references");1574}15751576static struct ref_iterator *packed_reflog_iterator_begin(struct ref_store *ref_store)1577{1578returnempty_ref_iterator_begin();1579}15801581static intpacked_for_each_reflog_ent(struct ref_store *ref_store,1582const char*refname,1583 each_reflog_ent_fn fn,void*cb_data)1584{1585return0;1586}15871588static intpacked_for_each_reflog_ent_reverse(struct ref_store *ref_store,1589const char*refname,1590 each_reflog_ent_fn fn,1591void*cb_data)1592{1593return0;1594}15951596static intpacked_reflog_exists(struct ref_store *ref_store,1597const char*refname)1598{1599return0;1600}16011602static intpacked_create_reflog(struct ref_store *ref_store,1603const char*refname,int force_create,1604struct strbuf *err)1605{1606die("BUG: packed reference store does not support reflogs");1607}16081609static intpacked_delete_reflog(struct ref_store *ref_store,1610const char*refname)1611{1612return0;1613}16141615static intpacked_reflog_expire(struct ref_store *ref_store,1616const char*refname,const struct object_id *oid,1617unsigned int flags,1618 reflog_expiry_prepare_fn prepare_fn,1619 reflog_expiry_should_prune_fn should_prune_fn,1620 reflog_expiry_cleanup_fn cleanup_fn,1621void*policy_cb_data)1622{1623return0;1624}16251626struct ref_storage_be refs_be_packed = {1627 NULL,1628"packed",1629 packed_ref_store_create,1630 packed_init_db,1631 packed_transaction_prepare,1632 packed_transaction_finish,1633 packed_transaction_abort,1634 packed_initial_transaction_commit,16351636 packed_pack_refs,1637 packed_create_symref,1638 packed_delete_refs,1639 packed_rename_ref,1640 packed_copy_ref,16411642 packed_ref_iterator_begin,1643 packed_read_raw_ref,16441645 packed_reflog_iterator_begin,1646 packed_for_each_reflog_ent,1647 packed_for_each_reflog_ent_reverse,1648 packed_reflog_exists,1649 packed_create_reflog,1650 packed_delete_reflog,1651 packed_reflog_expire1652};