# [PATCH 1/2] Add [-s|--hash] option to Linus' show-ref.

4 messages from 2006-09-17 to 2006-09-17. Participants: Christian Couder, Jakub Narebski.
Thread: https://gitlist.dev/t/5586

## Christian Couder, 2006-09-17 04:20

Subject: [PATCH 1/2] Add [-s|--hash] option to Linus' show-ref.
Message-ID: <20060917062024.c476e07d.chriscool@tuxfamily.org>
URL: https://gitlist.dev/e/20060917062024.c476e07d.chriscool%40tuxfamily.org

```
With this option only the sha1 hash of the ref should
be printed.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 builtin-show-ref.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/builtin-show-ref.c b/builtin-show-ref.c
index 161b236..577d934 100644
--- a/builtin-show-ref.c
+++ b/builtin-show-ref.c
@@ -3,9 +3,10 @@ #include "refs.h"
 #include "object.h"
 #include "tag.h"
 
-static const char show_ref_usage[] = "git show-ref [-q|--quiet] [--verify] [-h|--head] [-d|--deref] [--tags] [--heads] [--] [pattern*]";
+static const char show_ref_usage[] = "git show-ref [-q|--quiet] [--verify] [-h|--head] [-d|--deref] [-s|--hash] [--tags] [--heads] [--] [pattern*]";
 
-static int deref_tags = 0, show_head = 0, tags_only = 0, heads_only = 0, found_match = 0, verify = 0, quiet = 0;
+static int deref_tags = 0, show_head = 0, tags_only = 0, heads_only = 0,
+	found_match = 0, verify = 0, quiet = 0, hash_only = 0;
 static const char **pattern;
 
 static int show_ref(const char *refname, const unsigned char *sha1)
@@ -50,7 +51,10 @@ match:
 	}
 	if (quiet)
 		return 0;
-	printf("%s %s\n", sha1_to_hex(sha1), refname);
+	if (hash_only)
+		printf("%s\n", sha1_to_hex(sha1));
+	else
+		printf("%s %s\n", sha1_to_hex(sha1), refname);
 	if (deref_tags && obj->type == OBJ_TAG) {
 		obj = deref_tag(obj, refname, 0);
 		printf("%s %s^{}\n", sha1_to_hex(obj->sha1), refname);
@@ -86,6 +90,10 @@ int cmd_show_ref(int argc, const char **
 			deref_tags = 1;
 			continue;
 		}
+		if (!strcmp(arg, "-s") || !strcmp(arg, "--hash")) {
+			hash_only = 1;
+			continue;
+		}
 		if (!strcmp(arg, "--verify")) {
 			verify = 1;
 			continue;
-- 
1.4.2.1.gea00f-dirty

```

## Christian Couder, 2006-09-17 04:32

Subject: [PATCH 2/2] Use Linus' show ref in "git-branch.sh".
Message-ID: <20060917063224.0dc298ae.chriscool@tuxfamily.org>
URL: https://gitlist.dev/e/20060917063224.0dc298ae.chriscool%40tuxfamily.org
In-Reply-To: <20060917062024.c476e07d.chriscool@tuxfamily.org>

```
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 git-branch.sh |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/git-branch.sh b/git-branch.sh
index e0501ec..2600e9c 100755
--- a/git-branch.sh
+++ b/git-branch.sh
@@ -21,7 +21,7 @@ delete_branch () {
 	,,)
 	    die "What branch are you on anyway?" ;;
 	esac
-	branch=$(cat "$GIT_DIR/refs/heads/$branch_name") &&
+	branch=$(git-show-ref --verify --hash -- "refs/heads/$branch_name") &&
 	    branch=$(git-rev-parse --verify "$branch^0") ||
 		die "Seriously, what branch are you talking about?"
 	case "$option" in
@@ -112,7 +112,7 @@ rev=$(git-rev-parse --verify "$head") ||
 git-check-ref-format "heads/$branchname" ||
 	die "we do not like '$branchname' as a branch name."
 
-if [ -e "$GIT_DIR/refs/heads/$branchname" ]
+if git-show-ref --verify --quiet -- "refs/heads/$branchname"
 then
 	if test '' = "$force"
 	then
-- 
1.4.2.1.gea00f-dirty

```

## Jakub Narebski, 2006-09-17 07:15

Subject: Re: [PATCH 1/2] Add [-s|--hash] option to Linus' show-ref.
Message-ID: <eeiskc$l5n$1@sea.gmane.org>
URL: https://gitlist.dev/e/eeiskc%24l5n%241%40sea.gmane.org
In-Reply-To: <20060917062024.c476e07d.chriscool@tuxfamily.org>

```
Christian Couder wrote:

> With this option only the sha1 hash of the ref should
> be printed.

Could you please update manpage as well?

-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git

```

## Christian Couder, 2006-09-17 11:32

Subject: Re: [PATCH 1/2] Add [-s|--hash] option to Linus' show-ref.
Message-ID: <200609171332.01123.chriscool@tuxfamily.org>
URL: https://gitlist.dev/e/200609171332.01123.chriscool%40tuxfamily.org
In-Reply-To: <eeiskc$l5n$1@sea.gmane.org>

```
Jakub Narebski wrote:
> Christian Couder wrote:
> > With this option only the sha1 hash of the ref should
> > be printed.
>
> Could you please update manpage as well?

It seems to me that there is no man page for git-show-ref in next right now.

I could add one but I may not describe some part of it correctly.

Christian.

```
