refs: convert read_raw_ref backends to struct object_id

Convert the unsigned char * parameter to struct object_id * for files_read_raw_ref and packed_read_raw_ref. Update the documentation. Switch from using get_sha1_hex and a hard-coded 40 to using parse_oid_hex. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Oct 15, 2017 at 22:07 UTC 99afe91a6c3a37b7bb32c824f19b1b51712fe6f3
4 files changed +18 -17
refs.c
+4 -4
@@ -1382,10 +1382,10 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)
1382 }
1383
1384 int refs_read_raw_ref(struct ref_store *ref_store,
1385 - const char *refname, unsigned char *sha1,
1385 + const char *refname, struct object_id *oid,
1386 struct strbuf *referent, unsigned int *type)
1387 {
1388 - return ref_store->be->read_raw_ref(ref_store, refname, sha1, referent, type);
1388 + return ref_store->be->read_raw_ref(ref_store, refname, oid, referent, type);
1389 }
1390
1391 /* This function needs to return a meaningful errno on failure */
@@ -1428,7 +1428,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
1428 unsigned int read_flags = 0;
1429
1430 if (refs_read_raw_ref(refs, refname,
1431 - oid->hash, &sb_refname, &read_flags)) {
1431 + oid, &sb_refname, &read_flags)) {
1432 *flags |= read_flags;
1433
1434 /* In reading mode, refs must eventually resolve */
@@ -1879,7 +1879,7 @@ int refs_verify_refname_available(struct ref_store *refs,
1879 if (skip && string_list_has_string(skip, dirname.buf))
1880 continue;
1881
1882 - if (!refs_read_raw_ref(refs, dirname.buf, oid.hash, &referent, &type)) {
1882 + if (!refs_read_raw_ref(refs, dirname.buf, &oid, &referent, &type)) {
1883 strbuf_addf(err, "'%s' exists; cannot create '%s'",
1884 dirname.buf, refname);
1885 goto cleanup;
refs/files-backend.c
+7 -6
@@ -261,7 +261,7 @@ static struct ref_cache *get_loose_ref_cache(struct files_ref_store *refs)
261 }
262
263 static int files_read_raw_ref(struct ref_store *ref_store,
264 - const char *refname, unsigned char *sha1,
264 + const char *refname, struct object_id *oid,
265 struct strbuf *referent, unsigned int *type)
266 {
267 struct files_ref_store *refs =
@@ -270,6 +270,7 @@ static int files_read_raw_ref(struct ref_store *ref_store,
270 struct strbuf sb_path = STRBUF_INIT;
271 const char *path;
272 const char *buf;
273 + const char *p;
274 struct stat st;
275 int fd;
276 int ret = -1;
@@ -304,7 +305,7 @@ stat_ref:
305 if (errno != ENOENT)
306 goto out;
307 if (refs_read_raw_ref(refs->packed_ref_store, refname,
307 - sha1, referent, type)) {
308 + oid, referent, type)) {
309 errno = ENOENT;
310 goto out;
311 }
@@ -344,7 +345,7 @@ stat_ref:
345 * packed ref:
346 */
347 if (refs_read_raw_ref(refs->packed_ref_store, refname,
347 - sha1, referent, type)) {
348 + oid, referent, type)) {
349 errno = EISDIR;
350 goto out;
351 }
@@ -390,8 +391,8 @@ stat_ref:
391 * Please note that FETCH_HEAD has additional
392 * data after the sha.
393 */
393 - if (get_sha1_hex(buf, sha1) ||
394 - (buf[40] != '\0' && !isspace(buf[40]))) {
394 + if (parse_oid_hex(buf, oid, &p) ||
395 + (*p != '\0' && !isspace(*p))) {
396 *type |= REF_ISBROKEN;
397 errno = EINVAL;
398 goto out;
@@ -545,7 +546,7 @@ retry:
546 */
547
548 if (files_read_raw_ref(&refs->base, refname,
548 - lock->old_oid.hash, referent, type)) {
549 + &lock->old_oid, referent, type)) {
550 if (errno == ENOENT) {
551 if (mustexist) {
552 /* Garden variety missing reference. */
refs/packed-backend.c
+2 -2
@@ -716,7 +716,7 @@ static struct snapshot *get_snapshot(struct packed_ref_store *refs)
716 }
717
718 static int packed_read_raw_ref(struct ref_store *ref_store,
719 - const char *refname, unsigned char *sha1,
719 + const char *refname, struct object_id *oid,
720 struct strbuf *referent, unsigned int *type)
721 {
722 struct packed_ref_store *refs =
@@ -734,7 +734,7 @@ static int packed_read_raw_ref(struct ref_store *ref_store,
734 return -1;
735 }
736
737 - if (get_sha1_hex(rec, sha1))
737 + if (get_oid_hex(rec, oid))
738 die_invalid_line(refs->path, rec, snapshot->eof - rec);
739
740 *type = REF_ISPACKED;
refs/refs-internal.h
+5 -5
@@ -181,7 +181,7 @@ struct ref_update {
181 };
182
183 int refs_read_raw_ref(struct ref_store *ref_store,
184 - const char *refname, unsigned char *sha1,
184 + const char *refname, struct object_id *oid,
185 struct strbuf *referent, unsigned int *type);
186
187 /*
@@ -619,13 +619,13 @@ typedef int reflog_expire_fn(struct ref_store *ref_store,
619 * Read a reference from the specified reference store, non-recursively.
620 * Set type to describe the reference, and:
621 *
622 - * - If refname is the name of a normal reference, fill in sha1
622 + * - If refname is the name of a normal reference, fill in oid
623 * (leaving referent unchanged).
624 *
625 * - If refname is the name of a symbolic reference, write the full
626 * name of the reference to which it refers (e.g.
627 * "refs/heads/master") to referent and set the REF_ISSYMREF bit in
628 - * type (leaving sha1 unchanged). The caller is responsible for
628 + * type (leaving oid unchanged). The caller is responsible for
629 * validating that referent is a valid reference name.
630 *
631 * WARNING: refname might be used as part of a filename, so it is
@@ -637,7 +637,7 @@ typedef int reflog_expire_fn(struct ref_store *ref_store,
637 *
638 * Return 0 on success. If the ref doesn't exist, set errno to ENOENT
639 * and return -1. If the ref exists but is neither a symbolic ref nor
640 - * a sha1, it is broken; set REF_ISBROKEN in type, set errno to
640 + * an object ID, it is broken; set REF_ISBROKEN in type, set errno to
641 * EINVAL, and return -1. If there is another error reading the ref,
642 * set errno appropriately and return -1.
643 *
@@ -654,7 +654,7 @@ typedef int reflog_expire_fn(struct ref_store *ref_store,
654 * refname will still be valid and unchanged.
655 */
656 typedef int read_raw_ref_fn(struct ref_store *ref_store,
657 - const char *refname, unsigned char *sha1,
657 + const char *refname, struct object_id *oid,
658 struct strbuf *referent, unsigned int *type);
659
660 struct ref_storage_be {