Skip to content

Commit 99afe91

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ac2ed0d commit 99afe91

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

refs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,10 +1382,10 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)
13821382
}
13831383

13841384
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,
13861386
struct strbuf *referent, unsigned int *type)
13871387
{
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);
13891389
}
13901390

13911391
/* This function needs to return a meaningful errno on failure */
@@ -1428,7 +1428,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
14281428
unsigned int read_flags = 0;
14291429

14301430
if (refs_read_raw_ref(refs, refname,
1431-
oid->hash, &sb_refname, &read_flags)) {
1431+
oid, &sb_refname, &read_flags)) {
14321432
*flags |= read_flags;
14331433

14341434
/* In reading mode, refs must eventually resolve */
@@ -1879,7 +1879,7 @@ int refs_verify_refname_available(struct ref_store *refs,
18791879
if (skip && string_list_has_string(skip, dirname.buf))
18801880
continue;
18811881

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)) {
18831883
strbuf_addf(err, "'%s' exists; cannot create '%s'",
18841884
dirname.buf, refname);
18851885
goto cleanup;

refs/files-backend.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static struct ref_cache *get_loose_ref_cache(struct files_ref_store *refs)
261261
}
262262

263263
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,
265265
struct strbuf *referent, unsigned int *type)
266266
{
267267
struct files_ref_store *refs =
@@ -270,6 +270,7 @@ static int files_read_raw_ref(struct ref_store *ref_store,
270270
struct strbuf sb_path = STRBUF_INIT;
271271
const char *path;
272272
const char *buf;
273+
const char *p;
273274
struct stat st;
274275
int fd;
275276
int ret = -1;
@@ -304,7 +305,7 @@ static int files_read_raw_ref(struct ref_store *ref_store,
304305
if (errno != ENOENT)
305306
goto out;
306307
if (refs_read_raw_ref(refs->packed_ref_store, refname,
307-
sha1, referent, type)) {
308+
oid, referent, type)) {
308309
errno = ENOENT;
309310
goto out;
310311
}
@@ -344,7 +345,7 @@ static int files_read_raw_ref(struct ref_store *ref_store,
344345
* packed ref:
345346
*/
346347
if (refs_read_raw_ref(refs->packed_ref_store, refname,
347-
sha1, referent, type)) {
348+
oid, referent, type)) {
348349
errno = EISDIR;
349350
goto out;
350351
}
@@ -390,8 +391,8 @@ static int files_read_raw_ref(struct ref_store *ref_store,
390391
* Please note that FETCH_HEAD has additional
391392
* data after the sha.
392393
*/
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))) {
395396
*type |= REF_ISBROKEN;
396397
errno = EINVAL;
397398
goto out;
@@ -545,7 +546,7 @@ static int lock_raw_ref(struct files_ref_store *refs,
545546
*/
546547

547548
if (files_read_raw_ref(&refs->base, refname,
548-
lock->old_oid.hash, referent, type)) {
549+
&lock->old_oid, referent, type)) {
549550
if (errno == ENOENT) {
550551
if (mustexist) {
551552
/* Garden variety missing reference. */

refs/packed-backend.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ static struct snapshot *get_snapshot(struct packed_ref_store *refs)
716716
}
717717

718718
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,
720720
struct strbuf *referent, unsigned int *type)
721721
{
722722
struct packed_ref_store *refs =
@@ -734,7 +734,7 @@ static int packed_read_raw_ref(struct ref_store *ref_store,
734734
return -1;
735735
}
736736

737-
if (get_sha1_hex(rec, sha1))
737+
if (get_oid_hex(rec, oid))
738738
die_invalid_line(refs->path, rec, snapshot->eof - rec);
739739

740740
*type = REF_ISPACKED;

refs/refs-internal.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ struct ref_update {
181181
};
182182

183183
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,
185185
struct strbuf *referent, unsigned int *type);
186186

187187
/*
@@ -619,13 +619,13 @@ typedef int reflog_expire_fn(struct ref_store *ref_store,
619619
* Read a reference from the specified reference store, non-recursively.
620620
* Set type to describe the reference, and:
621621
*
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
623623
* (leaving referent unchanged).
624624
*
625625
* - If refname is the name of a symbolic reference, write the full
626626
* name of the reference to which it refers (e.g.
627627
* "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
629629
* validating that referent is a valid reference name.
630630
*
631631
* 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,
637637
*
638638
* Return 0 on success. If the ref doesn't exist, set errno to ENOENT
639639
* 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
641641
* EINVAL, and return -1. If there is another error reading the ref,
642642
* set errno appropriately and return -1.
643643
*
@@ -654,7 +654,7 @@ typedef int reflog_expire_fn(struct ref_store *ref_store,
654654
* refname will still be valid and unchanged.
655655
*/
656656
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,
658658
struct strbuf *referent, unsigned int *type);
659659

660660
struct ref_storage_be {

0 commit comments

Comments
 (0)