Skip to content

Commit 080b068

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f777f4d commit 080b068

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

refs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,8 +1752,8 @@ static int refs_read_special_head(struct ref_store *ref_store,
17521752
goto done;
17531753
}
17541754

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);
17571757

17581758
done:
17591759
strbuf_release(&full_path);

refs/files-backend.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,8 @@ static int read_ref_internal(struct ref_store *ref_store, const char *refname,
552552
strbuf_rtrim(&sb_contents);
553553
buf = sb_contents.buf;
554554

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);
556557

557558
out:
558559
if (ret && !myerr)
@@ -586,7 +587,8 @@ static int files_read_symbolic_ref(struct ref_store *ref_store, const char *refn
586587
return !(type & REF_ISSYMREF);
587588
}
588589

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,
590592
struct strbuf *referent, unsigned int *type,
591593
int *failure_errno)
592594
{
@@ -604,7 +606,7 @@ int parse_loose_ref_contents(const char *buf, struct object_id *oid,
604606
/*
605607
* FETCH_HEAD has additional data after the sha.
606608
*/
607-
if (parse_oid_hex(buf, oid, &p) ||
609+
if (parse_oid_hex_algop(buf, oid, &p, algop) ||
608610
(*p != '\0' && !isspace(*p))) {
609611
*type |= REF_ISBROKEN;
610612
*failure_errno = EINVAL;
@@ -1998,7 +2000,8 @@ static int files_delete_reflog(struct ref_store *ref_store,
19982000
return ret;
19992001
}
20002002

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)
20022005
{
20032006
struct object_id ooid, noid;
20042007
char *email_end, *message;
@@ -2008,8 +2011,8 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c
20082011

20092012
/* old SP new SP name <email> SP time TAB msg LF */
20102013
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++ != ' ' ||
20132016
!(email_end = strchr(p, '>')) ||
20142017
email_end[1] != ' ' ||
20152018
!(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,
21082111
strbuf_splice(&sb, 0, 0, bp + 1, endp - (bp + 1));
21092112
scanp = bp;
21102113
endp = bp + 1;
2111-
ret = show_one_reflog_ent(&sb, fn, cb_data);
2114+
ret = show_one_reflog_ent(refs, &sb, fn, cb_data);
21122115
strbuf_reset(&sb);
21132116
if (ret)
21142117
break;
@@ -2120,7 +2123,7 @@ static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store,
21202123
* Process it, and we can end the loop.
21212124
*/
21222125
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);
21242127
strbuf_reset(&sb);
21252128
break;
21262129
}
@@ -2170,7 +2173,7 @@ static int files_for_each_reflog_ent(struct ref_store *ref_store,
21702173
return -1;
21712174

21722175
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);
21742177
fclose(logfp);
21752178
strbuf_release(&sb);
21762179
return ret;

refs/refs-internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,8 @@ struct ref_store {
705705
* Parse contents of a loose ref file. *failure_errno maybe be set to EINVAL for
706706
* invalid contents.
707707
*/
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,
709710
struct strbuf *referent, unsigned int *type,
710711
int *failure_errno);
711712

0 commit comments

Comments
 (0)