mirror of
https://github.com/git-for-windows/git.git
synced 2026-06-14 05:33:00 -05:00
In the next commit we're about to introduce the "packed" object database source. This source will embed a packfile list, and consequently we'll have to include "packfile.h" to make the struct definition available. This will unfortunately lead to a cyclic dependency that we cannot resolve with a forward declaration. Split out the code that relates to the packfile list into a separate compilation unit so that both "packfile.h" and "odb/source-packed.h" can include it. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
87 lines
1.8 KiB
C
87 lines
1.8 KiB
C
#include "git-compat-util.h"
|
|
#include "packfile.h"
|
|
#include "packfile-list.h"
|
|
|
|
void packfile_list_clear(struct packfile_list *list)
|
|
{
|
|
struct packfile_list_entry *e, *next;
|
|
|
|
for (e = list->head; e; e = next) {
|
|
next = e->next;
|
|
free(e);
|
|
}
|
|
|
|
list->head = list->tail = NULL;
|
|
}
|
|
|
|
static struct packfile_list_entry *packfile_list_remove_internal(struct packfile_list *list,
|
|
struct packed_git *pack)
|
|
{
|
|
struct packfile_list_entry *e, *prev;
|
|
|
|
for (e = list->head, prev = NULL; e; prev = e, e = e->next) {
|
|
if (e->pack != pack)
|
|
continue;
|
|
|
|
if (prev)
|
|
prev->next = e->next;
|
|
if (list->head == e)
|
|
list->head = e->next;
|
|
if (list->tail == e)
|
|
list->tail = prev;
|
|
|
|
return e;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
void packfile_list_remove(struct packfile_list *list, struct packed_git *pack)
|
|
{
|
|
free(packfile_list_remove_internal(list, pack));
|
|
}
|
|
|
|
void packfile_list_prepend(struct packfile_list *list, struct packed_git *pack)
|
|
{
|
|
struct packfile_list_entry *entry;
|
|
|
|
entry = packfile_list_remove_internal(list, pack);
|
|
if (!entry) {
|
|
entry = xmalloc(sizeof(*entry));
|
|
entry->pack = pack;
|
|
}
|
|
entry->next = list->head;
|
|
|
|
list->head = entry;
|
|
if (!list->tail)
|
|
list->tail = entry;
|
|
}
|
|
|
|
void packfile_list_append(struct packfile_list *list, struct packed_git *pack)
|
|
{
|
|
struct packfile_list_entry *entry;
|
|
|
|
entry = packfile_list_remove_internal(list, pack);
|
|
if (!entry) {
|
|
entry = xmalloc(sizeof(*entry));
|
|
entry->pack = pack;
|
|
}
|
|
entry->next = NULL;
|
|
|
|
if (list->tail) {
|
|
list->tail->next = entry;
|
|
list->tail = entry;
|
|
} else {
|
|
list->head = list->tail = entry;
|
|
}
|
|
}
|
|
|
|
struct packed_git *packfile_list_find_oid(struct packfile_list_entry *packs,
|
|
const struct object_id *oid)
|
|
{
|
|
for (; packs; packs = packs->next)
|
|
if (find_pack_entry_one(oid, packs->pack))
|
|
return packs->pack;
|
|
return NULL;
|
|
}
|