builtin/index-pack: convert struct ref_delta_entry to object_id
Convert this struct to use a member of type object_id. Convert various static functions as well. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Mar 12, 2018 at 02:27 UTC
af8caf33d5ac055addff3971747898799c21557c
1 file changed
+17
-17
builtin/index-pack.c
+17
-17
@@ -58,7 +58,7 @@ struct ofs_delta_entry {
58
};
59
60
struct ref_delta_entry {
61
- unsigned char sha1[20];
61
+ struct object_id oid;
62
int obj_no;
63
};
64
@@ -671,18 +671,18 @@ static void find_ofs_delta_children(off_t offset,
671
*last_index = last;
672
}
673
674
-static int compare_ref_delta_bases(const unsigned char *sha1,
675
- const unsigned char *sha2,
674
+static int compare_ref_delta_bases(const struct object_id *oid1,
675
+ const struct object_id *oid2,
676
enum object_type type1,
677
enum object_type type2)
678
{
679
int cmp = type1 - type2;
680
if (cmp)
681
return cmp;
682
- return hashcmp(sha1, sha2);
682
+ return oidcmp(oid1, oid2);
683
}
684
685
-static int find_ref_delta(const unsigned char *sha1, enum object_type type)
685
+static int find_ref_delta(const struct object_id *oid, enum object_type type)
686
{
687
int first = 0, last = nr_ref_deltas;
688
@@ -691,7 +691,7 @@ static int find_ref_delta(const unsigned char *sha1, enum object_type type)
691
struct ref_delta_entry *delta = &ref_deltas[next];
692
int cmp;
693
694
- cmp = compare_ref_delta_bases(sha1, delta->sha1,
694
+ cmp = compare_ref_delta_bases(oid, &delta->oid,
695
type, objects[delta->obj_no].type);
696
if (!cmp)
697
return next;
@@ -704,11 +704,11 @@ static int find_ref_delta(const unsigned char *sha1, enum object_type type)
704
return -first-1;
705
}
706
707
-static void find_ref_delta_children(const unsigned char *sha1,
707
+static void find_ref_delta_children(const struct object_id *oid,
708
int *first_index, int *last_index,
709
enum object_type type)
710
{
711
- int first = find_ref_delta(sha1, type);
711
+ int first = find_ref_delta(oid, type);
712
int last = first;
713
int end = nr_ref_deltas - 1;
714
@@ -717,9 +717,9 @@ static void find_ref_delta_children(const unsigned char *sha1,
717
*last_index = -1;
718
return;
719
}
720
- while (first > 0 && !hashcmp(ref_deltas[first - 1].sha1, sha1))
720
+ while (first > 0 && !oidcmp(&ref_deltas[first - 1].oid, oid))
721
--first;
722
- while (last < end && !hashcmp(ref_deltas[last + 1].sha1, sha1))
722
+ while (last < end && !oidcmp(&ref_deltas[last + 1].oid, oid))
723
++last;
724
*first_index = first;
725
*last_index = last;
@@ -991,7 +991,7 @@ static struct base_data *find_unresolved_deltas_1(struct base_data *base,
991
struct base_data *prev_base)
992
{
993
if (base->ref_last == -1 && base->ofs_last == -1) {
994
- find_ref_delta_children(base->obj->idx.oid.hash,
994
+ find_ref_delta_children(&base->obj->idx.oid,
995
&base->ref_first, &base->ref_last,
996
OBJ_REF_DELTA);
997
@@ -1075,7 +1075,7 @@ static int compare_ref_delta_entry(const void *a, const void *b)
1075
const struct ref_delta_entry *delta_a = a;
1076
const struct ref_delta_entry *delta_b = b;
1077
1078
- return hashcmp(delta_a->sha1, delta_b->sha1);
1078
+ return oidcmp(&delta_a->oid, &delta_b->oid);
1079
}
1080
1081
static void resolve_base(struct object_entry *obj)
@@ -1141,7 +1141,7 @@ static void parse_pack_objects(unsigned char *hash)
1141
ofs_delta++;
1142
} else if (obj->type == OBJ_REF_DELTA) {
1143
ALLOC_GROW(ref_deltas, nr_ref_deltas + 1, ref_deltas_alloc);
1144
- hashcpy(ref_deltas[nr_ref_deltas].sha1, ref_delta_oid.hash);
1144
+ oidcpy(&ref_deltas[nr_ref_deltas].oid, &ref_delta_oid);
1145
ref_deltas[nr_ref_deltas].obj_no = i;
1146
nr_ref_deltas++;
1147
} else if (!data) {
@@ -1373,14 +1373,14 @@ static void fix_unresolved_deltas(struct hashfile *f)
1373
1374
if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
1375
continue;
1376
- base_obj->data = read_sha1_file(d->sha1, &type, &base_obj->size);
1376
+ base_obj->data = read_sha1_file(d->oid.hash, &type, &base_obj->size);
1377
if (!base_obj->data)
1378
continue;
1379
1380
- if (check_sha1_signature(d->sha1, base_obj->data,
1380
+ if (check_sha1_signature(d->oid.hash, base_obj->data,
1381
base_obj->size, type_name(type)))
1382
- die(_("local object %s is corrupt"), sha1_to_hex(d->sha1));
1383
- base_obj->obj = append_obj_to_pack(f, d->sha1,
1382
+ die(_("local object %s is corrupt"), oid_to_hex(&d->oid));
1383
+ base_obj->obj = append_obj_to_pack(f, d->oid.hash,
1384
base_obj->data, base_obj->size, type);
1385
find_unresolved_deltas(base_obj);
1386
display_progress(progress, nr_resolved_deltas);