summaryrefslogtreecommitdiff
path: root/refs/files-backend.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2017-04-16 08:41:34 +0200
committerJunio C Hamano <gitster@pobox.com>2017-04-16 21:32:46 -0700
commitdf30875987329bb46e54ec7be0eb29c33702de3a (patch)
tree6c2f92e2dbadf9554198da881f9ac002210d4565 /refs/files-backend.c
parente00d1a4ff7d79b403bf97a0746138d584c9ebf9a (diff)
downloadgit-df30875987329bb46e54ec7be0eb29c33702de3a.tar.gz
ref-cache: use a callback function to fill the cache
It is a leveling violation for `ref_cache` to know about `files_ref_store` or that it should call `read_loose_refs()` to lazily fill cache directories. So instead, have its constructor take as an argument a callback function that it should use for lazy-filling, and change `files_ref_store` to supply a pointer to function `read_loose_refs` (renamed to `loose_fill_ref_dir`) when creating the ref cache for its loose refs. This means that we can generify the type of the back-pointer in `struct ref_cache` from `files_ref_store` to `ref_store`. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs/files-backend.c')
-rw-r--r--refs/files-backend.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 1ed3a30d82..ff9251b9cd 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -386,7 +386,7 @@ static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *ref
refs->packed = xcalloc(1, sizeof(*refs->packed));
acquire_packed_ref_cache(refs->packed);
- refs->packed->cache = create_ref_cache(refs);
+ refs->packed->cache = create_ref_cache(&refs->base, NULL);
refs->packed->cache->root->flag &= ~REF_INCOMPLETE;
f = fopen(packed_refs_file, "r");
if (f) {
@@ -430,9 +430,11 @@ static void add_packed_ref(struct files_ref_store *refs,
* (without recursing). dirname must end with '/'. dir must be the
* directory entry corresponding to dirname.
*/
-void read_loose_refs(const char *dirname, struct ref_dir *dir)
+static void loose_fill_ref_dir(struct ref_store *ref_store,
+ struct ref_dir *dir, const char *dirname)
{
- struct files_ref_store *refs = dir->cache->ref_store;
+ struct files_ref_store *refs =
+ files_downcast(ref_store, REF_STORE_READ, "fill_ref_dir");
DIR *d;
struct dirent *de;
int dirnamelen = strlen(dirname);
@@ -515,7 +517,7 @@ static struct ref_dir *get_loose_refs(struct files_ref_store *refs)
* are about to read the only subdirectory that can
* hold references:
*/
- refs->loose = create_ref_cache(refs);
+ refs->loose = create_ref_cache(&refs->base, loose_fill_ref_dir);
/* We're going to fill the top level ourselves: */
refs->loose->root->flag &= ~REF_INCOMPLETE;