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