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>
This commit is contained in:
brian m. carlson
2017-10-15 22:07:11 +00:00
committed by Junio C Hamano
parent ac2ed0d7d5
commit 99afe91a6c
4 changed files with 18 additions and 17 deletions

View File

@ -261,7 +261,7 @@ static struct ref_cache *get_loose_ref_cache(struct files_ref_store *refs)
}
static int files_read_raw_ref(struct ref_store *ref_store,
const char *refname, unsigned char *sha1,
const char *refname, struct object_id *oid,
struct strbuf *referent, unsigned int *type)
{
struct files_ref_store *refs =
@ -270,6 +270,7 @@ static int files_read_raw_ref(struct ref_store *ref_store,
struct strbuf sb_path = STRBUF_INIT;
const char *path;
const char *buf;
const char *p;
struct stat st;
int fd;
int ret = -1;
@ -304,7 +305,7 @@ stat_ref:
if (errno != ENOENT)
goto out;
if (refs_read_raw_ref(refs->packed_ref_store, refname,
sha1, referent, type)) {
oid, referent, type)) {
errno = ENOENT;
goto out;
}
@ -344,7 +345,7 @@ stat_ref:
* packed ref:
*/
if (refs_read_raw_ref(refs->packed_ref_store, refname,
sha1, referent, type)) {
oid, referent, type)) {
errno = EISDIR;
goto out;
}
@ -390,8 +391,8 @@ stat_ref:
* Please note that FETCH_HEAD has additional
* data after the sha.
*/
if (get_sha1_hex(buf, sha1) ||
(buf[40] != '\0' && !isspace(buf[40]))) {
if (parse_oid_hex(buf, oid, &p) ||
(*p != '\0' && !isspace(*p))) {
*type |= REF_ISBROKEN;
errno = EINVAL;
goto out;
@ -545,7 +546,7 @@ retry:
*/
if (files_read_raw_ref(&refs->base, refname,
lock->old_oid.hash, referent, type)) {
&lock->old_oid, referent, type)) {
if (errno == ENOENT) {
if (mustexist) {
/* Garden variety missing reference. */