refs/files: stop using `the_repository` in `parse_loose_ref_contents()`
We implicitly rely on `the_repository` in `parse_loose_ref_contents()` by calling `parse_oid_hex()`. Convert the function to instead use `parse_oid_hex_algop()` and have callers pass in the hash algorithm to use. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Jul 30, 2024 at 07:22 UTC
080b068ffb72a41ea23d11a6a5781e587db7d860
3 files changed
+16
-12
refs.c
+2
-2
@@ -1752,8 +1752,8 @@ static int refs_read_special_head(struct ref_store *ref_store,
1752
goto done;
1753
}
1754
1755
- result = parse_loose_ref_contents(content.buf, oid, referent, type,
1756
- failure_errno);
1755
+ result = parse_loose_ref_contents(ref_store->repo->hash_algo, content.buf,
1756
+ oid, referent, type, failure_errno);
1757
1758
done:
1759
strbuf_release(&full_path);
refs/files-backend.c
+12
-9
@@ -552,7 +552,8 @@ stat_ref:
552
strbuf_rtrim(&sb_contents);
553
buf = sb_contents.buf;
554
555
- ret = parse_loose_ref_contents(buf, oid, referent, type, &myerr);
555
+ ret = parse_loose_ref_contents(ref_store->repo->hash_algo, buf,
556
+ oid, referent, type, &myerr);
557
558
out:
559
if (ret && !myerr)
@@ -586,7 +587,8 @@ static int files_read_symbolic_ref(struct ref_store *ref_store, const char *refn
587
return !(type & REF_ISSYMREF);
588
}
589
589
-int parse_loose_ref_contents(const char *buf, struct object_id *oid,
590
+int parse_loose_ref_contents(const struct git_hash_algo *algop,
591
+ const char *buf, struct object_id *oid,
592
struct strbuf *referent, unsigned int *type,
593
int *failure_errno)
594
{
@@ -604,7 +606,7 @@ int parse_loose_ref_contents(const char *buf, struct object_id *oid,
606
/*
607
* FETCH_HEAD has additional data after the sha.
608
*/
607
- if (parse_oid_hex(buf, oid, &p) ||
609
+ if (parse_oid_hex_algop(buf, oid, &p, algop) ||
610
(*p != '\0' && !isspace(*p))) {
611
*type |= REF_ISBROKEN;
612
*failure_errno = EINVAL;
@@ -1998,7 +2000,8 @@ static int files_delete_reflog(struct ref_store *ref_store,
2000
return ret;
2001
}
2002
2001
-static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *cb_data)
2003
+static int show_one_reflog_ent(struct files_ref_store *refs, struct strbuf *sb,
2004
+ each_reflog_ent_fn fn, void *cb_data)
2005
{
2006
struct object_id ooid, noid;
2007
char *email_end, *message;
@@ -2008,8 +2011,8 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c
2011
2012
/* old SP new SP name <email> SP time TAB msg LF */
2013
if (!sb->len || sb->buf[sb->len - 1] != '\n' ||
2011
- parse_oid_hex(p, &ooid, &p) || *p++ != ' ' ||
2012
- parse_oid_hex(p, &noid, &p) || *p++ != ' ' ||
2014
+ parse_oid_hex_algop(p, &ooid, &p, refs->base.repo->hash_algo) || *p++ != ' ' ||
2015
+ parse_oid_hex_algop(p, &noid, &p, refs->base.repo->hash_algo) || *p++ != ' ' ||
2016
!(email_end = strchr(p, '>')) ||
2017
email_end[1] != ' ' ||
2018
!(timestamp = parse_timestamp(email_end + 2, &message, 10)) ||
@@ -2108,7 +2111,7 @@ static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store,
2111
strbuf_splice(&sb, 0, 0, bp + 1, endp - (bp + 1));
2112
scanp = bp;
2113
endp = bp + 1;
2111
- ret = show_one_reflog_ent(&sb, fn, cb_data);
2114
+ ret = show_one_reflog_ent(refs, &sb, fn, cb_data);
2115
strbuf_reset(&sb);
2116
if (ret)
2117
break;
@@ -2120,7 +2123,7 @@ static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store,
2123
* Process it, and we can end the loop.
2124
*/
2125
strbuf_splice(&sb, 0, 0, buf, endp - buf);
2123
- ret = show_one_reflog_ent(&sb, fn, cb_data);
2126
+ ret = show_one_reflog_ent(refs, &sb, fn, cb_data);
2127
strbuf_reset(&sb);
2128
break;
2129
}
@@ -2170,7 +2173,7 @@ static int files_for_each_reflog_ent(struct ref_store *ref_store,
2173
return -1;
2174
2175
while (!ret && !strbuf_getwholeline(&sb, logfp, '\n'))
2173
- ret = show_one_reflog_ent(&sb, fn, cb_data);
2176
+ ret = show_one_reflog_ent(refs, &sb, fn, cb_data);
2177
fclose(logfp);
2178
strbuf_release(&sb);
2179
return ret;
refs/refs-internal.h
+2
-1
@@ -705,7 +705,8 @@ struct ref_store {
705
* Parse contents of a loose ref file. *failure_errno maybe be set to EINVAL for
706
* invalid contents.
707
*/
708
-int parse_loose_ref_contents(const char *buf, struct object_id *oid,
708
+int parse_loose_ref_contents(const struct git_hash_algo *algop,
709
+ const char *buf, struct object_id *oid,
710
struct strbuf *referent, unsigned int *type,
711
int *failure_errno);
712