47
#define SZ_FMT PRIuMAX
48
static inline uintmax_t sz_fmt(size_t s) { return s; }
49
50
+void packfile_list_clear(struct packfile_list *list)
51
+{
52
+ struct packfile_list_entry *e, *next;
53
+
54
+ for (e = list->head; e; e = next) {
55
+ next = e->next;
56
+ free(e);
57
+ }
58
+
59
+ list->head = list->tail = NULL;
60
+}
61
+
62
+static struct packfile_list_entry *packfile_list_remove_internal(struct packfile_list *list,
63
+ struct packed_git *pack)
64
+{
65
+ struct packfile_list_entry *e, *prev;
66
+
67
+ for (e = list->head, prev = NULL; e; prev = e, e = e->next) {
68
+ if (e->pack != pack)
69
+ continue;
70
+
71
+ if (prev)
72
+ prev->next = e->next;
73
+ if (list->head == e)
74
+ list->head = e->next;
75
+ if (list->tail == e)
76
+ list->tail = prev;
77
+
78
+ return e;
79
+ }
80
+
81
+ return NULL;
82
+}
83
+
84
+void packfile_list_remove(struct packfile_list *list, struct packed_git *pack)
85
+{
86
+ free(packfile_list_remove_internal(list, pack));
87
+}
88
+
89
+void packfile_list_prepend(struct packfile_list *list, struct packed_git *pack)
90
+{
91
+ struct packfile_list_entry *entry;
92
+
93
+ entry = packfile_list_remove_internal(list, pack);
94
+ if (!entry) {
95
+ entry = xmalloc(sizeof(*entry));
96
+ entry->pack = pack;
97
+ }
98
+ entry->next = list->head;
99
+
100
+ list->head = entry;
101
+ if (!list->tail)
102
+ list->tail = entry;
103
+}
104
+
105
+void packfile_list_append(struct packfile_list *list, struct packed_git *pack)
106
+{
107
+ struct packfile_list_entry *entry;
108
+
109
+ entry = packfile_list_remove_internal(list, pack);
110
+ if (!entry) {
111
+ entry = xmalloc(sizeof(*entry));
112
+ entry->pack = pack;
113
+ }
114
+ entry->next = NULL;
115
+
116
+ if (list->tail) {
117
+ list->tail->next = entry;
118
+ list->tail = entry;
119
+ } else {
120
+ list->head = list->tail = entry;
121
+ }
122
+}
123
+
124
void pack_report(struct repository *repo)
125
{
126
fprintf(stderr,
1069
{
1070
struct packed_git *p;
1071
998
- INIT_LIST_HEAD(&store->mru);
1072
+ packfile_list_clear(&store->mru);
1073
1074
for (p = store->packs; p; p = p->next)
1001
- list_add_tail(&p->mru, &store->mru);
1075
+ packfile_list_append(&store->mru, p);
1076
}
1077
1078
void packfile_store_prepare(struct packfile_store *store)
1114
return store->packs;
1115
}
1116
1043
-struct list_head *packfile_store_get_packs_mru(struct packfile_store *store)
1117
+struct packfile_list_entry *packfile_store_get_packs_mru(struct packfile_store *store)
1118
{
1119
packfile_store_prepare(store);
1046
- return &store->mru;
1120
+ return store->mru.head;
1121
}
1122
1123
/*
2122
2123
int find_pack_entry(struct repository *r, const struct object_id *oid, struct pack_entry *e)
2124
{
2051
- struct list_head *pos;
2125
+ struct packfile_list_entry *l;
2126
2127
packfile_store_prepare(r->objects->packfiles);
2128
2133
if (!r->objects->packfiles->packs)
2134
return 0;
2135
2062
- list_for_each(pos, &r->objects->packfiles->mru) {
2063
- struct packed_git *p = list_entry(pos, struct packed_git, mru);
2136
+ for (l = r->objects->packfiles->mru.head; l; l = l->next) {
2137
+ struct packed_git *p = l->pack;
2138
+
2139
if (!p->multi_pack_index && fill_pack_entry(oid, e, p)) {
2065
- list_move(&p->mru, &r->objects->packfiles->mru);
2140
+ packfile_list_prepend(&r->objects->packfiles->mru, p);
2141
return 1;
2142
}
2143
}
2389
struct packfile_store *store;
2390
CALLOC_ARRAY(store, 1);
2391
store->odb = odb;
2317
- INIT_LIST_HEAD(&store->mru);
2392
strmap_init(&store->packs_by_path);
2393
return store;
2394
}