Skip to content

Commit 0c09ec0

Browse files
dturner-twgitster
authored andcommitted
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>
1 parent 7d61826 commit 0c09ec0

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

refs/files-backend.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,10 @@ static int files_ref_iterator_advance(struct ref_iterator *ref_iterator)
17981798
int ok;
17991799

18001800
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+
18011805
if (!(iter->flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
18021806
!ref_resolves_to_object(iter->iter0->refname,
18031807
iter->iter0->oid,

refs/refs-internal.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,18 @@ extern struct ref_iterator *current_ref_iter;
467467
int do_for_each_ref_iterator(struct ref_iterator *iter,
468468
each_ref_fn fn, void *cb_data);
469469

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
471477

472478
struct ref_store;
473479

480+
/* refs backends */
481+
474482
/*
475483
* Initialize the ref_store for the specified submodule, or for the
476484
* main repository if submodule == NULL. These functions should call

0 commit comments

Comments
 (0)