1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-26 07:06:13 +02:00

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>
This commit is contained in:
brian m. carlson 2018-03-12 02:27:37 +00:00 committed by Junio C Hamano
parent e5ec981a4b
commit af8caf33d5

View File

@ -58,7 +58,7 @@ struct ofs_delta_entry {
};
struct ref_delta_entry {
unsigned char sha1[20];
struct object_id oid;
int obj_no;
};
@ -671,18 +671,18 @@ static void find_ofs_delta_children(off_t offset,
*last_index = last;
}
static int compare_ref_delta_bases(const unsigned char *sha1,
const unsigned char *sha2,
static int compare_ref_delta_bases(const struct object_id *oid1,
const struct object_id *oid2,
enum object_type type1,
enum object_type type2)
{
int cmp = type1 - type2;
if (cmp)
return cmp;
return hashcmp(sha1, sha2);
return oidcmp(oid1, oid2);
}
static int find_ref_delta(const unsigned char *sha1, enum object_type type)
static int find_ref_delta(const struct object_id *oid, enum object_type type)
{
int first = 0, last = nr_ref_deltas;
@ -691,7 +691,7 @@ static int find_ref_delta(const unsigned char *sha1, enum object_type type)
struct ref_delta_entry *delta = &ref_deltas[next];
int cmp;
cmp = compare_ref_delta_bases(sha1, delta->sha1,
cmp = compare_ref_delta_bases(oid, &delta->oid,
type, objects[delta->obj_no].type);
if (!cmp)
return next;
@ -704,11 +704,11 @@ static int find_ref_delta(const unsigned char *sha1, enum object_type type)
return -first-1;
}
static void find_ref_delta_children(const unsigned char *sha1,
static void find_ref_delta_children(const struct object_id *oid,
int *first_index, int *last_index,
enum object_type type)
{
int first = find_ref_delta(sha1, type);
int first = find_ref_delta(oid, type);
int last = first;
int end = nr_ref_deltas - 1;
@ -717,9 +717,9 @@ static void find_ref_delta_children(const unsigned char *sha1,
*last_index = -1;
return;
}
while (first > 0 && !hashcmp(ref_deltas[first - 1].sha1, sha1))
while (first > 0 && !oidcmp(&ref_deltas[first - 1].oid, oid))
--first;
while (last < end && !hashcmp(ref_deltas[last + 1].sha1, sha1))
while (last < end && !oidcmp(&ref_deltas[last + 1].oid, oid))
++last;
*first_index = first;
*last_index = last;
@ -991,7 +991,7 @@ static struct base_data *find_unresolved_deltas_1(struct base_data *base,
struct base_data *prev_base)
{
if (base->ref_last == -1 && base->ofs_last == -1) {
find_ref_delta_children(base->obj->idx.oid.hash,
find_ref_delta_children(&base->obj->idx.oid,
&base->ref_first, &base->ref_last,
OBJ_REF_DELTA);
@ -1075,7 +1075,7 @@ static int compare_ref_delta_entry(const void *a, const void *b)
const struct ref_delta_entry *delta_a = a;
const struct ref_delta_entry *delta_b = b;
return hashcmp(delta_a->sha1, delta_b->sha1);
return oidcmp(&delta_a->oid, &delta_b->oid);
}
static void resolve_base(struct object_entry *obj)
@ -1141,7 +1141,7 @@ static void parse_pack_objects(unsigned char *hash)
ofs_delta++;
} else if (obj->type == OBJ_REF_DELTA) {
ALLOC_GROW(ref_deltas, nr_ref_deltas + 1, ref_deltas_alloc);
hashcpy(ref_deltas[nr_ref_deltas].sha1, ref_delta_oid.hash);
oidcpy(&ref_deltas[nr_ref_deltas].oid, &ref_delta_oid);
ref_deltas[nr_ref_deltas].obj_no = i;
nr_ref_deltas++;
} else if (!data) {
@ -1373,14 +1373,14 @@ static void fix_unresolved_deltas(struct hashfile *f)
if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
continue;
base_obj->data = read_sha1_file(d->sha1, &type, &base_obj->size);
base_obj->data = read_sha1_file(d->oid.hash, &type, &base_obj->size);
if (!base_obj->data)
continue;
if (check_sha1_signature(d->sha1, base_obj->data,
if (check_sha1_signature(d->oid.hash, base_obj->data,
base_obj->size, type_name(type)))
die(_("local object %s is corrupt"), sha1_to_hex(d->sha1));
base_obj->obj = append_obj_to_pack(f, d->sha1,
die(_("local object %s is corrupt"), oid_to_hex(&d->oid));
base_obj->obj = append_obj_to_pack(f, d->oid.hash,
base_obj->data, base_obj->size, type);
find_unresolved_deltas(base_obj);
display_progress(progress, nr_resolved_deltas);