builtin/pack-redundant: avoid casting buffers to struct object_id

Now that we need our instances of struct object_id to be zero padded, we can no longer cast unsigned char buffers to be pointers to struct object_id. This file reads data out of the pack objects and then inserts it directly into a linked list item which is a pointer to struct object_id. Instead, let's have the linked list item hold its own struct object_id and copy the data into it. In addition, since these are not really pointers to struct object_id, stop passing them around as such, and call them what they really are: pointers to unsigned char. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Apr 26, 2021 at 01:02 UTC 0e5e2284f1267293e56e8948143f6cd04c74e2ed
1 file changed +14 -14
builtin/pack-redundant.c
+14 -14
@@ -20,7 +20,7 @@ static int load_all_packs, verbose, alt_odb;
20
21 struct llist_item {
22 struct llist_item *next;
23 - const struct object_id *oid;
23 + struct object_id oid;
24 };
25 static struct llist {
26 struct llist_item *front;
@@ -95,10 +95,10 @@ static struct llist * llist_copy(struct llist *list)
95
96 static inline struct llist_item *llist_insert(struct llist *list,
97 struct llist_item *after,
98 - const struct object_id *oid)
98 + const unsigned char *oid)
99 {
100 struct llist_item *new_item = llist_item_get();
101 - new_item->oid = oid;
101 + oidread(&new_item->oid, oid);
102 new_item->next = NULL;
103
104 if (after != NULL) {
@@ -118,7 +118,7 @@ static inline struct llist_item *llist_insert(struct llist *list,
118 }
119
120 static inline struct llist_item *llist_insert_back(struct llist *list,
121 - const struct object_id *oid)
121 + const unsigned char *oid)
122 {
123 return llist_insert(list, list->back, oid);
124 }
@@ -130,9 +130,9 @@ static inline struct llist_item *llist_insert_sorted_unique(struct llist *list,
130
131 l = (hint == NULL) ? list->front : hint;
132 while (l) {
133 - int cmp = oidcmp(l->oid, oid);
133 + int cmp = oidcmp(&l->oid, oid);
134 if (cmp > 0) { /* we insert before this entry */
135 - return llist_insert(list, prev, oid);
135 + return llist_insert(list, prev, oid->hash);
136 }
137 if (!cmp) { /* already exists */
138 return l;
@@ -141,11 +141,11 @@ static inline struct llist_item *llist_insert_sorted_unique(struct llist *list,
141 l = l->next;
142 }
143 /* insert at the end */
144 - return llist_insert_back(list, oid);
144 + return llist_insert_back(list, oid->hash);
145 }
146
147 /* returns a pointer to an item in front of sha1 */
148 -static inline struct llist_item * llist_sorted_remove(struct llist *list, const struct object_id *oid, struct llist_item *hint)
148 +static inline struct llist_item * llist_sorted_remove(struct llist *list, const unsigned char *oid, struct llist_item *hint)
149 {
150 struct llist_item *prev, *l;
151
@@ -153,7 +153,7 @@ redo_from_start:
153 l = (hint == NULL) ? list->front : hint;
154 prev = NULL;
155 while (l) {
156 - const int cmp = oidcmp(l->oid, oid);
156 + const int cmp = hashcmp(l->oid.hash, oid);
157 if (cmp > 0) /* not in list, since sorted */
158 return prev;
159 if (!cmp) { /* found */
@@ -188,7 +188,7 @@ static void llist_sorted_difference_inplace(struct llist *A,
188 b = B->front;
189
190 while (b) {
191 - hint = llist_sorted_remove(A, b->oid, hint);
191 + hint = llist_sorted_remove(A, b->oid.hash, hint);
192 b = b->next;
193 }
194 }
@@ -260,10 +260,10 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
260 /* cmp ~ p1 - p2 */
261 if (cmp == 0) {
262 p1_hint = llist_sorted_remove(p1->unique_objects,
263 - (const struct object_id *)(p1_base + p1_off),
263 + p1_base + p1_off,
264 p1_hint);
265 p2_hint = llist_sorted_remove(p2->unique_objects,
266 - (const struct object_id *)(p1_base + p1_off),
266 + p1_base + p1_off,
267 p2_hint);
268 p1_off += p1_step;
269 p2_off += p2_step;
@@ -455,7 +455,7 @@ static void load_all_objects(void)
455 l = pl->remaining_objects->front;
456 while (l) {
457 hint = llist_insert_sorted_unique(all_objects,
458 - l->oid, hint);
458 + &l->oid, hint);
459 l = l->next;
460 }
461 pl = pl->next;
@@ -521,7 +521,7 @@ static struct pack_list * add_pack(struct packed_git *p)
521 base += 256 * 4 + ((p->index_version < 2) ? 4 : 8);
522 step = the_hash_algo->rawsz + ((p->index_version < 2) ? 4 : 0);
523 while (off < p->num_objects * step) {
524 - llist_insert_back(l.remaining_objects, (const struct object_id *)(base + off));
524 + llist_insert_back(l.remaining_objects, base + off);
525 off += step;
526 }
527 l.all_objects_size = l.remaining_objects->size;