t0302 & t3900: add forgotten quotes
[gitweb.git] / refs / ref-cache.h
index da5388c136d82ce859b192b33803844b0c2648fe..ffdc54f3f07961b1ddd6b56c64973e40c18583bd 100644 (file)
@@ -1,8 +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 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;
 };
 
 /*
@@ -66,8 +85,8 @@ struct ref_dir {
         */
        int sorted;
 
-       /* A pointer to the files_ref_store that contains this ref_dir. */
-       struct files_ref_store *ref_store;
+       /* The ref_cache containing this entry: */
+       struct ref_cache *cache;
 
        struct ref_entry **entries;
 };
@@ -161,7 +180,7 @@ struct ref_dir *get_ref_dir(struct ref_entry *entry);
  * dirname is the name of the directory with a trailing slash (e.g.,
  * "refs/heads/") or "" for the top-level directory.
  */
-struct ref_entry *create_dir_entry(struct files_ref_store *ref_store,
+struct ref_entry *create_dir_entry(struct ref_cache *cache,
                                   const char *dirname, size_t len,
                                   int incomplete);
 
@@ -171,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.
@@ -210,18 +234,6 @@ int remove_entry_from_dir(struct ref_dir *dir, const char *refname);
  */
 int add_ref_entry(struct ref_dir *dir, struct ref_entry *ref);
 
-/*
- * If refname is a reference name, find the ref_dir within the dir
- * tree that should hold refname. If refname is a directory name
- * (i.e., it ends in '/'), then return that ref_dir itself. dir must
- * represent the top-level directory and must already be complete.
- * Sort ref_dirs and recurse into subdirectories as necessary. If
- * mkdir is set, then create any missing directories; otherwise,
- * return NULL if the desired directory cannot be found.
- */
-struct ref_dir *find_containing_dir(struct ref_dir *dir,
-                                   const char *refname, int mkdir);
-
 /*
  * Find the value entry with the given name in dir, sorting ref_dirs
  * and recursing into subdirectories as necessary.  If the name is not
@@ -229,19 +241,15 @@ struct ref_dir *find_containing_dir(struct ref_dir *dir,
  */
 struct ref_entry *find_ref_entry(struct ref_dir *dir, const char *refname);
 
-struct ref_iterator *cache_ref_iterator_begin(struct ref_dir *dir);
-
-typedef int each_ref_entry_fn(struct ref_entry *entry, void *cb_data);
-
 /*
- * Call fn for each reference in dir that has index in the range
- * offset <= index < dir->nr.  Recurse into subdirectories that are in
- * that index range, sorting them before iterating.  This function
- * does not sort dir itself; it should be sorted beforehand.  fn is
- * called for all references, including broken ones.
+ * Start iterating over references in `cache`. If `prefix` is
+ * specified, only include references whose names start with that
+ * prefix. If `prime_dir` is true, then fill any incomplete
+ * directories before beginning the iteration.
  */
-int do_for_each_entry_in_dir(struct ref_dir *dir, int offset,
-                            each_ref_entry_fn fn, void *cb_data);
+struct ref_iterator *cache_ref_iterator_begin(struct ref_cache *cache,
+                                             const char *prefix,
+                                             int prime_dir);
 
 /*
  * Peel the entry (if possible) and return its new peel_status.  If
@@ -256,9 +264,4 @@ int do_for_each_entry_in_dir(struct ref_dir *dir, int offset,
  */
 enum peel_status peel_entry(struct ref_entry *entry, int repeel);
 
-/*
- * Load all of the refs from `dir` into our in-memory cache.
- */
-void prime_ref_dir(struct ref_dir *dir);
-
 #endif /* REFS_REF_CACHE_H */