diff mbox series

[3/8] refs: move is_pseudoref_syntax() definition earlier

Message ID 20240429082148.GB233423@coredump.intra.peff.net (mailing list archive)
State New, archived
Headers show
Series tightening ref handling outside of refs/ | expand

Commit Message

Jeff King April 29, 2024, 8:21 a.m. UTC
We have a static local function is_pseudoref_syntax(), used by
is_pseudoref(). The difference being that the former checks only syntax,
whereas the latter actually looks at the on-disk refs.

There are a few other places in the file where we care about the
pseudoref syntax and could make use of this function. Let's move it
earlier in the file, so it can be used more extensively without having
to forward declare it.

Signed-off-by: Jeff King <peff@peff.net>
---
 refs.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/refs.c b/refs.c
index 55d2e0b2cb..d3d21ecd43 100644
--- a/refs.c
+++ b/refs.c
@@ -164,6 +164,22 @@  void update_ref_namespace(enum ref_namespace namespace, char *ref)
 	info->ref_updated = 1;
 }
 
+static int is_pseudoref_syntax(const char *refname)
+{
+	const char *c;
+
+	for (c = refname; *c; c++) {
+		if (!isupper(*c) && *c != '-' && *c != '_')
+			return 0;
+	}
+
+	/*
+	 * HEAD is not a pseudoref, but it certainly uses the
+	 * pseudoref syntax.
+	 */
+	return 1;
+}
+
 /*
  * Try to read one refname component from the front of refname.
  * Return the length of the component found, or -1 if the component is
@@ -844,22 +860,6 @@  int is_per_worktree_ref(const char *refname)
 	       starts_with(refname, "refs/rewritten/");
 }
 
-static int is_pseudoref_syntax(const char *refname)
-{
-	const char *c;
-
-	for (c = refname; *c; c++) {
-		if (!isupper(*c) && *c != '-' && *c != '_')
-			return 0;
-	}
-
-	/*
-	 * HEAD is not a pseudoref, but it certainly uses the
-	 * pseudoref syntax.
-	 */
-	return 1;
-}
-
 int is_pseudoref(struct ref_store *refs, const char *refname)
 {
 	static const char *const irregular_pseudorefs[] = {