refs: convert struct ref_entry to use struct object_id
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
May 25, 2015 at 18:38 UTC
8353847e85128e0d0bbed862889f6f36c608c73b
1 file changed
+22
-22
refs.c
+22
-22
@@ -161,7 +161,7 @@ struct ref_value {
161
* null. If REF_ISSYMREF, then this is the name of the object
162
* referred to by the last reference in the symlink chain.
163
*/
164
- unsigned char sha1[20];
164
+ struct object_id oid;
165
166
/*
167
* If REF_KNOWS_PEELED, then this field holds the peeled value
@@ -169,7 +169,7 @@ struct ref_value {
169
* be peelable. See the documentation for peel_ref() for an
170
* exact definition of "peelable".
171
*/
172
- unsigned char peeled[20];
172
+ struct object_id peeled;
173
};
174
175
struct ref_cache;
@@ -351,8 +351,8 @@ static struct ref_entry *create_ref_entry(const char *refname,
351
die("Reference has invalid format: '%s'", refname);
352
len = strlen(refname) + 1;
353
ref = xmalloc(sizeof(struct ref_entry) + len);
354
- hashcpy(ref->u.value.sha1, sha1);
355
- hashclr(ref->u.value.peeled);
354
+ hashcpy(ref->u.value.oid.hash, sha1);
355
+ oidclr(&ref->u.value.peeled);
356
memcpy(ref->name, refname, len);
357
ref->flag = flag;
358
return ref;
@@ -626,7 +626,7 @@ static int is_dup_ref(const struct ref_entry *ref1, const struct ref_entry *ref2
626
/* This is impossible by construction */
627
die("Reference directory conflict: %s", ref1->name);
628
629
- if (hashcmp(ref1->u.value.sha1, ref2->u.value.sha1))
629
+ if (oidcmp(&ref1->u.value.oid, &ref2->u.value.oid))
630
die("Duplicated ref, and SHA1s don't match: %s", ref1->name);
631
632
warning("Duplicated ref: %s", ref1->name);
@@ -674,7 +674,7 @@ static int ref_resolves_to_object(struct ref_entry *entry)
674
{
675
if (entry->flag & REF_ISBROKEN)
676
return 0;
677
- if (!has_sha1_file(entry->u.value.sha1)) {
677
+ if (!has_sha1_file(entry->u.value.oid.hash)) {
678
error("%s does not point to a valid object!", entry->name);
679
return 0;
680
}
@@ -722,7 +722,7 @@ static int do_one_ref(struct ref_entry *entry, void *cb_data)
722
/* Store the old value, in case this is a recursive call: */
723
old_current_ref = current_ref;
724
current_ref = entry;
725
- retval = data->fn(entry->name + data->trim, entry->u.value.sha1,
725
+ retval = data->fn(entry->name + data->trim, entry->u.value.oid.hash,
726
entry->flag, data->cb_data);
727
current_ref = old_current_ref;
728
return retval;
@@ -1258,7 +1258,7 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
1258
line.len == PEELED_LINE_LENGTH &&
1259
line.buf[PEELED_LINE_LENGTH - 1] == '\n' &&
1260
!get_sha1_hex(line.buf + 1, sha1)) {
1261
- hashcpy(last->u.value.peeled, sha1);
1261
+ hashcpy(last->u.value.peeled.hash, sha1);
1262
/*
1263
* Regardless of what the file header said,
1264
* we definitely know the value of *this*
@@ -1439,7 +1439,7 @@ static int resolve_gitlink_packed_ref(struct ref_cache *refs,
1439
if (ref == NULL)
1440
return -1;
1441
1442
- hashcpy(sha1, ref->u.value.sha1);
1442
+ hashcpy(sha1, ref->u.value.oid.hash);
1443
return 0;
1444
}
1445
@@ -1526,7 +1526,7 @@ static int resolve_missing_loose_ref(const char *refname,
1526
*/
1527
entry = get_packed_ref(refname);
1528
if (entry) {
1529
- hashcpy(sha1, entry->u.value.sha1);
1529
+ hashcpy(sha1, entry->u.value.oid.hash);
1530
if (flags)
1531
*flags |= REF_ISPACKED;
1532
return 0;
@@ -1836,9 +1836,9 @@ static enum peel_status peel_entry(struct ref_entry *entry, int repeel)
1836
if (entry->flag & REF_KNOWS_PEELED) {
1837
if (repeel) {
1838
entry->flag &= ~REF_KNOWS_PEELED;
1839
- hashclr(entry->u.value.peeled);
1839
+ oidclr(&entry->u.value.peeled);
1840
} else {
1841
- return is_null_sha1(entry->u.value.peeled) ?
1841
+ return is_null_oid(&entry->u.value.peeled) ?
1842
PEEL_NON_TAG : PEEL_PEELED;
1843
}
1844
}
@@ -1847,7 +1847,7 @@ static enum peel_status peel_entry(struct ref_entry *entry, int repeel)
1847
if (entry->flag & REF_ISSYMREF)
1848
return PEEL_IS_SYMREF;
1849
1850
- status = peel_object(entry->u.value.sha1, entry->u.value.peeled);
1850
+ status = peel_object(entry->u.value.oid.hash, entry->u.value.peeled.hash);
1851
if (status == PEEL_PEELED || status == PEEL_NON_TAG)
1852
entry->flag |= REF_KNOWS_PEELED;
1853
return status;
@@ -1862,7 +1862,7 @@ int peel_ref(const char *refname, unsigned char *sha1)
1862
|| !strcmp(current_ref->name, refname))) {
1863
if (peel_entry(current_ref, 0))
1864
return -1;
1865
- hashcpy(sha1, current_ref->u.value.peeled);
1865
+ hashcpy(sha1, current_ref->u.value.peeled.hash);
1866
return 0;
1867
}
1868
@@ -1882,7 +1882,7 @@ int peel_ref(const char *refname, unsigned char *sha1)
1882
if (r) {
1883
if (peel_entry(r, 0))
1884
return -1;
1885
- hashcpy(sha1, r->u.value.peeled);
1885
+ hashcpy(sha1, r->u.value.peeled.hash);
1886
return 0;
1887
}
1888
}
@@ -2496,9 +2496,9 @@ static int write_packed_entry_fn(struct ref_entry *entry, void *cb_data)
2496
if (peel_status != PEEL_PEELED && peel_status != PEEL_NON_TAG)
2497
error("internal error: %s is not a valid packed reference!",
2498
entry->name);
2499
- write_packed_entry(cb_data, entry->name, entry->u.value.sha1,
2499
+ write_packed_entry(cb_data, entry->name, entry->u.value.oid.hash,
2500
peel_status == PEEL_PEELED ?
2501
- entry->u.value.peeled : NULL);
2501
+ entry->u.value.peeled.hash : NULL);
2502
return 0;
2503
}
2504
@@ -2615,24 +2615,24 @@ static int pack_if_possible_fn(struct ref_entry *entry, void *cb_data)
2615
peel_status = peel_entry(entry, 1);
2616
if (peel_status != PEEL_PEELED && peel_status != PEEL_NON_TAG)
2617
die("internal error peeling reference %s (%s)",
2618
- entry->name, sha1_to_hex(entry->u.value.sha1));
2618
+ entry->name, oid_to_hex(&entry->u.value.oid));
2619
packed_entry = find_ref(cb->packed_refs, entry->name);
2620
if (packed_entry) {
2621
/* Overwrite existing packed entry with info from loose entry */
2622
packed_entry->flag = REF_ISPACKED | REF_KNOWS_PEELED;
2623
- hashcpy(packed_entry->u.value.sha1, entry->u.value.sha1);
2623
+ oidcpy(&packed_entry->u.value.oid, &entry->u.value.oid);
2624
} else {
2625
- packed_entry = create_ref_entry(entry->name, entry->u.value.sha1,
2625
+ packed_entry = create_ref_entry(entry->name, entry->u.value.oid.hash,
2626
REF_ISPACKED | REF_KNOWS_PEELED, 0);
2627
add_ref(cb->packed_refs, packed_entry);
2628
}
2629
- hashcpy(packed_entry->u.value.peeled, entry->u.value.peeled);
2629
+ oidcpy(&packed_entry->u.value.peeled, &entry->u.value.peeled);
2630
2631
/* Schedule the loose reference for pruning if requested. */
2632
if ((cb->flags & PACK_REFS_PRUNE)) {
2633
int namelen = strlen(entry->name) + 1;
2634
struct ref_to_prune *n = xcalloc(1, sizeof(*n) + namelen);
2635
- hashcpy(n->sha1, entry->u.value.sha1);
2635
+ hashcpy(n->sha1, entry->u.value.oid.hash);
2636
strcpy(n->name, entry->name);
2637
n->next = cb->ref_to_prune;
2638
cb->ref_to_prune = n;