Skip to content

Commit

Permalink
Add [-s|--hash] option to Linus' show-ref.
Browse files Browse the repository at this point in the history
With this option only the sha1 hash of the ref should
be printed.

Signed-off-by: Christian Couder <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
chriscool authored and Junio C Hamano committed Sep 17, 2006
1 parent 305e22c commit c40abef
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions builtin-show-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
#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)
Expand Down Expand Up @@ -50,7 +51,10 @@ static int show_ref(const char *refname, const unsigned char *sha1)
}
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);
Expand Down Expand Up @@ -86,6 +90,10 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
deref_tags = 1;
continue;
}
if (!strcmp(arg, "-s") || !strcmp(arg, "--hash")) {
hash_only = 1;
continue;
}
if (!strcmp(arg, "--verify")) {
verify = 1;
continue;
Expand Down

0 comments on commit c40abef

Please sign in to comment.