Skip to content

Commit 9d36dbd

Browse files
pks-tgitster
authored andcommitted
refs/reftable: stop using the_repository
Convert the reftable ref backend to stop using `the_repository` in favor of the repo that gets passed in via `struct ref_store`. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 79e54c6 commit 9d36dbd

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

refs/reftable-backend.c

Lines changed: 26 additions & 25 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 "../abspath.h"
53
#include "../chdir-notify.h"
@@ -201,7 +199,8 @@ static void fill_reftable_log_record(struct reftable_log_record *log, const stru
201199
log->value.update.tz_offset = sign * atoi(tz_begin);
202200
}
203201

204-
static int read_ref_without_reload(struct reftable_stack *stack,
202+
static int read_ref_without_reload(struct reftable_ref_store *refs,
203+
struct reftable_stack *stack,
205204
const char *refname,
206205
struct object_id *oid,
207206
struct strbuf *referent,
@@ -220,7 +219,7 @@ static int read_ref_without_reload(struct reftable_stack *stack,
220219
*type |= REF_ISSYMREF;
221220
} else if (reftable_ref_record_val1(&ref)) {
222221
oidread(oid, reftable_ref_record_val1(&ref),
223-
the_repository->hash_algo);
222+
refs->base.repo->hash_algo);
224223
} else {
225224
/* We got a tombstone, which should not happen. */
226225
BUG("unhandled reference value type %d", ref.value_type);
@@ -487,16 +486,16 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator)
487486
switch (iter->ref.value_type) {
488487
case REFTABLE_REF_VAL1:
489488
oidread(&iter->oid, iter->ref.value.val1,
490-
the_repository->hash_algo);
489+
refs->base.repo->hash_algo);
491490
break;
492491
case REFTABLE_REF_VAL2:
493492
oidread(&iter->oid, iter->ref.value.val2.value,
494-
the_repository->hash_algo);
493+
refs->base.repo->hash_algo);
495494
break;
496495
case REFTABLE_REF_SYMREF:
497496
if (!refs_resolve_ref_unsafe(&iter->refs->base, iter->ref.refname,
498497
RESOLVE_REF_READING, &iter->oid, &flags))
499-
oidclr(&iter->oid, the_repository->hash_algo);
498+
oidclr(&iter->oid, refs->base.repo->hash_algo);
500499
break;
501500
default:
502501
BUG("unhandled reference value type %d", iter->ref.value_type);
@@ -508,7 +507,7 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator)
508507
if (check_refname_format(iter->ref.refname, REFNAME_ALLOW_ONELEVEL)) {
509508
if (!refname_is_safe(iter->ref.refname))
510509
die(_("refname is dangerous: %s"), iter->ref.refname);
511-
oidclr(&iter->oid, the_repository->hash_algo);
510+
oidclr(&iter->oid, refs->base.repo->hash_algo);
512511
flags |= REF_BAD_NAME | REF_ISBROKEN;
513512
}
514513

@@ -551,7 +550,7 @@ static int reftable_ref_iterator_peel(struct ref_iterator *ref_iterator,
551550

552551
if (iter->ref.value_type == REFTABLE_REF_VAL2) {
553552
oidread(peeled, iter->ref.value.val2.target_value,
554-
the_repository->hash_algo);
553+
iter->refs->base.repo->hash_algo);
555554
return 0;
556555
}
557556

@@ -659,7 +658,7 @@ static int reftable_be_read_raw_ref(struct ref_store *ref_store,
659658
if (ret)
660659
return ret;
661660

662-
ret = read_ref_without_reload(stack, refname, oid, referent, type);
661+
ret = read_ref_without_reload(refs, stack, refname, oid, referent, type);
663662
if (ret < 0)
664663
return ret;
665664
if (ret > 0) {
@@ -868,8 +867,8 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
868867
goto done;
869868
}
870869

871-
ret = read_ref_without_reload(stack_for(refs, "HEAD", NULL), "HEAD", &head_oid,
872-
&head_referent, &head_type);
870+
ret = read_ref_without_reload(refs, stack_for(refs, "HEAD", NULL), "HEAD",
871+
&head_oid, &head_referent, &head_type);
873872
if (ret < 0)
874873
goto done;
875874
ret = 0;
@@ -936,7 +935,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
936935
string_list_insert(&affected_refnames, new_update->refname);
937936
}
938937

939-
ret = read_ref_without_reload(stack, rewritten_ref,
938+
ret = read_ref_without_reload(refs, stack, rewritten_ref,
940939
&current_oid, &referent, &u->type);
941940
if (ret < 0)
942941
goto done;
@@ -1500,7 +1499,8 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data)
15001499
memcpy(logs[logs_nr].value.update.old_hash, old_ref.value.val1, GIT_MAX_RAWSZ);
15011500
logs_nr++;
15021501

1503-
ret = read_ref_without_reload(arg->stack, "HEAD", &head_oid, &head_referent, &head_type);
1502+
ret = read_ref_without_reload(arg->refs, arg->stack, "HEAD", &head_oid,
1503+
&head_referent, &head_type);
15041504
if (ret < 0)
15051505
goto done;
15061506
append_head_reflog = (head_type & REF_ISSYMREF) && !strcmp(head_referent.buf, arg->oldname);
@@ -1790,15 +1790,16 @@ static struct ref_iterator *reftable_be_reflog_iterator_begin(struct ref_store *
17901790
ref_iterator_select, NULL);
17911791
}
17921792

1793-
static int yield_log_record(struct reftable_log_record *log,
1793+
static int yield_log_record(struct reftable_ref_store *refs,
1794+
struct reftable_log_record *log,
17941795
each_reflog_ent_fn fn,
17951796
void *cb_data)
17961797
{
17971798
struct object_id old_oid, new_oid;
17981799
const char *full_committer;
17991800

1800-
oidread(&old_oid, log->value.update.old_hash, the_repository->hash_algo);
1801-
oidread(&new_oid, log->value.update.new_hash, the_repository->hash_algo);
1801+
oidread(&old_oid, log->value.update.old_hash, refs->base.repo->hash_algo);
1802+
oidread(&new_oid, log->value.update.new_hash, refs->base.repo->hash_algo);
18021803

18031804
/*
18041805
* When both the old object ID and the new object ID are null
@@ -1841,7 +1842,7 @@ static int reftable_be_for_each_reflog_ent_reverse(struct ref_store *ref_store,
18411842
break;
18421843
}
18431844

1844-
ret = yield_log_record(&log, fn, cb_data);
1845+
ret = yield_log_record(refs, &log, fn, cb_data);
18451846
if (ret)
18461847
break;
18471848
}
@@ -1886,7 +1887,7 @@ static int reftable_be_for_each_reflog_ent(struct ref_store *ref_store,
18861887
}
18871888

18881889
for (i = logs_nr; i--;) {
1889-
ret = yield_log_record(&logs[i], fn, cb_data);
1890+
ret = yield_log_record(refs, &logs[i], fn, cb_data);
18901891
if (ret)
18911892
goto done;
18921893
}
@@ -2200,7 +2201,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
22002201
goto done;
22012202
if (reftable_ref_record_val1(&ref_record))
22022203
oidread(&oid, reftable_ref_record_val1(&ref_record),
2203-
the_repository->hash_algo);
2204+
ref_store->repo->hash_algo);
22042205
prepare_fn(refname, &oid, policy_cb_data);
22052206

22062207
while (1) {
@@ -2216,9 +2217,9 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
22162217
}
22172218

22182219
oidread(&old_oid, log.value.update.old_hash,
2219-
the_repository->hash_algo);
2220+
ref_store->repo->hash_algo);
22202221
oidread(&new_oid, log.value.update.new_hash,
2221-
the_repository->hash_algo);
2222+
ref_store->repo->hash_algo);
22222223

22232224
/*
22242225
* Skip over the reflog existence marker. We will add it back
@@ -2250,9 +2251,9 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
22502251

22512252
*dest = logs[i];
22522253
oidread(&old_oid, logs[i].value.update.old_hash,
2253-
the_repository->hash_algo);
2254+
ref_store->repo->hash_algo);
22542255
oidread(&new_oid, logs[i].value.update.new_hash,
2255-
the_repository->hash_algo);
2256+
ref_store->repo->hash_algo);
22562257

22572258
if (should_prune_fn(&old_oid, &new_oid, logs[i].value.update.email,
22582259
(timestamp_t)logs[i].value.update.time,
@@ -2269,7 +2270,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
22692270

22702271
if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash &&
22712272
reftable_ref_record_val1(&ref_record))
2272-
oidread(&arg.update_oid, last_hash, the_repository->hash_algo);
2273+
oidread(&arg.update_oid, last_hash, ref_store->repo->hash_algo);
22732274

22742275
arg.refs = refs;
22752276
arg.records = rewritten;

0 commit comments

Comments
 (0)