cache_ref_iterator_begin(): make function smarter
Change `cache_ref_iterator_begin()` to take two new arguments: * `prefix` -- to iterate only over references with the specified prefix. * `prime_dir` -- to "prime" (i.e., pre-load) the cache before starting the iteration. The new functionality makes it possible for `files_ref_iterator_begin()` to be made more ignorant of the internals of `ref_cache`, and `find_containing_dir()` and `prime_ref_dir()` to be made private. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
a714b19ca8
commit
059ae35a48
@ -1082,7 +1082,6 @@ static struct ref_iterator *files_ref_iterator_begin(
|
||||
const char *prefix, unsigned int flags)
|
||||
{
|
||||
struct files_ref_store *refs;
|
||||
struct ref_dir *loose_dir, *packed_dir;
|
||||
struct ref_iterator *loose_iter, *packed_iter;
|
||||
struct files_ref_iterator *iter;
|
||||
struct ref_iterator *ref_iterator;
|
||||
@ -1106,41 +1105,24 @@ static struct ref_iterator *files_ref_iterator_begin(
|
||||
* condition if loose refs are migrated to the packed-refs
|
||||
* file by a simultaneous process, but our in-memory view is
|
||||
* from before the migration. We ensure this as follows:
|
||||
* First, we call prime_ref_dir(), which pre-reads the loose
|
||||
* references for the subtree into the cache. (If they've
|
||||
* already been read, that's OK; we only need to guarantee
|
||||
* that they're read before the packed refs, not *how much*
|
||||
* before.) After that, we call get_packed_ref_cache(), which
|
||||
* internally checks whether the packed-ref cache is up to
|
||||
* date with what is on disk, and re-reads it if not.
|
||||
* First, we call start the loose refs iteration with its
|
||||
* `prime_ref` argument set to true. This causes the loose
|
||||
* references in the subtree to be pre-read into the cache.
|
||||
* (If they've already been read, that's OK; we only need to
|
||||
* guarantee that they're read before the packed refs, not
|
||||
* *how much* before.) After that, we call
|
||||
* get_packed_ref_cache(), which internally checks whether the
|
||||
* packed-ref cache is up to date with what is on disk, and
|
||||
* re-reads it if not.
|
||||
*/
|
||||
|
||||
loose_dir = get_loose_ref_dir(refs);
|
||||
|
||||
if (prefix && *prefix)
|
||||
loose_dir = find_containing_dir(loose_dir, prefix, 0);
|
||||
|
||||
if (loose_dir) {
|
||||
prime_ref_dir(loose_dir);
|
||||
loose_iter = cache_ref_iterator_begin(loose_dir);
|
||||
} else {
|
||||
/* There's nothing to iterate over. */
|
||||
loose_iter = empty_ref_iterator_begin();
|
||||
}
|
||||
loose_iter = cache_ref_iterator_begin(get_loose_ref_cache(refs),
|
||||
prefix, 1);
|
||||
|
||||
iter->packed_ref_cache = get_packed_ref_cache(refs);
|
||||
acquire_packed_ref_cache(iter->packed_ref_cache);
|
||||
packed_dir = get_packed_ref_dir(iter->packed_ref_cache);
|
||||
|
||||
if (prefix && *prefix)
|
||||
packed_dir = find_containing_dir(packed_dir, prefix, 0);
|
||||
|
||||
if (packed_dir) {
|
||||
packed_iter = cache_ref_iterator_begin(packed_dir);
|
||||
} else {
|
||||
/* There's nothing to iterate over. */
|
||||
packed_iter = empty_ref_iterator_begin();
|
||||
}
|
||||
packed_iter = cache_ref_iterator_begin(iter->packed_ref_cache->cache,
|
||||
prefix, 0);
|
||||
|
||||
iter->iter0 = overlay_ref_iterator_begin(loose_iter, packed_iter);
|
||||
iter->flags = flags;
|
||||
|
Reference in New Issue
Block a user