refs: peeling non-the_repository iterators is BUG

There is currently no support for peeling the current ref of an iterator iterating over a non-the_repository ref store, and none is needed. Thus, for now, BUG() if that happens. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Oct 8, 2021 at 14:08 UTC 8788195c8846be949e6cd4bd19c8dc5e6371ffd3
4 files changed +17 -2
refs/files-backend.c
+3 -2
@@ -833,7 +833,7 @@ static struct ref_iterator *files_ref_iterator_begin(
833 */
834
835 loose_iter = cache_ref_iterator_begin(get_loose_ref_cache(refs),
836 - prefix, 1);
836 + prefix, ref_store->repo, 1);
837
838 /*
839 * The packed-refs file might contain broken references, for
@@ -1165,7 +1165,8 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
1165
1166 packed_refs_lock(refs->packed_ref_store, LOCK_DIE_ON_ERROR, &err);
1167
1168 - iter = cache_ref_iterator_begin(get_loose_ref_cache(refs), NULL, 0);
1168 + iter = cache_ref_iterator_begin(get_loose_ref_cache(refs), NULL,
1169 + the_repository, 0);
1170 while ((ok = ref_iterator_advance(iter)) == ITER_OK) {
1171 /*
1172 * If the loose reference can be packed, add an entry
refs/packed-backend.c
+3
@@ -886,6 +886,9 @@ static int packed_ref_iterator_peel(struct ref_iterator *ref_iterator,
886 struct packed_ref_iterator *iter =
887 (struct packed_ref_iterator *)ref_iterator;
888
889 + if (iter->repo != the_repository)
890 + BUG("peeling for non-the_repository is not supported");
891 +
892 if ((iter->base.flags & REF_KNOWS_PEELED)) {
893 oidcpy(peeled, &iter->peeled);
894 return is_null_oid(&iter->peeled) ? -1 : 0;
refs/ref-cache.c
+10
@@ -435,6 +435,8 @@ struct cache_ref_iterator {
435 * on from there.)
436 */
437 struct cache_ref_iterator_level *levels;
438 +
439 + struct repository *repo;
440 };
441
442 static int cache_ref_iterator_advance(struct ref_iterator *ref_iterator)
@@ -491,6 +493,11 @@ static int cache_ref_iterator_advance(struct ref_iterator *ref_iterator)
493 static int cache_ref_iterator_peel(struct ref_iterator *ref_iterator,
494 struct object_id *peeled)
495 {
496 + struct cache_ref_iterator *iter =
497 + (struct cache_ref_iterator *)ref_iterator;
498 +
499 + if (iter->repo != the_repository)
500 + BUG("peeling for non-the_repository is not supported");
501 return peel_object(ref_iterator->oid, peeled) ? -1 : 0;
502 }
503
@@ -513,6 +520,7 @@ static struct ref_iterator_vtable cache_ref_iterator_vtable = {
520
521 struct ref_iterator *cache_ref_iterator_begin(struct ref_cache *cache,
522 const char *prefix,
523 + struct repository *repo,
524 int prime_dir)
525 {
526 struct ref_dir *dir;
@@ -547,5 +555,7 @@ struct ref_iterator *cache_ref_iterator_begin(struct ref_cache *cache,
555 level->prefix_state = PREFIX_CONTAINS_DIR;
556 }
557
558 + iter->repo = repo;
559 +
560 return ref_iterator;
561 }
refs/ref-cache.h
+1
@@ -238,6 +238,7 @@ struct ref_entry *find_ref_entry(struct ref_dir *dir, const char *refname);
238 */
239 struct ref_iterator *cache_ref_iterator_begin(struct ref_cache *cache,
240 const char *prefix,
241 + struct repository *repo,
242 int prime_dir);
243
244 #endif /* REFS_REF_CACHE_H */