[PATCH 1/3] refs: move `is_special_ref()`

Patrick Steinhardt
2024-04-29T13:41:28Z

[-- Attachment #1: Type: text/plain, Size: 2795 bytes --]

Move `is_special_ref()` further up so that we can start using it in
`is_pseudo_ref()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
refs.c | 62 +++++++++++++++++++++++++++++-----------------------------
1 file changed, 31 insertions(+), 31 deletions(-)

diff --git a/refs.c b/refs.c
index 55d2e0b2cb..c64f66bff9 100644
--- a/refs.c
+++ b/refs.c
@@ -844,6 +844,37 @@ int is_per_worktree_ref(const char *refname)
starts_with(refname, "refs/rewritten/");
}

+static int is_special_ref(const char *refname)
+{
+ /*
+ * Special references are refs that have different semantics compared
+ * to "normal" refs. These refs can thus not be stored in the ref
+ * backend, but must always be accessed via the filesystem. The
+ * following refs are special:
+ *
+ * - FETCH_HEAD may contain multiple object IDs, and each one of them
+ * carries additional metadata like where it came from.
+ *
+ * - MERGE_HEAD may contain multiple object IDs when merging multiple
+ * heads.
+ *
+ * Reading, writing or deleting references must consistently go either
+ * through the filesystem (special refs) or through the reference
+ * backend (normal ones).
+ */
+ static const char * const special_refs[] = {
+ "FETCH_HEAD",
+ "MERGE_HEAD",
+ };
+ size_t i;
+
+ for (i = 0; i < ARRAY_SIZE(special_refs); i++)
+ if (!strcmp(refname, special_refs[i]))
+ return 1;
+
+ return 0;
+}
+
static int is_pseudoref_syntax(const char *refname)
{
const char *c;
@@ -1876,37 +1907,6 @@ static int refs_read_special_head(struct ref_store *ref_store,
return result;
}

-static int is_special_ref(const char *refname)
-{
- /*
- * Special references are refs that have different semantics compared
- * to "normal" refs. These refs can thus not be stored in the ref
- * backend, but must always be accessed via the filesystem. The
- * following refs are special:
- *
- * - FETCH_HEAD may contain multiple object IDs, and each one of them
- * carries additional metadata like where it came from.
- *
- * - MERGE_HEAD may contain multiple object IDs when merging multiple
- * heads.
- *
- * Reading, writing or deleting references must consistently go either
- * through the filesystem (special refs) or through the reference
- * backend (normal ones).
- */
- static const char * const special_refs[] = {
- "FETCH_HEAD",
- "MERGE_HEAD",
- };
- size_t i;
-
- for (i = 0; i < ARRAY_SIZE(special_refs); i++)
- if (!strcmp(refname, special_refs[i]))
- return 1;
-
- return 0;
-}
-
int refs_read_raw_ref(struct ref_store *ref_store, const char *refname,
struct object_id *oid, struct strbuf *referent,
unsigned int *type, int *failure_errno)
--
2.45.0-rc1