Skip to content

Commit 5b87540

Browse files
avargitster
authored andcommitted
refs debug: add a wrapper for "read_symbolic_ref"
In cd475b3 (refs: add ability for backends to special-case reading of symbolic refs, 2022-03-01) when the "read_symbolic_ref" callback was added we'd fall back on "refs_read_raw_ref" if there wasn't any backend implementation of "read_symbolic_ref". As discussed in the preceding commit this would only happen if we were running the "debug" backend, e.g. in the "setup for ref completion" test in t9902-completion.sh with: GIT_TRACE_REFS=1 git fetch --no-tags other Let's improve the trace output, but and also eliminate the now-redundant refs_read_raw_ref() fallback case. As noted in the preceding commit the "packed" backend will never call refs_read_symbolic_ref() (nor is it ever going to). For any future backend such as reftable it's OK to ask that they either implement this (or a wrapper) themselves. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ca40893 commit 5b87540

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

refs.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,18 +1676,7 @@ int refs_read_raw_ref(struct ref_store *ref_store, const char *refname,
16761676
int refs_read_symbolic_ref(struct ref_store *ref_store, const char *refname,
16771677
struct strbuf *referent)
16781678
{
1679-
struct object_id oid;
1680-
int ret, failure_errno = 0;
1681-
unsigned int type = 0;
1682-
1683-
if (ref_store->be->read_symbolic_ref)
1684-
return ref_store->be->read_symbolic_ref(ref_store, refname, referent);
1685-
1686-
ret = refs_read_raw_ref(ref_store, refname, &oid, referent, &type, &failure_errno);
1687-
if (ret || !(type & REF_ISSYMREF))
1688-
return -1;
1689-
1690-
return 0;
1679+
return ref_store->be->read_symbolic_ref(ref_store, refname, referent);
16911680
}
16921681

16931682
const char *refs_resolve_ref_unsafe(struct ref_store *refs,

refs/debug.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,24 @@ static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,
262262
return res;
263263
}
264264

265+
static int debug_read_symbolic_ref(struct ref_store *ref_store, const char *refname,
266+
struct strbuf *referent)
267+
{
268+
struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;
269+
struct ref_store *refs = drefs->refs;
270+
int res;
271+
272+
res = refs->be->read_symbolic_ref(refs, refname, referent);
273+
if (!res)
274+
trace_printf_key(&trace_refs, "read_symbolic_ref: %s: (%s)\n",
275+
refname, referent->buf);
276+
else
277+
trace_printf_key(&trace_refs,
278+
"read_symbolic_ref: %s: %d\n", refname, res);
279+
return res;
280+
281+
}
282+
265283
static struct ref_iterator *
266284
debug_reflog_iterator_begin(struct ref_store *ref_store)
267285
{
@@ -423,6 +441,13 @@ struct ref_storage_be refs_be_debug = {
423441
.name = "debug",
424442
.init = NULL,
425443
.init_db = debug_init_db,
444+
445+
/*
446+
* None of these should be NULL. If the "files" backend (in
447+
* "struct ref_storage_be refs_be_files" in files-backend.c)
448+
* has a function we should also have a wrapper for it here.
449+
* Test the output with "GIT_TRACE_REFS=1".
450+
*/
426451
.transaction_prepare = debug_transaction_prepare,
427452
.transaction_finish = debug_transaction_finish,
428453
.transaction_abort = debug_transaction_abort,
@@ -436,7 +461,7 @@ struct ref_storage_be refs_be_debug = {
436461

437462
.iterator_begin = debug_ref_iterator_begin,
438463
.read_raw_ref = debug_read_raw_ref,
439-
.read_symbolic_ref = NULL,
464+
.read_symbolic_ref = debug_read_symbolic_ref,
440465

441466
.reflog_iterator_begin = debug_reflog_iterator_begin,
442467
.for_each_reflog_ent = debug_for_each_reflog_ent,

0 commit comments

Comments
 (0)