refs: pass gitdir to packed_ref_store_create

This is consistent with the calling convention for ref backend creation, and avoids storing ".git/packed-refs" (the name of a regular file) in a variable called ref_store::gitdir. Signed-off-by: Han-Wen Nienhuys <hanwen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Han-Wen Nienhuys committed Dec 22, 2021 at 18:11 UTC 99f0d97b736e80fb2f92f8a1a5fbc65b68c2a1b9
3 files changed +8 -8
refs/files-backend.c
+2 -3
@@ -93,9 +93,8 @@ static struct ref_store *files_ref_store_create(struct repository *repo,
93
94 get_common_dir_noenv(&sb, gitdir);
95 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);
96 + refs->packed_ref_store =
97 + packed_ref_store_create(repo, refs->gitcommondir, flags);
98
99 chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir);
100 chdir_notify_reparent("files-backend $GIT_COMMONDIR",
refs/packed-backend.c
+5 -4
@@ -194,20 +194,21 @@ static int release_snapshot(struct snapshot *snapshot)
194 }
195
196 struct ref_store *packed_ref_store_create(struct repository *repo,
197 - const char *path,
197 + const char *gitdir,
198 unsigned int store_flags)
199 {
200 struct packed_ref_store *refs = xcalloc(1, sizeof(*refs));
201 struct ref_store *ref_store = (struct ref_store *)refs;
202 + struct strbuf sb = STRBUF_INIT;
203
204 base_ref_store_init(ref_store, &refs_be_packed);
205 ref_store->repo = repo;
205 - ref_store->gitdir = xstrdup(path);
206 + ref_store->gitdir = xstrdup(gitdir);
207 refs->store_flags = store_flags;
208 + strbuf_addf(&sb, "%s/packed-refs", gitdir);
209 + refs->path = strbuf_detach(&sb, NULL);
210
208 - refs->path = xstrdup(path);
211 chdir_notify_reparent("packed-refs", &refs->path);
210 -
212 return ref_store;
213 }
214
refs/packed-backend.h
+1 -1
@@ -14,7 +14,7 @@ struct ref_transaction;
14 */
15
16 struct ref_store *packed_ref_store_create(struct repository *repo,
17 - const char *path,
17 + const char *gitdir,
18 unsigned int store_flags);
19
20 /*