* Create a newly-allocated `snapshot` of the `packed-refs` file in * its current state and return it. The return value will already have * its reference count incremented. * * A comment line of the form "# pack-refs with: " may contain zero or * more traits. We interpret the traits as follows: * * Neither `peeled` nor `fully-peeled`: * * Probably no references are peeled. But if th
| 704 | * The references in this file are known to be sorted by refname. |
| 705 | */ |
| 706 | static struct snapshot *create_snapshot(struct packed_ref_store *refs) |
| 707 | { |
| 708 | struct snapshot *snapshot = xcalloc(1, sizeof(*snapshot)); |
| 709 | int sorted = 0; |
| 710 | |
| 711 | snapshot->refs = refs; |
| 712 | acquire_snapshot(snapshot); |
| 713 | snapshot->peeled = PEELED_NONE; |
| 714 | |
| 715 | if (!load_contents(snapshot)) |
| 716 | return snapshot; |
| 717 | |
| 718 | /* If the file has a header line, process it: */ |
| 719 | if (snapshot->buf < snapshot->eof && *snapshot->buf == '#') { |
| 720 | char *tmp, *p, *eol; |
| 721 | struct string_list traits = STRING_LIST_INIT_NODUP; |
| 722 | |
| 723 | eol = memchr(snapshot->buf, '\n', |
| 724 | snapshot->eof - snapshot->buf); |
| 725 | if (!eol) |
| 726 | die_unterminated_line(refs->path, |
| 727 | snapshot->buf, |
| 728 | snapshot->eof - snapshot->buf); |
| 729 | |
| 730 | tmp = xmemdupz(snapshot->buf, eol - snapshot->buf); |
| 731 | |
| 732 | if (!skip_prefix(tmp, "# pack-refs with: ", (const char **)&p)) |
| 733 | die_invalid_line(refs->path, |
| 734 | snapshot->buf, |
| 735 | snapshot->eof - snapshot->buf); |
| 736 | |
| 737 | string_list_split_in_place(&traits, p, " ", -1); |
| 738 | |
| 739 | if (unsorted_string_list_has_string(&traits, "fully-peeled")) |
| 740 | snapshot->peeled = PEELED_FULLY; |
| 741 | else if (unsorted_string_list_has_string(&traits, "peeled")) |
| 742 | snapshot->peeled = PEELED_TAGS; |
| 743 | |
| 744 | sorted = unsorted_string_list_has_string(&traits, "sorted"); |
| 745 | |
| 746 | /* perhaps other traits later as well */ |
| 747 | |
| 748 | /* The "+ 1" is for the LF character. */ |
| 749 | snapshot->start = eol + 1; |
| 750 | |
| 751 | string_list_clear(&traits, 0); |
| 752 | free(tmp); |
| 753 | } |
| 754 | |
| 755 | verify_buffer_safe(snapshot); |
| 756 | |
| 757 | if (!sorted) { |
| 758 | sort_snapshot(snapshot); |
| 759 | |
| 760 | /* |
| 761 | * Reordering the records might have moved a short one |
| 762 | * to the end of the buffer, so verify the buffer's |
| 763 | * safety again: |
no test coverage detected