MCPcopy Create free account
hub / github.com/git/git / files_ref_iterator_begin

Function files_ref_iterator_begin

refs/files-backend.c:1012–1073  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1010};
1011
1012static struct ref_iterator *files_ref_iterator_begin(
1013 struct ref_store *ref_store,
1014 const char *prefix, const char **exclude_patterns,
1015 unsigned int flags)
1016{
1017 struct files_ref_store *refs;
1018 struct ref_iterator *loose_iter, *packed_iter, *overlay_iter;
1019 struct files_ref_iterator *iter;
1020 struct ref_iterator *ref_iterator;
1021 unsigned int required_flags = REF_STORE_READ;
1022
1023 if (!(flags & REFS_FOR_EACH_INCLUDE_BROKEN))
1024 required_flags |= REF_STORE_ODB;
1025
1026 refs = files_downcast(ref_store, required_flags, "ref_iterator_begin");
1027
1028 /*
1029 * We must make sure that all loose refs are read before
1030 * accessing the packed-refs file; this avoids a race
1031 * condition if loose refs are migrated to the packed-refs
1032 * file by a simultaneous process, but our in-memory view is
1033 * from before the migration. We ensure this as follows:
1034 * First, we call start the loose refs iteration with its
1035 * `prime_ref` argument set to true. This causes the loose
1036 * references in the subtree to be pre-read into the cache.
1037 * (If they've already been read, that's OK; we only need to
1038 * guarantee that they're read before the packed refs, not
1039 * *how much* before.) After that, we call
1040 * packed_ref_iterator_begin(), which internally checks
1041 * whether the packed-ref cache is up to date with what is on
1042 * disk, and re-reads it if not.
1043 */
1044
1045 loose_iter = cache_ref_iterator_begin(get_loose_ref_cache(refs, flags),
1046 prefix, ref_store->repo, 1);
1047
1048 /*
1049 * The packed-refs file might contain broken references, for
1050 * example an old version of a reference that points at an
1051 * object that has since been garbage-collected. This is OK as
1052 * long as there is a corresponding loose reference that
1053 * overrides it, and we don't want to emit an error message in
1054 * this case. So ask the packed_ref_store for all of its
1055 * references, and (if needed) do our own check for broken
1056 * ones in files_ref_iterator_advance(), after we have merged
1057 * the packed and loose references.
1058 */
1059 packed_iter = refs_ref_iterator_begin(
1060 refs->packed_ref_store, prefix, exclude_patterns, 0,
1061 REFS_FOR_EACH_INCLUDE_BROKEN);
1062
1063 overlay_iter = overlay_ref_iterator_begin(loose_iter, packed_iter);
1064
1065 CALLOC_ARRAY(iter, 1);
1066 ref_iterator = &iter->base;
1067 base_ref_iterator_init(ref_iterator, &files_ref_iterator_vtable);
1068 iter->iter0 = overlay_iter;
1069 iter->repo = ref_store->repo;

Callers

nothing calls this directly

Calls 6

files_downcastFunction · 0.85
cache_ref_iterator_beginFunction · 0.85
get_loose_ref_cacheFunction · 0.85
refs_ref_iterator_beginFunction · 0.85
base_ref_iterator_initFunction · 0.85

Tested by

no test coverage detected