Skip to content

Commit 0e5e228

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5951bf4 commit 0e5e228

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

builtin/pack-redundant.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static int load_all_packs, verbose, alt_odb;
2020

2121
struct llist_item {
2222
struct llist_item *next;
23-
const struct object_id *oid;
23+
struct object_id oid;
2424
};
2525
static struct llist {
2626
struct llist_item *front;
@@ -95,10 +95,10 @@ static struct llist * llist_copy(struct llist *list)
9595

9696
static inline struct llist_item *llist_insert(struct llist *list,
9797
struct llist_item *after,
98-
const struct object_id *oid)
98+
const unsigned char *oid)
9999
{
100100
struct llist_item *new_item = llist_item_get();
101-
new_item->oid = oid;
101+
oidread(&new_item->oid, oid);
102102
new_item->next = NULL;
103103

104104
if (after != NULL) {
@@ -118,7 +118,7 @@ static inline struct llist_item *llist_insert(struct llist *list,
118118
}
119119

120120
static inline struct llist_item *llist_insert_back(struct llist *list,
121-
const struct object_id *oid)
121+
const unsigned char *oid)
122122
{
123123
return llist_insert(list, list->back, oid);
124124
}
@@ -130,9 +130,9 @@ static inline struct llist_item *llist_insert_sorted_unique(struct llist *list,
130130

131131
l = (hint == NULL) ? list->front : hint;
132132
while (l) {
133-
int cmp = oidcmp(l->oid, oid);
133+
int cmp = oidcmp(&l->oid, oid);
134134
if (cmp > 0) { /* we insert before this entry */
135-
return llist_insert(list, prev, oid);
135+
return llist_insert(list, prev, oid->hash);
136136
}
137137
if (!cmp) { /* already exists */
138138
return l;
@@ -141,19 +141,19 @@ static inline struct llist_item *llist_insert_sorted_unique(struct llist *list,
141141
l = l->next;
142142
}
143143
/* insert at the end */
144-
return llist_insert_back(list, oid);
144+
return llist_insert_back(list, oid->hash);
145145
}
146146

147147
/* 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)
149149
{
150150
struct llist_item *prev, *l;
151151

152152
redo_from_start:
153153
l = (hint == NULL) ? list->front : hint;
154154
prev = NULL;
155155
while (l) {
156-
const int cmp = oidcmp(l->oid, oid);
156+
const int cmp = hashcmp(l->oid.hash, oid);
157157
if (cmp > 0) /* not in list, since sorted */
158158
return prev;
159159
if (!cmp) { /* found */
@@ -188,7 +188,7 @@ static void llist_sorted_difference_inplace(struct llist *A,
188188
b = B->front;
189189

190190
while (b) {
191-
hint = llist_sorted_remove(A, b->oid, hint);
191+
hint = llist_sorted_remove(A, b->oid.hash, hint);
192192
b = b->next;
193193
}
194194
}
@@ -260,10 +260,10 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
260260
/* cmp ~ p1 - p2 */
261261
if (cmp == 0) {
262262
p1_hint = llist_sorted_remove(p1->unique_objects,
263-
(const struct object_id *)(p1_base + p1_off),
263+
p1_base + p1_off,
264264
p1_hint);
265265
p2_hint = llist_sorted_remove(p2->unique_objects,
266-
(const struct object_id *)(p1_base + p1_off),
266+
p1_base + p1_off,
267267
p2_hint);
268268
p1_off += p1_step;
269269
p2_off += p2_step;
@@ -455,7 +455,7 @@ static void load_all_objects(void)
455455
l = pl->remaining_objects->front;
456456
while (l) {
457457
hint = llist_insert_sorted_unique(all_objects,
458-
l->oid, hint);
458+
&l->oid, hint);
459459
l = l->next;
460460
}
461461
pl = pl->next;
@@ -521,7 +521,7 @@ static struct pack_list * add_pack(struct packed_git *p)
521521
base += 256 * 4 + ((p->index_version < 2) ? 4 : 8);
522522
step = the_hash_algo->rawsz + ((p->index_version < 2) ? 4 : 0);
523523
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);
525525
off += step;
526526
}
527527
l.all_objects_size = l.remaining_objects->size;

0 commit comments

Comments
 (0)