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 <dtur...@twopensource.com>
Signed-off-by: Junio C Hamano <gits...@pobox.com>
---
 refs/files-backend.c | 16 ++++++++++++++++
 refs/refs-internal.h |  7 +++++++
 2 files changed, 23 insertions(+)

diff --git a/refs/files-backend.c b/refs/files-backend.c
index f3d857a..31f38d0 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -560,6 +560,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;
 
@@ -1693,6 +1697,18 @@ static int files_do_for_each_ref(const char *submodule, 
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)
+{
+       /*
+        * It's important that this one use the files backend, since
+        *  that's what controls the per-worktree refs
+        */
+       return files_do_for_each_ref(submodule, base, fn, trim,
+                                    flags | DO_FOR_EACH_PER_WORKTREE_ONLY, 
cb_data);
+}
+
 static void unlock_ref(struct ref_lock *lock)
 {
        /* Do not free lock->lk -- atexit() still looks at them */
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index 3702737..bb0d588 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -203,6 +203,13 @@ int rename_ref_available(const char *oldname, const char 
*newname);
 /* 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);
+
 /* refs backends */
 typedef int ref_transaction_commit_fn(struct ref_transaction *transaction,
                                      struct strbuf *err);
-- 
2.4.2.767.g62658d5-twtrsrc

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to