diff options
author | Michael Haggerty <mhagger@alum.mit.edu> | 2017-04-16 09:41:34 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-04-17 07:32:46 +0300 |
commit | df30875987329bb46e54ec7be0eb29c33702de3a (patch) | |
tree | 6c2f92e2dbadf9554198da881f9ac002210d4565 /refs/ref-cache.h | |
parent | e00d1a4ff7d79b403bf97a0746138d584c9ebf9a (diff) |
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.h')
-rw-r--r-- | refs/ref-cache.h | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/refs/ref-cache.h b/refs/ref-cache.h index 83051854ff..ed51e80d88 100644 --- a/refs/ref-cache.h +++ b/refs/ref-cache.h @@ -1,11 +1,27 @@ #ifndef REFS_REF_CACHE_H #define REFS_REF_CACHE_H +struct ref_dir; + +/* + * If this ref_cache is filled lazily, this function is used to load + * information into the specified ref_dir (shallow or deep, at the + * option of the ref_store). dirname includes a trailing slash. + */ +typedef void fill_ref_dir_fn(struct ref_store *ref_store, + struct ref_dir *dir, const char *dirname); + struct ref_cache { struct ref_entry *root; - /* A pointer to the files_ref_store whose cache this is: */ - struct files_ref_store *ref_store; + /* A pointer to the ref_store whose cache this is: */ + struct ref_store *ref_store; + + /* + * Function used (if necessary) to lazily-fill cache. May be + * NULL. + */ + fill_ref_dir_fn *fill_ref_dir; }; /* @@ -174,9 +190,14 @@ struct ref_entry *create_ref_entry(const char *refname, /* * Return a pointer to a new `ref_cache`. Its top-level starts out - * marked incomplete. + * marked incomplete. If `fill_ref_dir` is non-NULL, it is the + * function called to fill in incomplete directories in the + * `ref_cache` when they are accessed. If it is NULL, then the whole + * `ref_cache` must be filled (including clearing its directories' + * `REF_INCOMPLETE` bits) before it is used. */ -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); /* * Free the `ref_cache` and all of its associated data. |