diff mbox series

[6/7] refs: exempt pseudoref patterns from prefixing

Message ID 20231019193911.1669705-7-andy.koppe@gmail.com (mailing list archive)
State New, archived
Headers show
Series decorate: add color.decorate.symbols config option | expand

Commit Message

Andy Koppe Oct. 19, 2023, 7:39 p.m. UTC
In normalize_glob_ref(), don't prefix patterns that look like pseudorefs
with "refs/". This is in preparation for showing pseudorefs such as
ORIG_HEAD in log decorations, as they are not matched as intended in
decoration filters otherwise.

Use existing function is_pseudoref_syntax() to do this, declaring it in
refs.h to make it available to normalize_glob_ref() and anything else
that might need it. As the function returns true for HEAD as well, the
special case for that is no longer needed.

Signed-off-by: Andy Koppe <andy.koppe@gmail.com>
---
 refs.c | 8 ++------
 refs.h | 2 ++
 2 files changed, 4 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/refs.c b/refs.c
index b03cccab909..492b9f7d4e5 100644
--- a/refs.c
+++ b/refs.c
@@ -564,12 +564,8 @@  void normalize_glob_ref(struct string_list_item *item, const char *prefix,
 	if (prefix)
 		strbuf_addstr(&normalized_pattern, prefix);
 	else if (!starts_with(pattern, "refs/") &&
-		   strcmp(pattern, "HEAD"))
+		 !is_pseudoref_syntax(pattern))
 		strbuf_addstr(&normalized_pattern, "refs/");
-	/*
-	 * NEEDSWORK: Special case other symrefs such as REBASE_HEAD,
-	 * MERGE_HEAD, etc.
-	 */
 
 	strbuf_addstr(&normalized_pattern, pattern);
 	strbuf_strip_suffix(&normalized_pattern, "/");
@@ -840,7 +836,7 @@  int is_per_worktree_ref(const char *refname)
 	       starts_with(refname, "refs/rewritten/");
 }
 
-static int is_pseudoref_syntax(const char *refname)
+int is_pseudoref_syntax(const char *refname)
 {
 	const char *c;
 
diff --git a/refs.h b/refs.h
index 82aecd37a2b..b77691d787a 100644
--- a/refs.h
+++ b/refs.h
@@ -123,6 +123,8 @@  int should_autocreate_reflog(const char *refname);
 
 int is_branch(const char *refname);
 
+int is_pseudoref_syntax(const char *refname);
+
 int refs_init_db(struct strbuf *err);
 
 /*