@matheusbsbs / matheus-bagliano / commits / c40abef89f
Fork 0

Add [-s|--hash] option to Linus' show-ref.

With this option only the sha1 hash of the ref should be printed. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Christian Couder committed Sep 17, 2006 at 06:20 UTC c40abef89f746ef7b9b7815b12b740e2f22905c8
1 file changed +11 -3
builtin-show-ref.c
+11 -3
@@ -3,9 +3,10 @@
3 #include "object.h"
4 #include "tag.h"
5
6 -static const char show_ref_usage[] = "git show-ref [-q|--quiet] [--verify] [-h|--head] [-d|--deref] [--tags] [--heads] [--] [pattern*]";
6 +static const char show_ref_usage[] = "git show-ref [-q|--quiet] [--verify] [-h|--head] [-d|--deref] [-s|--hash] [--tags] [--heads] [--] [pattern*]";
7
8 -static int deref_tags = 0, show_head = 0, tags_only = 0, heads_only = 0, found_match = 0, verify = 0, quiet = 0;
8 +static int deref_tags = 0, show_head = 0, tags_only = 0, heads_only = 0,
9 + found_match = 0, verify = 0, quiet = 0, hash_only = 0;
10 static const char **pattern;
11
12 static int show_ref(const char *refname, const unsigned char *sha1)
@@ -50,7 +51,10 @@ match:
51 }
52 if (quiet)
53 return 0;
53 - printf("%s %s\n", sha1_to_hex(sha1), refname);
54 + if (hash_only)
55 + printf("%s\n", sha1_to_hex(sha1));
56 + else
57 + printf("%s %s\n", sha1_to_hex(sha1), refname);
58 if (deref_tags && obj->type == OBJ_TAG) {
59 obj = deref_tag(obj, refname, 0);
60 printf("%s %s^{}\n", sha1_to_hex(obj->sha1), refname);
@@ -86,6 +90,10 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
90 deref_tags = 1;
91 continue;
92 }
93 + if (!strcmp(arg, "-s") || !strcmp(arg, "--hash")) {
94 + hash_only = 1;
95 + continue;
96 + }
97 if (!strcmp(arg, "--verify")) {
98 verify = 1;
99 continue;