Alternate refs backends might still use files to store per-worktree refs. So the files backend's ref-loading infrastructure should be available to those backends, just for use on per-worktree refs. Add do_for_each_per_worktree_ref, which iterates over per-worktree refs. Signed-off-by: David Turner <dturner@xxxxxxxxxxxxxxxx> --- refs/files-backend.c | 15 ++++++++++++--- refs/refs-internal.h | 10 ++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 0772a02..3d678ad 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -518,9 +518,6 @@ static void sort_ref_dir(struct ref_dir *dir) dir->sorted = dir->nr = i; } -/* Include broken references in a do_for_each_ref*() iteration: */ -#define DO_FOR_EACH_INCLUDE_BROKEN 0x01 - /* * Return true iff the reference described by entry can be resolved to * an object in the database. Emit a warning if the referred-to @@ -568,6 +565,10 @@ static int do_one_ref(struct ref_entry *entry, void *cb_data) struct ref_entry *old_current_ref; int retval; + if (data->flags & DO_FOR_EACH_PER_WORKTREE_ONLY && + ref_type(entry->name) != REF_TYPE_PER_WORKTREE) + return 0; + if (!starts_with(entry->name, data->base)) return 0; @@ -1756,6 +1757,14 @@ static int do_for_each_ref(struct ref_cache *refs, const char *base, return do_for_each_entry(refs, base, do_one_ref, &data); } +int do_for_each_per_worktree_ref(const char *submodule, const char *base, + each_ref_fn fn, int trim, int flags, + void *cb_data) +{ + return do_for_each_ref(get_ref_cache(submodule), base, fn, trim, + flags | DO_FOR_EACH_PER_WORKTREE_ONLY, cb_data); +} + static int do_head_ref(const char *submodule, each_ref_fn fn, void *cb_data) { struct object_id oid; diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 4a1d215..cb949c5 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -57,6 +57,16 @@ */ int refname_is_safe(const char *refname); +/* Include broken references in a do_for_each_ref*() iteration */ +#define DO_FOR_EACH_INCLUDE_BROKEN 0x01 + +/* Only include per-worktree refs in a do_for_each_ref*() iteration */ +#define DO_FOR_EACH_PER_WORKTREE_ONLY 0x02 + +int do_for_each_per_worktree_ref(const char *submodule, const char *base, + each_ref_fn fn, int trim, int flags, + void *cb_data); + enum peel_status { /* object was peeled successfully: */ PEEL_PEELED = 0, -- 2.4.2.749.g730654d-twtrsrc -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html