@matheusbsbs / matheus-bagliano / commits / 7e3fe904ef
Fork 0

Teach show-branch how to show ref-log data.

Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Dec 14, 2006 at 15:58 UTC 7e3fe904ef9b1ce9cb9a3ddc03d85508bcc48df2
1 file changed +30 -5
builtin-show-branch.c
+30 -5
@@ -6,7 +6,7 @@
6 #include "builtin.h"
7
8 static const char show_branch_usage[] =
9 -"git-show-branch [--sparse] [--current] [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...]";
9 +"git-show-branch [--sparse] [--current] [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...] | --reflog[=n] <branch>";
10
11 static int default_num;
12 static int default_alloc;
@@ -17,6 +17,8 @@ static const char **default_arg;
17 #define REV_SHIFT 2
18 #define MAX_REVS (FLAG_BITS - REV_SHIFT) /* should not exceed bits_per_int - REV_SHIFT */
19
20 +#define DEFAULT_REFLOG 4
21 +
22 static struct commit *interesting(struct commit_list *list)
23 {
24 while (list) {
@@ -570,6 +572,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
572 int head_at = -1;
573 int topics = 0;
574 int dense = 1;
575 + int reflog = 0;
576
577 git_config(git_show_branch_config);
578
@@ -615,6 +618,15 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
618 dense = 0;
619 else if (!strcmp(arg, "--date-order"))
620 lifo = 0;
621 + else if (!strcmp(arg, "--reflog")) {
622 + reflog = DEFAULT_REFLOG;
623 + }
624 + else if (!strncmp(arg, "--reflog=", 9)) {
625 + char *end;
626 + reflog = strtoul(arg + 9, &end, 10);
627 + if (*end != '\0')
628 + die("unrecognized reflog count '%s'", arg + 9);
629 + }
630 else
631 usage(show_branch_usage);
632 ac--; av++;
@@ -622,7 +634,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
634 ac--; av++;
635
636 /* Only one of these is allowed */
625 - if (1 < independent + merge_base + (extra != 0))
637 + if (1 < independent + merge_base + (extra != 0) + (!!reflog))
638 usage(show_branch_usage);
639
640 /* If nothing is specified, show all branches by default */
@@ -631,9 +643,22 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
643
644 if (all_heads + all_tags)
645 snarf_refs(all_heads, all_tags);
634 - while (0 < ac) {
635 - append_one_rev(*av);
636 - ac--; av++;
646 + if (reflog) {
647 + int reflen;
648 + if (!ac)
649 + die("--reflog option needs one branch name");
650 + reflen = strlen(*av);
651 + for (i = 0; i < reflog; i++) {
652 + char *name = xmalloc(reflen + 20);
653 + sprintf(name, "%s@{%d}", *av, i);
654 + append_one_rev(name);
655 + }
656 + }
657 + else {
658 + while (0 < ac) {
659 + append_one_rev(*av);
660 + ac--; av++;
661 + }
662 }
663
664 head_p = resolve_ref("HEAD", head_sha1, 1, NULL);