Skip to content

Commit e6a492b

Browse files
bk2204gitster
authored andcommitted
pack: convert struct pack_idx_entry to struct object_id
Convert struct pack_idx_entry to use struct object_id by changing the definition and applying the following semantic patch, plus the standard object_id transforms: @@ struct pack_idx_entry E1; @@ - E1.sha1 + E1.oid.hash @@ struct pack_idx_entry *E1; @@ - E1->sha1 + E1->oid.hash Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bc83266 commit e6a492b

8 files changed

+89
-69
lines changed

builtin/index-pack.c

+19-14
Original file line numberDiff line numberDiff line change
@@ -747,13 +747,13 @@ static int compare_objects(const unsigned char *buf, unsigned long size,
747747
ssize_t len = read_istream(data->st, data->buf, size);
748748
if (len == 0)
749749
die(_("SHA1 COLLISION FOUND WITH %s !"),
750-
sha1_to_hex(data->entry->idx.sha1));
750+
oid_to_hex(&data->entry->idx.oid));
751751
if (len < 0)
752752
die(_("unable to read %s"),
753-
sha1_to_hex(data->entry->idx.sha1));
753+
oid_to_hex(&data->entry->idx.oid));
754754
if (memcmp(buf, data->buf, len))
755755
die(_("SHA1 COLLISION FOUND WITH %s !"),
756-
sha1_to_hex(data->entry->idx.sha1));
756+
oid_to_hex(&data->entry->idx.oid));
757757
size -= len;
758758
buf += len;
759759
}
@@ -771,12 +771,12 @@ static int check_collison(struct object_entry *entry)
771771

772772
memset(&data, 0, sizeof(data));
773773
data.entry = entry;
774-
data.st = open_istream(entry->idx.sha1, &type, &size, NULL);
774+
data.st = open_istream(entry->idx.oid.hash, &type, &size, NULL);
775775
if (!data.st)
776776
return -1;
777777
if (size != entry->size || type != entry->type)
778778
die(_("SHA1 COLLISION FOUND WITH %s !"),
779-
sha1_to_hex(entry->idx.sha1));
779+
oid_to_hex(&entry->idx.oid));
780780
unpack_data(entry, compare_objects, &data);
781781
close_istream(data.st);
782782
free(data.buf);
@@ -957,9 +957,10 @@ static void resolve_delta(struct object_entry *delta_obj,
957957
if (!result->data)
958958
bad_object(delta_obj->idx.offset, _("failed to apply delta"));
959959
hash_sha1_file(result->data, result->size,
960-
typename(delta_obj->real_type), delta_obj->idx.sha1);
960+
typename(delta_obj->real_type),
961+
delta_obj->idx.oid.hash);
961962
sha1_object(result->data, NULL, result->size, delta_obj->real_type,
962-
delta_obj->idx.sha1);
963+
delta_obj->idx.oid.hash);
963964
counter_lock();
964965
nr_resolved_deltas++;
965966
counter_unlock();
@@ -989,7 +990,7 @@ static struct base_data *find_unresolved_deltas_1(struct base_data *base,
989990
struct base_data *prev_base)
990991
{
991992
if (base->ref_last == -1 && base->ofs_last == -1) {
992-
find_ref_delta_children(base->obj->idx.sha1,
993+
find_ref_delta_children(base->obj->idx.oid.hash,
993994
&base->ref_first, &base->ref_last,
994995
OBJ_REF_DELTA);
995996

@@ -1130,7 +1131,8 @@ static void parse_pack_objects(unsigned char *sha1)
11301131
for (i = 0; i < nr_objects; i++) {
11311132
struct object_entry *obj = &objects[i];
11321133
void *data = unpack_raw_entry(obj, &ofs_delta->offset,
1133-
ref_delta_sha1, obj->idx.sha1);
1134+
ref_delta_sha1,
1135+
obj->idx.oid.hash);
11341136
obj->real_type = obj->type;
11351137
if (obj->type == OBJ_OFS_DELTA) {
11361138
nr_ofs_deltas++;
@@ -1146,7 +1148,8 @@ static void parse_pack_objects(unsigned char *sha1)
11461148
obj->real_type = OBJ_BAD;
11471149
nr_delays++;
11481150
} else
1149-
sha1_object(data, NULL, obj->size, obj->type, obj->idx.sha1);
1151+
sha1_object(data, NULL, obj->size, obj->type,
1152+
obj->idx.oid.hash);
11501153
free(data);
11511154
display_progress(progress, i+1);
11521155
}
@@ -1172,7 +1175,8 @@ static void parse_pack_objects(unsigned char *sha1)
11721175
if (obj->real_type != OBJ_BAD)
11731176
continue;
11741177
obj->real_type = obj->type;
1175-
sha1_object(NULL, obj, obj->size, obj->type, obj->idx.sha1);
1178+
sha1_object(NULL, obj, obj->size, obj->type,
1179+
obj->idx.oid.hash);
11761180
nr_delays--;
11771181
}
11781182
if (nr_delays)
@@ -1330,7 +1334,7 @@ static struct object_entry *append_obj_to_pack(struct sha1file *f,
13301334
obj[1].idx.offset += write_compressed(f, buf, size);
13311335
obj[0].idx.crc32 = crc32_end(f);
13321336
sha1flush(f);
1333-
hashcpy(obj->idx.sha1, sha1);
1337+
hashcpy(obj->idx.oid.hash, sha1);
13341338
return obj;
13351339
}
13361340

@@ -1581,13 +1585,14 @@ static void show_pack_info(int stat_only)
15811585
if (stat_only)
15821586
continue;
15831587
printf("%s %-6s %lu %lu %"PRIuMAX,
1584-
sha1_to_hex(obj->idx.sha1),
1588+
oid_to_hex(&obj->idx.oid),
15851589
typename(obj->real_type), obj->size,
15861590
(unsigned long)(obj[1].idx.offset - obj->idx.offset),
15871591
(uintmax_t)obj->idx.offset);
15881592
if (is_delta_type(obj->type)) {
15891593
struct object_entry *bobj = &objects[obj_stat[i].base_object_no];
1590-
printf(" %u %s", obj_stat[i].delta_depth, sha1_to_hex(bobj->idx.sha1));
1594+
printf(" %u %s", obj_stat[i].delta_depth,
1595+
oid_to_hex(&bobj->idx.oid));
15911596
}
15921597
putchar('\n');
15931598
}

builtin/pack-objects.c

+37-26
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,14 @@ static void *get_delta(struct object_entry *entry)
106106
void *buf, *base_buf, *delta_buf;
107107
enum object_type type;
108108

109-
buf = read_sha1_file(entry->idx.sha1, &type, &size);
109+
buf = read_sha1_file(entry->idx.oid.hash, &type, &size);
110110
if (!buf)
111-
die("unable to read %s", sha1_to_hex(entry->idx.sha1));
112-
base_buf = read_sha1_file(entry->delta->idx.sha1, &type, &base_size);
111+
die("unable to read %s", oid_to_hex(&entry->idx.oid));
112+
base_buf = read_sha1_file(entry->delta->idx.oid.hash, &type,
113+
&base_size);
113114
if (!base_buf)
114-
die("unable to read %s", sha1_to_hex(entry->delta->idx.sha1));
115+
die("unable to read %s",
116+
oid_to_hex(&entry->delta->idx.oid));
115117
delta_buf = diff_delta(base_buf, base_size,
116118
buf, size, &delta_size, 0);
117119
if (!delta_buf || delta_size != entry->delta_size)
@@ -249,12 +251,14 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent
249251
if (!usable_delta) {
250252
if (entry->type == OBJ_BLOB &&
251253
entry->size > big_file_threshold &&
252-
(st = open_istream(entry->idx.sha1, &type, &size, NULL)) != NULL)
254+
(st = open_istream(entry->idx.oid.hash, &type, &size, NULL)) != NULL)
253255
buf = NULL;
254256
else {
255-
buf = read_sha1_file(entry->idx.sha1, &type, &size);
257+
buf = read_sha1_file(entry->idx.oid.hash, &type,
258+
&size);
256259
if (!buf)
257-
die(_("unable to read %s"), sha1_to_hex(entry->idx.sha1));
260+
die(_("unable to read %s"),
261+
oid_to_hex(&entry->idx.oid));
258262
}
259263
/*
260264
* make sure no cached delta data remains from a
@@ -322,7 +326,7 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent
322326
return 0;
323327
}
324328
sha1write(f, header, hdrlen);
325-
sha1write(f, entry->delta->idx.sha1, 20);
329+
sha1write(f, entry->delta->idx.oid.hash, 20);
326330
hdrlen += 20;
327331
} else {
328332
if (limit && hdrlen + datalen + 20 >= limit) {
@@ -334,7 +338,7 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent
334338
sha1write(f, header, hdrlen);
335339
}
336340
if (st) {
337-
datalen = write_large_blob_data(st, f, entry->idx.sha1);
341+
datalen = write_large_blob_data(st, f, entry->idx.oid.hash);
338342
close_istream(st);
339343
} else {
340344
sha1write(f, buf, datalen);
@@ -369,7 +373,8 @@ static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry,
369373
datalen = revidx[1].offset - offset;
370374
if (!pack_to_stdout && p->index_version > 1 &&
371375
check_pack_crc(p, &w_curs, offset, datalen, revidx->nr)) {
372-
error("bad packed object CRC for %s", sha1_to_hex(entry->idx.sha1));
376+
error("bad packed object CRC for %s",
377+
oid_to_hex(&entry->idx.oid));
373378
unuse_pack(&w_curs);
374379
return write_no_reuse_object(f, entry, limit, usable_delta);
375380
}
@@ -379,7 +384,8 @@ static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry,
379384

380385
if (!pack_to_stdout && p->index_version == 1 &&
381386
check_pack_inflate(p, &w_curs, offset, datalen, entry->size)) {
382-
error("corrupt packed object for %s", sha1_to_hex(entry->idx.sha1));
387+
error("corrupt packed object for %s",
388+
oid_to_hex(&entry->idx.oid));
383389
unuse_pack(&w_curs);
384390
return write_no_reuse_object(f, entry, limit, usable_delta);
385391
}
@@ -404,7 +410,7 @@ static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry,
404410
return 0;
405411
}
406412
sha1write(f, header, hdrlen);
407-
sha1write(f, entry->delta->idx.sha1, 20);
413+
sha1write(f, entry->delta->idx.oid.hash, 20);
408414
hdrlen += 20;
409415
reused_delta++;
410416
} else {
@@ -509,7 +515,7 @@ static enum write_one_status write_one(struct sha1file *f,
509515
recursing = (e->idx.offset == 1);
510516
if (recursing) {
511517
warning("recursive delta detected for object %s",
512-
sha1_to_hex(e->idx.sha1));
518+
oid_to_hex(&e->idx.oid));
513519
return WRITE_ONE_RECURSIVE;
514520
} else if (e->idx.offset || e->preferred_base) {
515521
/* offset is non zero if object is written already. */
@@ -1432,7 +1438,7 @@ static void check_object(struct object_entry *entry)
14321438
ofs += 1;
14331439
if (!ofs || MSB(ofs, 7)) {
14341440
error("delta base offset overflow in pack for %s",
1435-
sha1_to_hex(entry->idx.sha1));
1441+
oid_to_hex(&entry->idx.oid));
14361442
goto give_up;
14371443
}
14381444
c = buf[used_0++];
@@ -1441,7 +1447,7 @@ static void check_object(struct object_entry *entry)
14411447
ofs = entry->in_pack_offset - ofs;
14421448
if (ofs <= 0 || ofs >= entry->in_pack_offset) {
14431449
error("delta base offset out of bound for %s",
1444-
sha1_to_hex(entry->idx.sha1));
1450+
oid_to_hex(&entry->idx.oid));
14451451
goto give_up;
14461452
}
14471453
if (reuse_delta && !entry->preferred_base) {
@@ -1498,7 +1504,7 @@ static void check_object(struct object_entry *entry)
14981504
unuse_pack(&w_curs);
14991505
}
15001506

1501-
entry->type = sha1_object_info(entry->idx.sha1, &entry->size);
1507+
entry->type = sha1_object_info(entry->idx.oid.hash, &entry->size);
15021508
/*
15031509
* The error condition is checked in prepare_pack(). This is
15041510
* to permit a missing preferred base object to be ignored
@@ -1514,7 +1520,7 @@ static int pack_offset_sort(const void *_a, const void *_b)
15141520

15151521
/* avoid filesystem trashing with loose objects */
15161522
if (!a->in_pack && !b->in_pack)
1517-
return hashcmp(a->idx.sha1, b->idx.sha1);
1523+
return oidcmp(&a->idx.oid, &b->idx.oid);
15181524

15191525
if (a->in_pack < b->in_pack)
15201526
return -1;
@@ -1560,7 +1566,8 @@ static void drop_reused_delta(struct object_entry *entry)
15601566
* And if that fails, the error will be recorded in entry->type
15611567
* and dealt with in prepare_pack().
15621568
*/
1563-
entry->type = sha1_object_info(entry->idx.sha1, &entry->size);
1569+
entry->type = sha1_object_info(entry->idx.oid.hash,
1570+
&entry->size);
15641571
}
15651572
}
15661573

@@ -1852,26 +1859,29 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
18521859
/* Load data if not already done */
18531860
if (!trg->data) {
18541861
read_lock();
1855-
trg->data = read_sha1_file(trg_entry->idx.sha1, &type, &sz);
1862+
trg->data = read_sha1_file(trg_entry->idx.oid.hash, &type,
1863+
&sz);
18561864
read_unlock();
18571865
if (!trg->data)
18581866
die("object %s cannot be read",
1859-
sha1_to_hex(trg_entry->idx.sha1));
1867+
oid_to_hex(&trg_entry->idx.oid));
18601868
if (sz != trg_size)
18611869
die("object %s inconsistent object length (%lu vs %lu)",
1862-
sha1_to_hex(trg_entry->idx.sha1), sz, trg_size);
1870+
oid_to_hex(&trg_entry->idx.oid), sz,
1871+
trg_size);
18631872
*mem_usage += sz;
18641873
}
18651874
if (!src->data) {
18661875
read_lock();
1867-
src->data = read_sha1_file(src_entry->idx.sha1, &type, &sz);
1876+
src->data = read_sha1_file(src_entry->idx.oid.hash, &type,
1877+
&sz);
18681878
read_unlock();
18691879
if (!src->data) {
18701880
if (src_entry->preferred_base) {
18711881
static int warned = 0;
18721882
if (!warned++)
18731883
warning("object %s cannot be read",
1874-
sha1_to_hex(src_entry->idx.sha1));
1884+
oid_to_hex(&src_entry->idx.oid));
18751885
/*
18761886
* Those objects are not included in the
18771887
* resulting pack. Be resilient and ignore
@@ -1881,11 +1891,12 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
18811891
return 0;
18821892
}
18831893
die("object %s cannot be read",
1884-
sha1_to_hex(src_entry->idx.sha1));
1894+
oid_to_hex(&src_entry->idx.oid));
18851895
}
18861896
if (sz != src_size)
18871897
die("object %s inconsistent object length (%lu vs %lu)",
1888-
sha1_to_hex(src_entry->idx.sha1), sz, src_size);
1898+
oid_to_hex(&src_entry->idx.oid), sz,
1899+
src_size);
18891900
*mem_usage += sz;
18901901
}
18911902
if (!src->index) {
@@ -2406,7 +2417,7 @@ static void prepare_pack(int window, int depth)
24062417
nr_deltas++;
24072418
if (entry->type < 0)
24082419
die("unable to get type of object %s",
2409-
sha1_to_hex(entry->idx.sha1));
2420+
oid_to_hex(&entry->idx.oid));
24102421
} else {
24112422
if (entry->type < 0) {
24122423
/*

bulk-checkin.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static int already_written(struct bulk_checkin_state *state, unsigned char sha1[
6969

7070
/* Might want to keep the list sorted */
7171
for (i = 0; i < state->nr_written; i++)
72-
if (!hashcmp(state->written[i]->sha1, sha1))
72+
if (!hashcmp(state->written[i]->oid.hash, sha1))
7373
return 1;
7474

7575
/* This is a new object we need to keep */
@@ -242,7 +242,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,
242242
state->offset = checkpoint.offset;
243243
free(idx);
244244
} else {
245-
hashcpy(idx->sha1, result_sha1);
245+
hashcpy(idx->oid.hash, result_sha1);
246246
ALLOC_GROW(state->written,
247247
state->nr_written + 1,
248248
state->alloc_written);

0 commit comments

Comments
 (0)