Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions refs/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,33 @@ 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;

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");
}

Expand Down
19 changes: 18 additions & 1 deletion t/helper/test-repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 <gitdir>");
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");
Expand Down
7 changes: 7 additions & 0 deletions t/t1405-main-ref-store.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
Loading