diff options
author | Michael Haggerty <mhagger@alum.mit.edu> | 2017-04-16 08:41:34 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-04-16 21:32:46 -0700 |
commit | df30875987329bb46e54ec7be0eb29c33702de3a (patch) | |
tree | 6c2f92e2dbadf9554198da881f9ac002210d4565 /refs/ref-cache.c | |
parent | e00d1a4ff7d79b403bf97a0746138d584c9ebf9a (diff) | |
download | git-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/ref-cache.c')
-rw-r--r-- | refs/ref-cache.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/refs/ref-cache.c b/refs/ref-cache.c index 96da094788..7f247b9170 100644 --- a/refs/ref-cache.c +++ b/refs/ref-cache.c @@ -4,9 +4,6 @@ #include "ref-cache.h" #include "../iterator.h" -/* FIXME: This declaration shouldn't be here */ -void read_loose_refs(const char *dirname, struct ref_dir *dir); - void add_entry_to_dir(struct ref_dir *dir, struct ref_entry *entry) { ALLOC_GROW(dir->entries, dir->nr + 1, dir->alloc); @@ -25,7 +22,10 @@ struct ref_dir *get_ref_dir(struct ref_entry *entry) assert(entry->flag & REF_DIR); dir = &entry->u.subdir; if (entry->flag & REF_INCOMPLETE) { - read_loose_refs(entry->name, dir); + if (!dir->cache->fill_ref_dir) + die("BUG: incomplete ref_store without fill_ref_dir function"); + + dir->cache->fill_ref_dir(dir->cache->ref_store, dir, entry->name); /* * Manually add refs/bisect, which, being @@ -63,11 +63,13 @@ struct ref_entry *create_ref_entry(const char *refname, return ref; } -struct ref_cache *create_ref_cache(struct files_ref_store *refs) +struct ref_cache *create_ref_cache(struct ref_store *refs, + fill_ref_dir_fn *fill_ref_dir) { struct ref_cache *ret = xcalloc(1, sizeof(*ret)); ret->ref_store = refs; + ret->fill_ref_dir = fill_ref_dir; ret->root = create_dir_entry(ret, "", 0, 1); return ret; } |