Skip to content

Commit 34224e1

Browse files
jonathantanmygitster
authored andcommitted
refs: plumb repo into ref stores
In preparation for the next 2 patches that adds (partial) support for arbitrary repositories to ref iterators, plumb a repository into all ref stores. There are no changes to program logic. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b6b210c commit 34224e1

File tree

5 files changed

+40
-13
lines changed

5 files changed

+40
-13
lines changed

refs.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,7 +1873,8 @@ static struct ref_store *lookup_ref_store_map(struct hashmap *map,
18731873
* Create, record, and return a ref_store instance for the specified
18741874
* gitdir.
18751875
*/
1876-
static struct ref_store *ref_store_init(const char *gitdir,
1876+
static struct ref_store *ref_store_init(struct repository *repo,
1877+
const char *gitdir,
18771878
unsigned int flags)
18781879
{
18791880
const char *be_name = "files";
@@ -1883,7 +1884,7 @@ static struct ref_store *ref_store_init(const char *gitdir,
18831884
if (!be)
18841885
BUG("reference backend %s is unknown", be_name);
18851886

1886-
refs = be->init(gitdir, flags);
1887+
refs = be->init(repo, gitdir, flags);
18871888
return refs;
18881889
}
18891890

@@ -1895,7 +1896,7 @@ struct ref_store *get_main_ref_store(struct repository *r)
18951896
if (!r->gitdir)
18961897
BUG("attempting to get main_ref_store outside of repository");
18971898

1898-
r->refs_private = ref_store_init(r->gitdir, REF_STORE_ALL_CAPS);
1899+
r->refs_private = ref_store_init(r, r->gitdir, REF_STORE_ALL_CAPS);
18991900
r->refs_private = maybe_debug_wrap_ref_store(r->gitdir, r->refs_private);
19001901
return r->refs_private;
19011902
}
@@ -1925,6 +1926,7 @@ struct ref_store *get_submodule_ref_store(const char *submodule)
19251926
struct ref_store *refs;
19261927
char *to_free = NULL;
19271928
size_t len;
1929+
struct repository *subrepo;
19281930

19291931
if (!submodule)
19301932
return NULL;
@@ -1950,8 +1952,19 @@ struct ref_store *get_submodule_ref_store(const char *submodule)
19501952
if (submodule_to_gitdir(&submodule_sb, submodule))
19511953
goto done;
19521954

1953-
/* assume that add_submodule_odb() has been called */
1954-
refs = ref_store_init(submodule_sb.buf,
1955+
subrepo = xmalloc(sizeof(*subrepo));
1956+
/*
1957+
* NEEDSWORK: Make get_submodule_ref_store() work with arbitrary
1958+
* superprojects other than the_repository. This probably should be
1959+
* done by making it take a struct repository * parameter instead of a
1960+
* submodule path.
1961+
*/
1962+
if (repo_submodule_init(subrepo, the_repository, submodule,
1963+
null_oid())) {
1964+
free(subrepo);
1965+
goto done;
1966+
}
1967+
refs = ref_store_init(subrepo, submodule_sb.buf,
19551968
REF_STORE_READ | REF_STORE_ODB);
19561969
register_ref_store_map(&submodule_ref_stores, "submodule",
19571970
refs, submodule);
@@ -1977,10 +1990,12 @@ struct ref_store *get_worktree_ref_store(const struct worktree *wt)
19771990
return refs;
19781991

19791992
if (wt->id)
1980-
refs = ref_store_init(git_common_path("worktrees/%s", wt->id),
1993+
refs = ref_store_init(the_repository,
1994+
git_common_path("worktrees/%s", wt->id),
19811995
REF_STORE_ALL_CAPS);
19821996
else
1983-
refs = ref_store_init(get_git_common_dir(),
1997+
refs = ref_store_init(the_repository,
1998+
get_git_common_dir(),
19841999
REF_STORE_ALL_CAPS);
19852000

19862001
if (refs)

refs/files-backend.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,23 @@ static void clear_loose_ref_cache(struct files_ref_store *refs)
7979
* Create a new submodule ref cache and add it to the internal
8080
* set of caches.
8181
*/
82-
static struct ref_store *files_ref_store_create(const char *gitdir,
82+
static struct ref_store *files_ref_store_create(struct repository *repo,
83+
const char *gitdir,
8384
unsigned int flags)
8485
{
8586
struct files_ref_store *refs = xcalloc(1, sizeof(*refs));
8687
struct ref_store *ref_store = (struct ref_store *)refs;
8788
struct strbuf sb = STRBUF_INIT;
8889

90+
ref_store->repo = repo;
8991
ref_store->gitdir = xstrdup(gitdir);
9092
base_ref_store_init(ref_store, &refs_be_files);
9193
refs->store_flags = flags;
9294

9395
get_common_dir_noenv(&sb, gitdir);
9496
refs->gitcommondir = strbuf_detach(&sb, NULL);
9597
strbuf_addf(&sb, "%s/packed-refs", refs->gitcommondir);
96-
refs->packed_ref_store = packed_ref_store_create(sb.buf, flags);
98+
refs->packed_ref_store = packed_ref_store_create(repo, sb.buf, flags);
9799
strbuf_release(&sb);
98100

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

refs/packed-backend.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,15 @@ static int release_snapshot(struct snapshot *snapshot)
193193
}
194194
}
195195

196-
struct ref_store *packed_ref_store_create(const char *path,
196+
struct ref_store *packed_ref_store_create(struct repository *repo,
197+
const char *path,
197198
unsigned int store_flags)
198199
{
199200
struct packed_ref_store *refs = xcalloc(1, sizeof(*refs));
200201
struct ref_store *ref_store = (struct ref_store *)refs;
201202

202203
base_ref_store_init(ref_store, &refs_be_packed);
204+
ref_store->repo = repo;
203205
ref_store->gitdir = xstrdup(path);
204206
refs->store_flags = store_flags;
205207

refs/packed-backend.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef REFS_PACKED_BACKEND_H
22
#define REFS_PACKED_BACKEND_H
33

4+
struct repository;
45
struct ref_transaction;
56

67
/*
@@ -12,7 +13,8 @@ struct ref_transaction;
1213
* even among packed refs.
1314
*/
1415

15-
struct ref_store *packed_ref_store_create(const char *path,
16+
struct ref_store *packed_ref_store_create(struct repository *repo,
17+
const char *path,
1618
unsigned int store_flags);
1719

1820
/*

refs/refs-internal.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,8 @@ struct ref_store;
539539
* should call base_ref_store_init() to initialize the shared part of
540540
* the ref_store and to record the ref_store for later lookup.
541541
*/
542-
typedef struct ref_store *ref_store_init_fn(const char *gitdir,
542+
typedef struct ref_store *ref_store_init_fn(struct repository *repo,
543+
const char *gitdir,
543544
unsigned int flags);
544545

545546
typedef int ref_init_db_fn(struct ref_store *refs, struct strbuf *err);
@@ -697,7 +698,12 @@ struct ref_store {
697698
/* The backend describing this ref_store's storage scheme: */
698699
const struct ref_storage_be *be;
699700

700-
/* The gitdir that this ref_store applies to: */
701+
struct repository *repo;
702+
703+
/*
704+
* The gitdir that this ref_store applies to. Note that this is not
705+
* necessarily repo->gitdir if the repo has multiple worktrees.
706+
*/
701707
char *gitdir;
702708
};
703709

0 commit comments

Comments
 (0)