refs: implement iteration over only per-worktree refs

Alternate refs backends might still use files to store per-worktree refs. So provide a way to iterate over only the per-worktree references in a ref_store. The other backend can set up a files ref_store and iterate using the new DO_FOR_EACH_PER_WORKTREE_ONLY flag when iterating. Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Turner committed Sep 4, 2016 at 18:08 UTC 0c09ec07d1e617be5f2d7b5c937b60e77a30ede2
2 files changed +13 -1
refs/files-backend.c
+4
@@ -1798,6 +1798,10 @@ static int files_ref_iterator_advance(struct ref_iterator *ref_iterator)
1798 int ok;
1799
1800 while ((ok = ref_iterator_advance(iter->iter0)) == ITER_OK) {
1801 + if (iter->flags & DO_FOR_EACH_PER_WORKTREE_ONLY &&
1802 + ref_type(iter->iter0->refname) != REF_TYPE_PER_WORKTREE)
1803 + continue;
1804 +
1805 if (!(iter->flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
1806 !ref_resolves_to_object(iter->iter0->refname,
1807 iter->iter0->oid,
refs/refs-internal.h
+9 -1
@@ -467,10 +467,18 @@ extern struct ref_iterator *current_ref_iter;
467 int do_for_each_ref_iterator(struct ref_iterator *iter,
468 each_ref_fn fn, void *cb_data);
469
470 -/* refs backends */
470 +/*
471 + * Only include per-worktree refs in a do_for_each_ref*() iteration.
472 + * Normally this will be used with a files ref_store, since that's
473 + * where all reference backends will presumably store their
474 + * per-worktree refs.
475 + */
476 +#define DO_FOR_EACH_PER_WORKTREE_ONLY 0x02
477
478 struct ref_store;
479
480 +/* refs backends */
481 +
482 /*
483 * Initialize the ref_store for the specified submodule, or for the
484 * main repository if submodule == NULL. These functions should call