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

[RFC/PATCH 1/2] for-each-ref: add new format 'refbasename'

From
SZEDER Gábor <szeder@ira.uka.de>
Date
Aug 29, 2008, 10:37 UTC
Message-ID
<0329f1ab2642e1dab701b5fc6517bfb1b4ea2d46.1220004755.git.szeder@ira.uka.de>

fot-each-ref's refname format outputs each ref in its full format, e.g. 'refs/heads/foo' and 'refs/tags/bar'. However, there are tools that need only the last part of the refname, e.g. only 'foo' and 'bar'. Such a tool is git's bash completion script, which spends considerable amount of time removing the unneeded parts from for-each-ref's output.

Therefore, we introduce a new for-each-ref format called 'refbasename', which strips everything before and including the second '/' in the ref's name from the output.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
  I assumed that refs always look like 'refs/{heads,tags,whatever}/foo',
  hence this patch breaks if a ref might look like 'refs/foo' or just
  'foo'.  But can I really rely on that?
 builtin-for-each-ref.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index 21e92bb..1993ff4 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -66,6 +66,7 @@ static struct {
 	{ "subject" },
 	{ "body" },
 	{ "contents" },
+	{ "refbasename" },
 };
 
 /*
@@ -577,6 +578,10 @@ static void populate_value(struct refinfo *ref)
 			char *s = xmalloc(len + 4);
 			sprintf(s, "%s^{}", ref->refname);
 			v->s = s;
+		} else if (!strcmp(name, "refbasename")) {
+			char * p = strchr(ref->refname, '/');
+			p = strchr(p+1, '/');
+			v->s = p+1;
 		}
 	}
 
-- 
1.6.0.1.133.g10dd.dirty
Next: SZEDER Gábor
Message 1 of 8 in “for-each-ref: add new format 'refbasename'”
  1. 1/2 for-each-ref: add new format 'refbasename'SZEDER Gábor, Aug 29, 2008
  2. 2/2 bash: use for-each-ref format 'refbasename'SZEDER Gábor, Aug 29, 2008
  3. Shawn O. PearceAug 29, 2008
  4. 1/2 for-each-ref: add new format 'refbasename'SZEDER Gábor, Aug 29, 2008
  5. Bert WesargAug 29, 2008
  6. for-each-ref: new 'refshort' formatBert Wesarg, Aug 29, 2008
  7. Junio C HamanoAug 31, 2008
  8. Bert WesargAug 31, 2008

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.