Skip to content

Commit 92a29c2

Browse files
committed
Merge branch 'ps/refs-wo-the-repository' into ps/config-wo-the-repository
* ps/refs-wo-the-repository: refs/reftable: stop using `the_repository` refs/packed: stop using `the_repository` refs/files: stop using `the_repository` refs/files: stop using `the_repository` in `parse_loose_ref_contents()` refs: stop using `the_repository`
2 parents 406f326 + 9d36dbd commit 92a29c2

File tree

5 files changed

+56
-57
lines changed

5 files changed

+56
-57
lines changed

refs.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
* The backend-independent part of the reference module.
33
*/
44

5-
#define USE_THE_REPOSITORY_VARIABLE
6-
75
#include "git-compat-util.h"
86
#include "advice.h"
97
#include "config.h"
@@ -1754,8 +1752,8 @@ static int refs_read_special_head(struct ref_store *ref_store,
17541752
goto done;
17551753
}
17561754

1757-
result = parse_loose_ref_contents(content.buf, oid, referent, type,
1758-
failure_errno);
1755+
result = parse_loose_ref_contents(ref_store->repo->hash_algo, content.buf,
1756+
oid, referent, type, failure_errno);
17591757

17601758
done:
17611759
strbuf_release(&full_path);
@@ -1838,7 +1836,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
18381836
failure_errno != ENOTDIR)
18391837
return NULL;
18401838

1841-
oidclr(oid, the_repository->hash_algo);
1839+
oidclr(oid, refs->repo->hash_algo);
18421840
if (*flags & REF_BAD_NAME)
18431841
*flags |= REF_ISBROKEN;
18441842
return refname;
@@ -1848,15 +1846,15 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
18481846

18491847
if (!(read_flags & REF_ISSYMREF)) {
18501848
if (*flags & REF_BAD_NAME) {
1851-
oidclr(oid, the_repository->hash_algo);
1849+
oidclr(oid, refs->repo->hash_algo);
18521850
*flags |= REF_ISBROKEN;
18531851
}
18541852
return refname;
18551853
}
18561854

18571855
refname = sb_refname.buf;
18581856
if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
1859-
oidclr(oid, the_repository->hash_algo);
1857+
oidclr(oid, refs->repo->hash_algo);
18601858
return refname;
18611859
}
18621860
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
@@ -2011,7 +2009,7 @@ struct ref_store *repo_get_submodule_ref_store(struct repository *repo,
20112009
free(subrepo);
20122010
goto done;
20132011
}
2014-
refs = ref_store_init(subrepo, the_repository->ref_storage_format,
2012+
refs = ref_store_init(subrepo, repo->ref_storage_format,
20152013
submodule_sb.buf,
20162014
REF_STORE_READ | REF_STORE_ODB);
20172015
register_ref_store_map(&repo->submodule_ref_stores, "submodule",
@@ -2045,7 +2043,7 @@ struct ref_store *get_worktree_ref_store(const struct worktree *wt)
20452043
common_path.buf, REF_STORE_ALL_CAPS);
20462044
strbuf_release(&common_path);
20472045
} else {
2048-
refs = ref_store_init(wt->repo, the_repository->ref_storage_format,
2046+
refs = ref_store_init(wt->repo, wt->repo->ref_storage_format,
20492047
wt->repo->commondir, REF_STORE_ALL_CAPS);
20502048
}
20512049

refs/files-backend.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
2-
31
#include "../git-compat-util.h"
42
#include "../copy.h"
53
#include "../environment.h"
@@ -248,7 +246,7 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,
248246

249247
if (!refs_resolve_ref_unsafe(&refs->base, refname, RESOLVE_REF_READING,
250248
&oid, &flag)) {
251-
oidclr(&oid, the_repository->hash_algo);
249+
oidclr(&oid, refs->base.repo->hash_algo);
252250
flag |= REF_ISBROKEN;
253251
} else if (is_null_oid(&oid)) {
254252
/*
@@ -265,7 +263,7 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,
265263
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
266264
if (!refname_is_safe(refname))
267265
die("loose refname is dangerous: %s", refname);
268-
oidclr(&oid, the_repository->hash_algo);
266+
oidclr(&oid, refs->base.repo->hash_algo);
269267
flag |= REF_BAD_NAME | REF_ISBROKEN;
270268
}
271269
add_entry_to_dir(dir, create_ref_entry(refname, &oid, flag));
@@ -552,7 +550,8 @@ static int read_ref_internal(struct ref_store *ref_store, const char *refname,
552550
strbuf_rtrim(&sb_contents);
553551
buf = sb_contents.buf;
554552

555-
ret = parse_loose_ref_contents(buf, oid, referent, type, &myerr);
553+
ret = parse_loose_ref_contents(ref_store->repo->hash_algo, buf,
554+
oid, referent, type, &myerr);
556555

557556
out:
558557
if (ret && !myerr)
@@ -586,7 +585,8 @@ static int files_read_symbolic_ref(struct ref_store *ref_store, const char *refn
586585
return !(type & REF_ISSYMREF);
587586
}
588587

589-
int parse_loose_ref_contents(const char *buf, struct object_id *oid,
588+
int parse_loose_ref_contents(const struct git_hash_algo *algop,
589+
const char *buf, struct object_id *oid,
590590
struct strbuf *referent, unsigned int *type,
591591
int *failure_errno)
592592
{
@@ -604,7 +604,7 @@ int parse_loose_ref_contents(const char *buf, struct object_id *oid,
604604
/*
605605
* FETCH_HEAD has additional data after the sha.
606606
*/
607-
if (parse_oid_hex(buf, oid, &p) ||
607+
if (parse_oid_hex_algop(buf, oid, &p, algop) ||
608608
(*p != '\0' && !isspace(*p))) {
609609
*type |= REF_ISBROKEN;
610610
*failure_errno = EINVAL;
@@ -1152,7 +1152,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
11521152

11531153
if (!refs_resolve_ref_unsafe(&refs->base, lock->ref_name, 0,
11541154
&lock->old_oid, NULL))
1155-
oidclr(&lock->old_oid, the_repository->hash_algo);
1155+
oidclr(&lock->old_oid, refs->base.repo->hash_algo);
11561156
goto out;
11571157

11581158
error_return:
@@ -1998,7 +1998,8 @@ static int files_delete_reflog(struct ref_store *ref_store,
19981998
return ret;
19991999
}
20002000

2001-
static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *cb_data)
2001+
static int show_one_reflog_ent(struct files_ref_store *refs, struct strbuf *sb,
2002+
each_reflog_ent_fn fn, void *cb_data)
20022003
{
20032004
struct object_id ooid, noid;
20042005
char *email_end, *message;
@@ -2008,8 +2009,8 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c
20082009

20092010
/* old SP new SP name <email> SP time TAB msg LF */
20102011
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++ != ' ' ||
2012+
parse_oid_hex_algop(p, &ooid, &p, refs->base.repo->hash_algo) || *p++ != ' ' ||
2013+
parse_oid_hex_algop(p, &noid, &p, refs->base.repo->hash_algo) || *p++ != ' ' ||
20132014
!(email_end = strchr(p, '>')) ||
20142015
email_end[1] != ' ' ||
20152016
!(timestamp = parse_timestamp(email_end + 2, &message, 10)) ||
@@ -2108,7 +2109,7 @@ static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store,
21082109
strbuf_splice(&sb, 0, 0, bp + 1, endp - (bp + 1));
21092110
scanp = bp;
21102111
endp = bp + 1;
2111-
ret = show_one_reflog_ent(&sb, fn, cb_data);
2112+
ret = show_one_reflog_ent(refs, &sb, fn, cb_data);
21122113
strbuf_reset(&sb);
21132114
if (ret)
21142115
break;
@@ -2120,7 +2121,7 @@ static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store,
21202121
* Process it, and we can end the loop.
21212122
*/
21222123
strbuf_splice(&sb, 0, 0, buf, endp - buf);
2123-
ret = show_one_reflog_ent(&sb, fn, cb_data);
2124+
ret = show_one_reflog_ent(refs, &sb, fn, cb_data);
21242125
strbuf_reset(&sb);
21252126
break;
21262127
}
@@ -2170,7 +2171,7 @@ static int files_for_each_reflog_ent(struct ref_store *ref_store,
21702171
return -1;
21712172

21722173
while (!ret && !strbuf_getwholeline(&sb, logfp, '\n'))
2173-
ret = show_one_reflog_ent(&sb, fn, cb_data);
2174+
ret = show_one_reflog_ent(refs, &sb, fn, cb_data);
21742175
fclose(logfp);
21752176
strbuf_release(&sb);
21762177
return ret;

refs/packed-backend.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
2-
31
#include "../git-compat-util.h"
42
#include "../config.h"
53
#include "../dir.h"
@@ -794,7 +792,7 @@ static int packed_read_raw_ref(struct ref_store *ref_store, const char *refname,
794792
return -1;
795793
}
796794

797-
if (get_oid_hex(rec, oid))
795+
if (get_oid_hex_algop(rec, oid, ref_store->repo->hash_algo))
798796
die_invalid_line(refs->path, rec, snapshot->eof - rec);
799797

800798
*type = REF_ISPACKED;
@@ -879,7 +877,7 @@ static int next_record(struct packed_ref_iterator *iter)
879877
p = iter->pos;
880878

881879
if (iter->eof - p < snapshot_hexsz(iter->snapshot) + 2 ||
882-
parse_oid_hex(p, &iter->oid, &p) ||
880+
parse_oid_hex_algop(p, &iter->oid, &p, iter->repo->hash_algo) ||
883881
!isspace(*p++))
884882
die_invalid_line(iter->snapshot->refs->path,
885883
iter->pos, iter->eof - iter->pos);
@@ -896,7 +894,7 @@ static int next_record(struct packed_ref_iterator *iter)
896894
if (!refname_is_safe(iter->base.refname))
897895
die("packed refname is dangerous: %s",
898896
iter->base.refname);
899-
oidclr(&iter->oid, the_repository->hash_algo);
897+
oidclr(&iter->oid, iter->repo->hash_algo);
900898
iter->base.flags |= REF_BAD_NAME | REF_ISBROKEN;
901899
}
902900
if (iter->snapshot->peeled == PEELED_FULLY ||
@@ -909,7 +907,7 @@ static int next_record(struct packed_ref_iterator *iter)
909907
if (iter->pos < iter->eof && *iter->pos == '^') {
910908
p = iter->pos + 1;
911909
if (iter->eof - p < snapshot_hexsz(iter->snapshot) + 1 ||
912-
parse_oid_hex(p, &iter->peeled, &p) ||
910+
parse_oid_hex_algop(p, &iter->peeled, &p, iter->repo->hash_algo) ||
913911
*p++ != '\n')
914912
die_invalid_line(iter->snapshot->refs->path,
915913
iter->pos, iter->eof - iter->pos);
@@ -921,13 +919,13 @@ static int next_record(struct packed_ref_iterator *iter)
921919
* we suppress it if the reference is broken:
922920
*/
923921
if ((iter->base.flags & REF_ISBROKEN)) {
924-
oidclr(&iter->peeled, the_repository->hash_algo);
922+
oidclr(&iter->peeled, iter->repo->hash_algo);
925923
iter->base.flags &= ~REF_KNOWS_PEELED;
926924
} else {
927925
iter->base.flags |= REF_KNOWS_PEELED;
928926
}
929927
} else {
930-
oidclr(&iter->peeled, the_repository->hash_algo);
928+
oidclr(&iter->peeled, iter->repo->hash_algo);
931929
}
932930

933931
return ITER_OK;

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)