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/packfile-list.c # 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 / packfile-list.c` 87 lines ยท 1856 bytes Raw Blame History 1 #include "git-compat-util.h" 2 #include "packfile.h" 3 #include "packfile-list.h" 4 5 void packfile_list_clear(struct packfile_list *list) 6 { 7 struct packfile_list_entry *e, *next; 8 9 for (e = list->head; e; e = next) { 10 next = e->next; 11 free(e); 12 } 13 14 list->head = list->tail = NULL; 15 } 16 17 static struct packfile_list_entry *packfile_list_remove_internal(struct packfile_list *list, 18 struct packed_git *pack) 19 { 20 struct packfile_list_entry *e, *prev; 21 22 for (e = list->head, prev = NULL; e; prev = e, e = e->next) { 23 if (e->pack != pack) 24 continue; 25 26 if (prev) 27 prev->next = e->next; 28 if (list->head == e) 29 list->head = e->next; 30 if (list->tail == e) 31 list->tail = prev; 32 33 return e; 34 } 35 36 return NULL; 37 } 38 39 void packfile_list_remove(struct packfile_list *list, struct packed_git *pack) 40 { 41 free(packfile_list_remove_internal(list, pack)); 42 } 43 44 void packfile_list_prepend(struct packfile_list *list, struct packed_git *pack) 45 { 46 struct packfile_list_entry *entry; 47 48 entry = packfile_list_remove_internal(list, pack); 49 if (!entry) { 50 entry = xmalloc(sizeof(*entry)); 51 entry->pack = pack; 52 } 53 entry->next = list->head; 54 55 list->head = entry; 56 if (!list->tail) 57 list->tail = entry; 58 } 59 60 void packfile_list_append(struct packfile_list *list, struct packed_git *pack, 61 int skip_dup_check) 62 { 63 struct packfile_list_entry *entry; 64 65 entry = skip_dup_check ? NULL : packfile_list_remove_internal(list, pack); 66 if (!entry) { 67 entry = xmalloc(sizeof(*entry)); 68 entry->pack = pack; 69 } 70 entry->next = NULL; 71 72 if (list->tail) { 73 list->tail->next = entry; 74 list->tail = entry; 75 } else { 76 list->head = list->tail = entry; 77 } 78 } 79 80 struct packed_git *packfile_list_find_oid(struct packfile_list_entry *packs, 81 const struct object_id *oid) 82 { 83 for (; packs; packs = packs->next) 84 if (find_pack_entry_one(oid, packs->pack)) 85 return packs->pack; 86 return NULL; 87 }