git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] refs.c: use skip_prefix() in prettify_refname()
@ 2017-03-23 15:50 SZEDER Gábor
  2017-03-23 19:18 ` René Scharfe
  0 siblings, 1 reply; 11+ messages in thread
From: SZEDER Gábor @ 2017-03-23 15:50 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, SZEDER Gábor

This eliminates three magic numbers.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
 refs.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/refs.c b/refs.c
index e7606716d..0272e332c 100644
--- a/refs.c
+++ b/refs.c
@@ -366,11 +366,11 @@ int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data)
 
 const char *prettify_refname(const char *name)
 {
-	return name + (
-		starts_with(name, "refs/heads/") ? 11 :
-		starts_with(name, "refs/tags/") ? 10 :
-		starts_with(name, "refs/remotes/") ? 13 :
-		0);
+	if (skip_prefix(name, "refs/heads/", &name) ||
+	    skip_prefix(name, "refs/tags/", &name) ||
+	    skip_prefix(name, "refs/remotes/", &name))
+		; /* nothing */
+	return name;
 }
 
 static const char *ref_rev_parse_rules[] = {
-- 
2.12.1.485.g1616aa492


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

end of thread, other threads:[~2017-03-23 20:06 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-23 15:50 [PATCH] refs.c: use skip_prefix() in prettify_refname() SZEDER Gábor
2017-03-23 19:18 ` René Scharfe
2017-03-23 19:23   ` Jeff King
2017-03-23 19:31     ` Stefan Beller
2017-03-23 19:33     ` Junio C Hamano
2017-03-23 19:36       ` René Scharfe
2017-03-23 19:40         ` Junio C Hamano
2017-03-23 19:39       ` Jeff King
2017-03-23 20:05         ` Junio C Hamano
2017-03-23 20:06         ` SZEDER Gábor
2017-03-23 20:06         ` René Scharfe

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).