diff --git a/refs/debug.c b/refs/debug.c index 639db0f26e1bbb..78d1eb5a986abd 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -8,6 +8,7 @@ static struct trace_key trace_refs = TRACE_KEY_INIT(REFS); struct debug_ref_store { struct ref_store base; struct ref_store *refs; + struct ref_storage_be backend; }; extern struct ref_storage_be refs_be_debug; @@ -15,27 +16,25 @@ extern struct ref_storage_be refs_be_debug; struct ref_store *maybe_debug_wrap_ref_store(const char *gitdir, struct ref_store *store) { struct debug_ref_store *res; - struct ref_storage_be *be_copy; if (!trace_want(&trace_refs)) { return store; } res = xmalloc(sizeof(struct debug_ref_store)); - be_copy = xmalloc(sizeof(*be_copy)); - *be_copy = refs_be_debug; - /* we never deallocate backends, so safe to copy the pointer. */ - be_copy->name = store->be->name; + res->backend = refs_be_debug; + res->backend.name = store->be->name; trace_printf_key(&trace_refs, "ref_store for %s\n", gitdir); res->refs = store; base_ref_store_init((struct ref_store *)res, store->repo, gitdir, - be_copy); + &res->backend); return (struct ref_store *)res; } static void debug_release(struct ref_store *refs) { struct debug_ref_store *drefs = (struct debug_ref_store *)refs; - drefs->refs->be->release(drefs->refs); + ref_store_release(drefs->refs); + free(drefs->refs); trace_printf_key(&trace_refs, "release\n"); } diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c index 9ba94cdffa4c47..6184db863f9462 100644 --- a/t/helper/test-repository.c +++ b/t/helper/test-repository.c @@ -6,6 +6,7 @@ #include "environment.h" #include "hex.h" #include "object.h" +#include "refs.h" #include "repository.h" #include "setup.h" #include "tree.h" @@ -65,11 +66,27 @@ static void test_get_commit_tree_in_graph(const char *gitdir, repo_clear(&r); } +static void test_ref_store(const char *gitdir) +{ + struct repository r; + struct object_id oid; + + if (repo_init(&r, gitdir, NULL)) + die("cannot open repository %s", gitdir); + if (refs_read_ref(get_main_ref_store(&r), "HEAD", &oid)) + die("cannot read HEAD"); + repo_clear(&r); +} + int cmd__repository(int argc, const char **argv) { if (argc < 2) die("must have at least 2 arguments"); - if (!strcmp(argv[1], "parse_commit_in_graph")) { + if (!strcmp(argv[1], "ref-store")) { + if (argc != 3) + die("usage: test-tool repository ref-store "); + test_ref_store(argv[2]); + } else if (!strcmp(argv[1], "parse_commit_in_graph")) { struct object_id oid; if (argc < 5) die("not enough arguments"); diff --git a/t/t1405-main-ref-store.sh b/t/t1405-main-ref-store.sh index 6d8f401a2a9827..fca3b7415b562c 100755 --- a/t/t1405-main-ref-store.sh +++ b/t/t1405-main-ref-store.sh @@ -14,6 +14,13 @@ test_expect_success 'setup' ' test_commit one ' +for trace in 0 1 +do + test_expect_success "release main ref store with GIT_TRACE_REFS=$trace" ' + GIT_TRACE_REFS=$trace test-tool repository ref-store .git + ' +done + test_expect_success 'create_symref(FOO, refs/heads/main)' ' $RUN create-symref FOO refs/heads/main nothing && echo refs/heads/main >expected &&