From d0f00c1ac17bf1e00c2721a90e2bbdb132b5ab6e Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Fri, 23 Feb 2024 11:01:10 +0100 Subject: refs: introduce `refs_for_each_include_root_refs()` Introduce a new ref iteration flag `DO_FOR_EACH_INCLUDE_ROOT_REFS`, which will be used to iterate over regular refs plus pseudorefs and HEAD. Refs which fall outside the `refs/` and aren't either pseudorefs or HEAD are more of a grey area. This is because we don't block the users from creating such refs but they are not officially supported. Introduce `refs_for_each_include_root_refs()` which calls `do_for_each_ref()` with this newly introduced flag. In `refs/files-backend.c`, introduce a new function `add_pseudoref_and_head_entries()` to add pseudorefs and HEAD to the `ref_dir`. We then finally call `add_pseudoref_and_head_entries()` whenever the `DO_FOR_EACH_INCLUDE_ROOT_REFS` flag is set. Any new ref backend will also have to implement similar changes on its end. Signed-off-by: Karthik Nayak Signed-off-by: Junio C Hamano --- refs.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'refs.h') diff --git a/refs.h b/refs.h index f66cdd731c..5cfaee6229 100644 --- a/refs.h +++ b/refs.h @@ -398,6 +398,12 @@ int for_each_namespaced_ref(const char **exclude_patterns, int refs_for_each_rawref(struct ref_store *refs, each_ref_fn fn, void *cb_data); int for_each_rawref(each_ref_fn fn, void *cb_data); +/* + * Iterates over all refs including root refs, i.e. pseudorefs and HEAD. + */ +int refs_for_each_include_root_refs(struct ref_store *refs, each_ref_fn fn, + void *cb_data); + /* * Normalizes partial refs to their fully qualified form. * Will prepend to the if it doesn't start with 'refs/'. -- cgit 1.2.3-korg