git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC/PATCH 1/2] for-each-ref: add new format 'refbasename'
@ 2008-08-29 10:37 SZEDER Gábor
  2008-08-29 10:37 ` [RFC/PATCH 2/2] bash: use for-each-ref " SZEDER Gábor
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: SZEDER Gábor @ 2008-08-29 10:37 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Shawn O. Pearce, SZEDER Gábor

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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-08-31  7:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-29 10:37 [RFC/PATCH 1/2] for-each-ref: add new format 'refbasename' SZEDER Gábor
2008-08-29 10:37 ` [RFC/PATCH 2/2] bash: use for-each-ref " SZEDER Gábor
2008-08-29 14:34 ` [RFC/PATCH 1/2] for-each-ref: add new " Shawn O. Pearce
2008-08-29 16:45   ` [RFC/PATCH 1/2 v2] " SZEDER Gábor
2008-08-29 18:21 ` [RFC/PATCH 1/2] " Bert Wesarg
2008-08-29 21:41   ` [PATCH] for-each-ref: new 'refshort' format Bert Wesarg
2008-08-31  4:31     ` Junio C Hamano
2008-08-31  7:11       ` Bert Wesarg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).