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

[PATCH 4/8] refs: disallow dash in pseudoref syntax

From
Jeff King <peff@peff.net>
Date
Apr 29, 2024, 08:23 UTC
Message-ID
<20240429082302.GC233423@coredump.intra.peff.net>

Our is_pseudoref_syntax() function allows upper-case letters, underscore ("_") and dash ("-"). Our glossary definition is vague on the allowed punctuation, but I don't think we have ever used a pseudoref with anything but an underscore. And the existing open-coded syntax check in refname_is_safe() allows only underscores.

The logic comes from 266b18273a (refs: add ref_type function, 2015-07-31), but I couldn't find any comment on the dash in the commit message or the list discussion. It's used mostly for is_pseudoref(), which further requires that the name either end in "_HEAD" or be one of a specific set of "irregular" pseudorefs.

So I don't think we'd ever see a dash in the real world (you'd need to have "FOO-BAR_HEAD"). Let's tighten this up now so that the function is consistent with (and can be used in) other spots.

Signed-off-by: Jeff King <peff@peff.net>
---
 refs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/refs.c b/refs.c
index d3d21ecd43..b202dca904 100644
--- a/refs.c
+++ b/refs.c
@@ -169,7 +169,7 @@ static int is_pseudoref_syntax(const char *refname)
 	const char *c;
 
 	for (c = refname; *c; c++) {
-		if (!isupper(*c) && *c != '-' && *c != '_')
+		if (!isupper(*c) && *c != '_')
 			return 0;
 	}
 
-- 
2.45.0.rc1.416.gbe2a76c799
Message 1 of 1 in “refs: disallow dash in pseudoref syntax”
  1. 4/8 refs: disallow dash in pseudoref syntaxJeff 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.