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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed May 6, 2017 at 22:10 UTC e6a492b7beca9dc8b656f2be3aec23fc1a35e4de
8 files changed +89 -69
builtin/index-pack.c
+19 -14
@@ -747,13 +747,13 @@ static int compare_objects(const unsigned char *buf, unsigned long size,
747 ssize_t len = read_istream(data->st, data->buf, size);
748 if (len == 0)
749 die(_("SHA1 COLLISION FOUND WITH %s !"),
750 - sha1_to_hex(data->entry->idx.sha1));
750 + oid_to_hex(&data->entry->idx.oid));
751 if (len < 0)
752 die(_("unable to read %s"),
753 - sha1_to_hex(data->entry->idx.sha1));
753 + oid_to_hex(&data->entry->idx.oid));
754 if (memcmp(buf, data->buf, len))
755 die(_("SHA1 COLLISION FOUND WITH %s !"),
756 - sha1_to_hex(data->entry->idx.sha1));
756 + oid_to_hex(&data->entry->idx.oid));
757 size -= len;
758 buf += len;
759 }
@@ -771,12 +771,12 @@ static int check_collison(struct object_entry *entry)
771
772 memset(&data, 0, sizeof(data));
773 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);
775 if (!data.st)
776 return -1;
777 if (size != entry->size || type != entry->type)
778 die(_("SHA1 COLLISION FOUND WITH %s !"),
779 - sha1_to_hex(entry->idx.sha1));
779 + oid_to_hex(&entry->idx.oid));
780 unpack_data(entry, compare_objects, &data);
781 close_istream(data.st);
782 free(data.buf);
@@ -957,9 +957,10 @@ static void resolve_delta(struct object_entry *delta_obj,
957 if (!result->data)
958 bad_object(delta_obj->idx.offset, _("failed to apply delta"));
959 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);
962 sha1_object(result->data, NULL, result->size, delta_obj->real_type,
962 - delta_obj->idx.sha1);
963 + delta_obj->idx.oid.hash);
964 counter_lock();
965 nr_resolved_deltas++;
966 counter_unlock();
@@ -989,7 +990,7 @@ static struct base_data *find_unresolved_deltas_1(struct base_data *base,
990 struct base_data *prev_base)
991 {
992 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,
994 &base->ref_first, &base->ref_last,
995 OBJ_REF_DELTA);
996
@@ -1130,7 +1131,8 @@ static void parse_pack_objects(unsigned char *sha1)
1131 for (i = 0; i < nr_objects; i++) {
1132 struct object_entry *obj = &objects[i];
1133 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);
1136 obj->real_type = obj->type;
1137 if (obj->type == OBJ_OFS_DELTA) {
1138 nr_ofs_deltas++;
@@ -1146,7 +1148,8 @@ static void parse_pack_objects(unsigned char *sha1)
1148 obj->real_type = OBJ_BAD;
1149 nr_delays++;
1150 } 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);
1153 free(data);
1154 display_progress(progress, i+1);
1155 }
@@ -1172,7 +1175,8 @@ static void parse_pack_objects(unsigned char *sha1)
1175 if (obj->real_type != OBJ_BAD)
1176 continue;
1177 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);
1180 nr_delays--;
1181 }
1182 if (nr_delays)
@@ -1330,7 +1334,7 @@ static struct object_entry *append_obj_to_pack(struct sha1file *f,
1334 obj[1].idx.offset += write_compressed(f, buf, size);
1335 obj[0].idx.crc32 = crc32_end(f);
1336 sha1flush(f);
1333 - hashcpy(obj->idx.sha1, sha1);
1337 + hashcpy(obj->idx.oid.hash, sha1);
1338 return obj;
1339 }
1340
@@ -1581,13 +1585,14 @@ static void show_pack_info(int stat_only)
1585 if (stat_only)
1586 continue;
1587 printf("%s %-6s %lu %lu %"PRIuMAX,
1584 - sha1_to_hex(obj->idx.sha1),
1588 + oid_to_hex(&obj->idx.oid),
1589 typename(obj->real_type), obj->size,
1590 (unsigned long)(obj[1].idx.offset - obj->idx.offset),
1591 (uintmax_t)obj->idx.offset);
1592 if (is_delta_type(obj->type)) {
1593 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));
1596 }
1597 putchar('\n');
1598 }
builtin/pack-objects.c
+37 -26
@@ -106,12 +106,14 @@ static void *get_delta(struct object_entry *entry)
106 void *buf, *base_buf, *delta_buf;
107 enum object_type type;
108
109 - buf = read_sha1_file(entry->idx.sha1, &type, &size);
109 + buf = read_sha1_file(entry->idx.oid.hash, &type, &size);
110 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);
114 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));
117 delta_buf = diff_delta(base_buf, base_size,
118 buf, size, &delta_size, 0);
119 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
251 if (!usable_delta) {
252 if (entry->type == OBJ_BLOB &&
253 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)
255 buf = NULL;
256 else {
255 - buf = read_sha1_file(entry->idx.sha1, &type, &size);
257 + buf = read_sha1_file(entry->idx.oid.hash, &type,
258 + &size);
259 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));
262 }
263 /*
264 * 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
326 return 0;
327 }
328 sha1write(f, header, hdrlen);
325 - sha1write(f, entry->delta->idx.sha1, 20);
329 + sha1write(f, entry->delta->idx.oid.hash, 20);
330 hdrlen += 20;
331 } else {
332 if (limit && hdrlen + datalen + 20 >= limit) {
@@ -334,7 +338,7 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent
338 sha1write(f, header, hdrlen);
339 }
340 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);
342 close_istream(st);
343 } else {
344 sha1write(f, buf, datalen);
@@ -369,7 +373,8 @@ static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry,
373 datalen = revidx[1].offset - offset;
374 if (!pack_to_stdout && p->index_version > 1 &&
375 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));
378 unuse_pack(&w_curs);
379 return write_no_reuse_object(f, entry, limit, usable_delta);
380 }
@@ -379,7 +384,8 @@ static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry,
384
385 if (!pack_to_stdout && p->index_version == 1 &&
386 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));
389 unuse_pack(&w_curs);
390 return write_no_reuse_object(f, entry, limit, usable_delta);
391 }
@@ -404,7 +410,7 @@ static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry,
410 return 0;
411 }
412 sha1write(f, header, hdrlen);
407 - sha1write(f, entry->delta->idx.sha1, 20);
413 + sha1write(f, entry->delta->idx.oid.hash, 20);
414 hdrlen += 20;
415 reused_delta++;
416 } else {
@@ -509,7 +515,7 @@ static enum write_one_status write_one(struct sha1file *f,
515 recursing = (e->idx.offset == 1);
516 if (recursing) {
517 warning("recursive delta detected for object %s",
512 - sha1_to_hex(e->idx.sha1));
518 + oid_to_hex(&e->idx.oid));
519 return WRITE_ONE_RECURSIVE;
520 } else if (e->idx.offset || e->preferred_base) {
521 /* offset is non zero if object is written already. */
@@ -1432,7 +1438,7 @@ static void check_object(struct object_entry *entry)
1438 ofs += 1;
1439 if (!ofs || MSB(ofs, 7)) {
1440 error("delta base offset overflow in pack for %s",
1435 - sha1_to_hex(entry->idx.sha1));
1441 + oid_to_hex(&entry->idx.oid));
1442 goto give_up;
1443 }
1444 c = buf[used_0++];
@@ -1441,7 +1447,7 @@ static void check_object(struct object_entry *entry)
1447 ofs = entry->in_pack_offset - ofs;
1448 if (ofs <= 0 || ofs >= entry->in_pack_offset) {
1449 error("delta base offset out of bound for %s",
1444 - sha1_to_hex(entry->idx.sha1));
1450 + oid_to_hex(&entry->idx.oid));
1451 goto give_up;
1452 }
1453 if (reuse_delta && !entry->preferred_base) {
@@ -1498,7 +1504,7 @@ static void check_object(struct object_entry *entry)
1504 unuse_pack(&w_curs);
1505 }
1506
1501 - entry->type = sha1_object_info(entry->idx.sha1, &entry->size);
1507 + entry->type = sha1_object_info(entry->idx.oid.hash, &entry->size);
1508 /*
1509 * The error condition is checked in prepare_pack(). This is
1510 * 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)
1520
1521 /* avoid filesystem trashing with loose objects */
1522 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);
1524
1525 if (a->in_pack < b->in_pack)
1526 return -1;
@@ -1560,7 +1566,8 @@ static void drop_reused_delta(struct object_entry *entry)
1566 * And if that fails, the error will be recorded in entry->type
1567 * and dealt with in prepare_pack().
1568 */
1563 - entry->type = sha1_object_info(entry->idx.sha1, &entry->size);
1569 + entry->type = sha1_object_info(entry->idx.oid.hash,
1570 + &entry->size);
1571 }
1572 }
1573
@@ -1852,26 +1859,29 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
1859 /* Load data if not already done */
1860 if (!trg->data) {
1861 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);
1864 read_unlock();
1865 if (!trg->data)
1866 die("object %s cannot be read",
1859 - sha1_to_hex(trg_entry->idx.sha1));
1867 + oid_to_hex(&trg_entry->idx.oid));
1868 if (sz != trg_size)
1869 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);
1872 *mem_usage += sz;
1873 }
1874 if (!src->data) {
1875 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);
1878 read_unlock();
1879 if (!src->data) {
1880 if (src_entry->preferred_base) {
1881 static int warned = 0;
1882 if (!warned++)
1883 warning("object %s cannot be read",
1874 - sha1_to_hex(src_entry->idx.sha1));
1884 + oid_to_hex(&src_entry->idx.oid));
1885 /*
1886 * Those objects are not included in the
1887 * resulting pack. Be resilient and ignore
@@ -1881,11 +1891,12 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
1891 return 0;
1892 }
1893 die("object %s cannot be read",
1884 - sha1_to_hex(src_entry->idx.sha1));
1894 + oid_to_hex(&src_entry->idx.oid));
1895 }
1896 if (sz != src_size)
1897 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);
1900 *mem_usage += sz;
1901 }
1902 if (!src->index) {
@@ -2406,7 +2417,7 @@ static void prepare_pack(int window, int depth)
2417 nr_deltas++;
2418 if (entry->type < 0)
2419 die("unable to get type of object %s",
2409 - sha1_to_hex(entry->idx.sha1));
2420 + oid_to_hex(&entry->idx.oid));
2421 } else {
2422 if (entry->type < 0) {
2423 /*
bulk-checkin.c
+2 -2
@@ -69,7 +69,7 @@ static int already_written(struct bulk_checkin_state *state, unsigned char sha1[
69
70 /* Might want to keep the list sorted */
71 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))
73 return 1;
74
75 /* This is a new object we need to keep */
@@ -242,7 +242,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,
242 state->offset = checkpoint.offset;
243 free(idx);
244 } else {
245 - hashcpy(idx->sha1, result_sha1);
245 + hashcpy(idx->oid.hash, result_sha1);
246 ALLOC_GROW(state->written,
247 state->nr_written + 1,
248 state->alloc_written);
fast-import.c
+15 -15
@@ -565,7 +565,7 @@ static struct object_entry *new_object(struct object_id *oid)
565 alloc_objects(object_entry_alloc);
566
567 e = blocks->next_free++;
568 - hashcpy(e->idx.sha1, oid->hash);
568 + oidcpy(&e->idx.oid, oid);
569 return e;
570 }
571
@@ -574,7 +574,7 @@ static struct object_entry *find_object(struct object_id *oid)
574 unsigned int h = oid->hash[0] << 8 | oid->hash[1];
575 struct object_entry *e;
576 for (e = object_table[h]; e; e = e->next)
577 - if (!hashcmp(oid->hash, e->idx.sha1))
577 + if (!oidcmp(oid, &e->idx.oid))
578 return e;
579 return NULL;
580 }
@@ -585,7 +585,7 @@ static struct object_entry *insert_object(struct object_id *oid)
585 struct object_entry *e = object_table[h];
586
587 while (e) {
588 - if (!hashcmp(oid->hash, e->idx.sha1))
588 + if (!oidcmp(oid, &e->idx.oid))
589 return e;
590 e = e->next;
591 }
@@ -1849,7 +1849,7 @@ static void dump_marks_helper(FILE *f,
1849 for (k = 0; k < 1024; k++) {
1850 if (m->data.marked[k])
1851 fprintf(f, ":%" PRIuMAX " %s\n", base + k,
1852 - sha1_to_hex(m->data.marked[k]->idx.sha1));
1852 + oid_to_hex(&m->data.marked[k]->idx.oid));
1853 }
1854 }
1855 }
@@ -2389,7 +2389,7 @@ static void file_change_m(const char *p, struct branch *b)
2389
2390 if (*p == ':') {
2391 oe = find_mark(parse_mark_ref_space(&p));
2392 - hashcpy(oid.hash, oe->idx.sha1);
2392 + oidcpy(&oid, &oe->idx.oid);
2393 } else if (skip_prefix(p, "inline ", &p)) {
2394 inline_data = 1;
2395 oe = NULL; /* not used with inline_data, but makes gcc happy */
@@ -2555,7 +2555,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
2555 /* <dataref> or 'inline' */
2556 if (*p == ':') {
2557 oe = find_mark(parse_mark_ref_space(&p));
2558 - hashcpy(oid.hash, oe->idx.sha1);
2558 + oidcpy(&oid, &oe->idx.oid);
2559 } else if (skip_prefix(p, "inline ", &p)) {
2560 inline_data = 1;
2561 oe = NULL; /* not used with inline_data, but makes gcc happy */
@@ -2578,7 +2578,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
2578 struct object_entry *commit_oe = find_mark(commit_mark);
2579 if (commit_oe->type != OBJ_COMMIT)
2580 die("Mark :%" PRIuMAX " not a commit", commit_mark);
2581 - hashcpy(commit_oid.hash, commit_oe->idx.sha1);
2581 + oidcpy(&commit_oid, &commit_oe->idx.oid);
2582 } else if (!get_oid(p, &commit_oid)) {
2583 unsigned long size;
2584 char *buf = read_object_with_reference(commit_oid.hash,
@@ -2683,8 +2683,8 @@ static int parse_from(struct branch *b)
2683 struct object_entry *oe = find_mark(idnum);
2684 if (oe->type != OBJ_COMMIT)
2685 die("Mark :%" PRIuMAX " not a commit", idnum);
2686 - if (hashcmp(b->oid.hash, oe->idx.sha1)) {
2687 - hashcpy(b->oid.hash, oe->idx.sha1);
2686 + if (oidcmp(&b->oid, &oe->idx.oid)) {
2687 + oidcpy(&b->oid, &oe->idx.oid);
2688 if (oe->pack_id != MAX_PACK_ID) {
2689 unsigned long size;
2690 char *buf = gfi_unpack_entry(oe, &size);
@@ -2727,7 +2727,7 @@ static struct hash_list *parse_merge(unsigned int *count)
2727 struct object_entry *oe = find_mark(idnum);
2728 if (oe->type != OBJ_COMMIT)
2729 die("Mark :%" PRIuMAX " not a commit", idnum);
2730 - hashcpy(n->oid.hash, oe->idx.sha1);
2730 + oidcpy(&n->oid, &oe->idx.oid);
2731 } else if (!get_oid(from, &n->oid)) {
2732 unsigned long size;
2733 char *buf = read_object_with_reference(n->oid.hash,
@@ -2884,7 +2884,7 @@ static void parse_new_tag(const char *arg)
2884 from_mark = parse_mark_ref_eol(from);
2885 oe = find_mark(from_mark);
2886 type = oe->type;
2887 - hashcpy(oid.hash, oe->idx.sha1);
2887 + oidcpy(&oid, &oe->idx.oid);
2888 } else if (!get_oid(from, &oid)) {
2889 struct object_entry *oe = find_object(&oid);
2890 if (!oe) {
@@ -3014,7 +3014,7 @@ static void parse_get_mark(const char *p)
3014 if (!oe)
3015 die("Unknown mark: %s", command_buf.buf);
3016
3017 - xsnprintf(output, sizeof(output), "%s\n", sha1_to_hex(oe->idx.sha1));
3017 + xsnprintf(output, sizeof(output), "%s\n", oid_to_hex(&oe->idx.oid));
3018 cat_blob_write(output, GIT_SHA1_HEXSZ + 1);
3019 }
3020
@@ -3028,7 +3028,7 @@ static void parse_cat_blob(const char *p)
3028 oe = find_mark(parse_mark_ref_eol(p));
3029 if (!oe)
3030 die("Unknown mark: %s", command_buf.buf);
3031 - hashcpy(oid.hash, oe->idx.sha1);
3031 + oidcpy(&oid, &oe->idx.oid);
3032 } else {
3033 if (parse_oid_hex(p, &oid, &p))
3034 die("Invalid dataref: %s", command_buf.buf);
@@ -3100,7 +3100,7 @@ static struct object_entry *parse_treeish_dataref(const char **p)
3100 e = find_mark(parse_mark_ref_space(p));
3101 if (!e)
3102 die("Unknown mark: %s", command_buf.buf);
3103 - hashcpy(oid.hash, e->idx.sha1);
3103 + oidcpy(&oid, &e->idx.oid);
3104 } else { /* <sha1> */
3105 if (parse_oid_hex(*p, &oid, p))
3106 die("Invalid dataref: %s", command_buf.buf);
@@ -3154,7 +3154,7 @@ static void parse_ls(const char *p, struct branch *b)
3154 } else {
3155 struct object_entry *e = parse_treeish_dataref(&p);
3156 root = new_tree_entry();
3157 - hashcpy(root->versions[1].oid.hash, e->idx.sha1);
3157 + oidcpy(&root->versions[1].oid, &e->idx.oid);
3158 if (!is_null_oid(&root->versions[1].oid))
3159 root->versions[1].mode = S_IFDIR;
3160 load_tree(root);
pack-bitmap-write.c
+5 -3
@@ -73,7 +73,8 @@ void bitmap_writer_build_type_index(struct pack_idx_entry **index,
73 break;
74
75 default:
76 - real_type = sha1_object_info(entry->idx.sha1, NULL);
76 + real_type = sha1_object_info(entry->idx.oid.hash,
77 + NULL);
78 break;
79 }
80
@@ -96,7 +97,8 @@ void bitmap_writer_build_type_index(struct pack_idx_entry **index,
97
98 default:
99 die("Missing type information for %s (%d/%d)",
99 - sha1_to_hex(entry->idx.sha1), real_type, entry->type);
100 + oid_to_hex(&entry->idx.oid), real_type,
101 + entry->type);
102 }
103 }
104 }
@@ -459,7 +461,7 @@ static inline void dump_bitmap(struct sha1file *f, struct ewah_bitmap *bitmap)
461 static const unsigned char *sha1_access(size_t pos, void *table)
462 {
463 struct pack_idx_entry **index = table;
462 - return index[pos]->sha1;
464 + return index[pos]->oid.hash;
465 }
466
467 static void write_selected_commits_v1(struct sha1file *f,
pack-objects.c
+5 -3
@@ -14,7 +14,7 @@ static uint32_t locate_object_entry_hash(struct packing_data *pdata,
14 while (pdata->index[i] > 0) {
15 uint32_t pos = pdata->index[i] - 1;
16
17 - if (!hashcmp(sha1, pdata->objects[pos].idx.sha1)) {
17 + if (!hashcmp(sha1, pdata->objects[pos].idx.oid.hash)) {
18 *found = 1;
19 return i;
20 }
@@ -53,7 +53,9 @@ static void rehash_objects(struct packing_data *pdata)
53
54 for (i = 0; i < pdata->nr_objects; i++) {
55 int found;
56 - uint32_t ix = locate_object_entry_hash(pdata, entry->idx.sha1, &found);
56 + uint32_t ix = locate_object_entry_hash(pdata,
57 + entry->idx.oid.hash,
58 + &found);
59
60 if (found)
61 die("BUG: Duplicate object in hash");
@@ -98,7 +100,7 @@ struct object_entry *packlist_alloc(struct packing_data *pdata,
100 new_entry = pdata->objects + pdata->nr_objects++;
101
102 memset(new_entry, 0, sizeof(*new_entry));
101 - hashcpy(new_entry->idx.sha1, sha1);
103 + hashcpy(new_entry->idx.oid.hash, sha1);
104
105 if (pdata->index_size * 3 <= pdata->nr_objects * 4)
106 rehash_objects(pdata);
pack-write.c
+5 -5
@@ -13,7 +13,7 @@ static int sha1_compare(const void *_a, const void *_b)
13 {
14 struct pack_idx_entry *a = *(struct pack_idx_entry **)_a;
15 struct pack_idx_entry *b = *(struct pack_idx_entry **)_b;
16 - return hashcmp(a->sha1, b->sha1);
16 + return oidcmp(&a->oid, &b->oid);
17 }
18
19 static int cmp_uint32(const void *a_, const void *b_)
@@ -103,7 +103,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
103 struct pack_idx_entry **next = list;
104 while (next < last) {
105 struct pack_idx_entry *obj = *next;
106 - if (obj->sha1[0] != i)
106 + if (obj->oid.hash[0] != i)
107 break;
108 next++;
109 }
@@ -122,11 +122,11 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
122 uint32_t offset = htonl(obj->offset);
123 sha1write(f, &offset, 4);
124 }
125 - sha1write(f, obj->sha1, 20);
125 + sha1write(f, obj->oid.hash, 20);
126 if ((opts->flags & WRITE_IDX_STRICT) &&
127 - (i && !hashcmp(list[-2]->sha1, obj->sha1)))
127 + (i && !oidcmp(&list[-2]->oid, &obj->oid)))
128 die("The same object %s appears twice in the pack",
129 - sha1_to_hex(obj->sha1));
129 + oid_to_hex(&obj->oid));
130 }
131
132 if (index_version >= 2) {
pack.h
+1 -1
@@ -67,7 +67,7 @@ struct pack_idx_header {
67 * Common part of object structure used for write_idx_file
68 */
69 struct pack_idx_entry {
70 - unsigned char sha1[20];
70 + struct object_id oid;
71 uint32_t crc32;
72 off_t offset;
73 };