Skip to content

Commit 01ea04f

Browse files
committed
Merge branch 'hn/refs-debug-update'
Debugging support for refs API. * hn/refs-debug-update: refs: centralize initialization of the base ref_store. refs: print error message in debug output refs: pass gitdir to packed_ref_store_create
2 parents 3c0e417 + f9f7fd3 commit 01ea04f

File tree

6 files changed

+19
-20
lines changed

6 files changed

+19
-20
lines changed

refs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,10 +2007,12 @@ struct ref_store *get_worktree_ref_store(const struct worktree *wt)
20072007
return refs;
20082008
}
20092009

2010-
void base_ref_store_init(struct ref_store *refs,
2011-
const struct ref_storage_be *be)
2010+
void base_ref_store_init(struct ref_store *refs, struct repository *repo,
2011+
const char *path, const struct ref_storage_be *be)
20122012
{
20132013
refs->be = be;
2014+
refs->repo = repo;
2015+
refs->gitdir = xstrdup(path);
20142016
}
20152017

20162018
/* backend functions */

refs/debug.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ struct ref_store *maybe_debug_wrap_ref_store(const char *gitdir, struct ref_stor
2626
be_copy->name = store->be->name;
2727
trace_printf_key(&trace_refs, "ref_store for %s\n", gitdir);
2828
res->refs = store;
29-
base_ref_store_init((struct ref_store *)res, be_copy);
29+
base_ref_store_init((struct ref_store *)res, store->repo, gitdir,
30+
be_copy);
3031
return (struct ref_store *)res;
3132
}
3233

@@ -47,7 +48,8 @@ static int debug_transaction_prepare(struct ref_store *refs,
4748
transaction->ref_store = drefs->refs;
4849
res = drefs->refs->be->transaction_prepare(drefs->refs, transaction,
4950
err);
50-
trace_printf_key(&trace_refs, "transaction_prepare: %d\n", res);
51+
trace_printf_key(&trace_refs, "transaction_prepare: %d \"%s\"\n", res,
52+
err->buf);
5153
return res;
5254
}
5355

refs/files-backend.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,12 @@ static struct ref_store *files_ref_store_create(struct repository *repo,
8686
struct ref_store *ref_store = (struct ref_store *)refs;
8787
struct strbuf sb = STRBUF_INIT;
8888

89-
ref_store->repo = repo;
90-
ref_store->gitdir = xstrdup(gitdir);
91-
base_ref_store_init(ref_store, &refs_be_files);
89+
base_ref_store_init(ref_store, repo, gitdir, &refs_be_files);
9290
refs->store_flags = flags;
93-
9491
get_common_dir_noenv(&sb, gitdir);
9592
refs->gitcommondir = strbuf_detach(&sb, NULL);
96-
strbuf_addf(&sb, "%s/packed-refs", refs->gitcommondir);
97-
refs->packed_ref_store = packed_ref_store_create(repo, sb.buf, flags);
98-
strbuf_release(&sb);
93+
refs->packed_ref_store =
94+
packed_ref_store_create(repo, refs->gitcommondir, flags);
9995

10096
chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir);
10197
chdir_notify_reparent("files-backend $GIT_COMMONDIR",

refs/packed-backend.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,19 @@ static int release_snapshot(struct snapshot *snapshot)
194194
}
195195

196196
struct ref_store *packed_ref_store_create(struct repository *repo,
197-
const char *path,
197+
const char *gitdir,
198198
unsigned int store_flags)
199199
{
200200
struct packed_ref_store *refs = xcalloc(1, sizeof(*refs));
201201
struct ref_store *ref_store = (struct ref_store *)refs;
202+
struct strbuf sb = STRBUF_INIT;
202203

203-
base_ref_store_init(ref_store, &refs_be_packed);
204-
ref_store->repo = repo;
205-
ref_store->gitdir = xstrdup(path);
204+
base_ref_store_init(ref_store, repo, gitdir, &refs_be_packed);
206205
refs->store_flags = store_flags;
207206

208-
refs->path = xstrdup(path);
207+
strbuf_addf(&sb, "%s/packed-refs", gitdir);
208+
refs->path = strbuf_detach(&sb, NULL);
209209
chdir_notify_reparent("packed-refs", &refs->path);
210-
211210
return ref_store;
212211
}
213212

refs/packed-backend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct ref_transaction;
1414
*/
1515

1616
struct ref_store *packed_ref_store_create(struct repository *repo,
17-
const char *path,
17+
const char *gitdir,
1818
unsigned int store_flags);
1919

2020
/*

refs/refs-internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,8 @@ int parse_loose_ref_contents(const char *buf, struct object_id *oid,
710710
* Fill in the generic part of refs and add it to our collection of
711711
* reference stores.
712712
*/
713-
void base_ref_store_init(struct ref_store *refs,
714-
const struct ref_storage_be *be);
713+
void base_ref_store_init(struct ref_store *refs, struct repository *repo,
714+
const char *path, const struct ref_storage_be *be);
715715

716716
/*
717717
* Support GIT_TRACE_REFS by optionally wrapping the given ref_store instance.

0 commit comments

Comments
 (0)