# [PATCH 1/2] Use a common function to get the pretty name of refs

4 messages from 2009-03-09 to 2009-03-09. Participants: Daniel Barkalow, Johannes Schindelin.
Thread: https://gitlist.dev/t/18219

## Daniel Barkalow, 2009-03-09 01:06

Subject: [PATCH 1/2] Use a common function to get the pretty name of refs
Message-ID: <alpine.LNX.1.00.0903082104410.19665@iabervon.org>
URL: https://gitlist.dev/e/alpine.LNX.1.00.0903082104410.19665%40iabervon.org

```
The result should be consistent between fetch and push, so we ought to
use the same code in both cases, even though it's short.

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
---
 builtin-fetch.c     |    6 +-----
 builtin-send-pack.c |   10 ----------
 refs.c              |   10 ++++++++++
 refs.h              |    2 ++
 4 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/builtin-fetch.c b/builtin-fetch.c
index 1e4a3d9..f3bdeda 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -197,11 +197,7 @@ static int update_local_ref(struct ref *ref,
 	struct commit *current = NULL, *updated;
 	enum object_type type;
 	struct branch *current_branch = branch_get(NULL);
-	const char *pretty_ref = ref->name + (
-		!prefixcmp(ref->name, "refs/heads/") ? 11 :
-		!prefixcmp(ref->name, "refs/tags/") ? 10 :
-		!prefixcmp(ref->name, "refs/remotes/") ? 13 :
-		0);
+	const char *pretty_ref = prettify_ref(ref);
 
 	*display = 0;
 	type = sha1_object_info(ref->new_sha1, NULL);
diff --git a/builtin-send-pack.c b/builtin-send-pack.c
index 9072905..43b89ec 100644
--- a/builtin-send-pack.c
+++ b/builtin-send-pack.c
@@ -172,16 +172,6 @@ static void update_tracking_ref(struct remote *remote, struct ref *ref)
 	}
 }
 
-static const char *prettify_ref(const struct ref *ref)
-{
-	const char *name = ref->name;
-	return name + (
-		!prefixcmp(name, "refs/heads/") ? 11 :
-		!prefixcmp(name, "refs/tags/") ? 10 :
-		!prefixcmp(name, "refs/remotes/") ? 13 :
-		0);
-}
-
 #define SUMMARY_WIDTH (2 * DEFAULT_ABBREV + 3)
 
 static void print_ref_status(char flag, const char *summary, struct ref *to, struct ref *from, const char *msg)
diff --git a/refs.c b/refs.c
index b2a37e1..8f968b5 100644
--- a/refs.c
+++ b/refs.c
@@ -736,6 +736,16 @@ int check_ref_format(const char *ref)
 	}
 }
 
+const char *prettify_ref(const struct ref *ref)
+{
+	const char *name = ref->name;
+	return name + (
+		!prefixcmp(name, "refs/heads/") ? 11 :
+		!prefixcmp(name, "refs/tags/") ? 10 :
+		!prefixcmp(name, "refs/remotes/") ? 13 :
+		0);
+}
+
 const char *ref_rev_parse_rules[] = {
 	"%.*s",
 	"refs/%.*s",
diff --git a/refs.h b/refs.h
index 29bdcec..68c2d16 100644
--- a/refs.h
+++ b/refs.h
@@ -79,6 +79,8 @@ extern int for_each_reflog(each_ref_fn, void *);
 #define CHECK_REF_FORMAT_WILDCARD (-3)
 extern int check_ref_format(const char *target);
 
+extern const char *prettify_ref(const struct ref *ref);
+
 /** rename ref, return 0 on success **/
 extern int rename_ref(const char *oldref, const char *newref, const char *logmsg);
 
-- 
1.6.1.286.gd33a4.dirty

```

## Johannes Schindelin, 2009-03-09 09:38

Subject: Re: [PATCH 1/2] Use a common function to get the pretty name of refs
Message-ID: <alpine.DEB.1.00.0903091036420.10279@pacific.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0903091036420.10279%40pacific.mpi-cbg.de
In-Reply-To: <alpine.LNX.1.00.0903082104410.19665@iabervon.org>

```
Hi,

On Sun, 8 Mar 2009, Daniel Barkalow wrote:

> The result should be consistent between fetch and push, so we ought to 
> use the same code in both cases, even though it's short.

You might want to mention that we cannot use skip_prefix() here, as that 
function does not give us any clue if something was skipped at all, and we 
must _not_ skip multiple prefixes.

Ciao,
Dscho

```

## Daniel Barkalow, 2009-03-09 16:00

Subject: Re: [PATCH 1/2] Use a common function to get the pretty name of refs
Message-ID: <alpine.LNX.1.00.0903091159000.19665@iabervon.org>
URL: https://gitlist.dev/e/alpine.LNX.1.00.0903091159000.19665%40iabervon.org
In-Reply-To: <alpine.DEB.1.00.0903091036420.10279@pacific.mpi-cbg.de>

```
On Mon, 9 Mar 2009, Johannes Schindelin wrote:

> Hi,
> 
> On Sun, 8 Mar 2009, Daniel Barkalow wrote:
> 
> > The result should be consistent between fetch and push, so we ought to 
> > use the same code in both cases, even though it's short.
> 
> You might want to mention that we cannot use skip_prefix() here, as that 
> function does not give us any clue if something was skipped at all, and we 
> must _not_ skip multiple prefixes.

I didn't even know about the skip_prefix() function; I just moved code 
around.

	-Daniel
*This .sig left intentionally blank*

```

## Johannes Schindelin, 2009-03-09 16:11

Subject: Re: [PATCH 1/2] Use a common function to get the pretty name of refs
Message-ID: <alpine.DEB.1.00.0903091710020.6358@intel-tinevez-2-302>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0903091710020.6358%40intel-tinevez-2-302
In-Reply-To: <alpine.LNX.1.00.0903091159000.19665@iabervon.org>

```
Hi,

On Mon, 9 Mar 2009, Daniel Barkalow wrote:

> On Mon, 9 Mar 2009, Johannes Schindelin wrote:
> 
> > On Sun, 8 Mar 2009, Daniel Barkalow wrote:
> > 
> > > The result should be consistent between fetch and push, so we ought 
> > > to use the same code in both cases, even though it's short.
> > 
> > You might want to mention that we cannot use skip_prefix() here, as 
> > that function does not give us any clue if something was skipped at 
> > all, and we must _not_ skip multiple prefixes.
> 
> I didn't even know about the skip_prefix() function; I just moved code 
> around.

But I know the function.  And I had to look at the code to end the 
head-scratching.  Therefore I'd like the paragraph I wrote to be part of 
the commit message, to save other people from going bald.

Ciao,
Dscho

```
