static struct pack_list * add_pack(struct packed_git *p) { struct pack_list l; unsigned long off = 0, step; const unsigned char *base; if (!p->pack_local && !(alt_odb || verbose)) return NULL; l.pack = p; llist_init(&l.all_objects); if (open_pack_index(p)) return NULL; base = p->index_data; base += 256 * 4 + ((p->index_version < 2) ? 4 : 8); step = the_hash_algo->rawsz + ((p->index_version < 2) ? 4 : 0); while (off < p->num_objects * step) { llist_insert_back(l.all_objects, (const struct object_id *)(base + off)); off += step; } /* this list will be pruned in cmp_two_packs later */ l.unique_objects = llist_copy(l.all_objects); if (p->pack_local) return pack_list_insert(&local_packs, &l); else return pack_list_insert(&altodb_packs, &l); }
static inline struct llist_item *llist_insert_sorted_unique(struct llist *list, const struct object_id *oid, struct llist_item *hint) { struct llist_item *prev = NULL, *l; l = (hint == NULL) ? list->front : hint; while (l) { int cmp = oidcmp(l->oid, oid); if (cmp > 0) { /* we insert before this entry */ return llist_insert(list, prev, oid); } if (!cmp) { /* already exists */ return l; } prev = l; l = l->next; } /* insert at the end */ return llist_insert_back(list, oid); }
static inline struct llist_item *llist_insert_sorted_unique(struct llist *list, const unsigned char *sha1, struct llist_item *hint) { struct llist_item *prev = NULL, *l; l = (hint == NULL) ? list->front : hint; while (l) { int cmp = hashcmp(l->sha1, sha1); if (cmp > 0) { /* we insert before this entry */ return llist_insert(list, prev, sha1); } if (!cmp) { /* already exists */ return l; } prev = l; l = l->next; } /* insert at the end */ return llist_insert_back(list, sha1); }