git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jeff King <peff@peff.net>
Date
Apr 29, 2024, 08:21 UTC
Message-ID
<20240429082148.GB233423@coredump.intra.peff.net>

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 --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[] = {
-- 
2.45.0.rc1.416.gbe2a76c799
Message 1 of 1 in “refs: move is_pseudoref_syntax() definition earlier”
  1. 3/8 refs: move is_pseudoref_syntax() definition earlierJeff King, Apr 29, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.