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

Make git-show-branch options similar to git-branch.

Branch has "-r" for remote branches and "-a" for local and remote. It seems logical to mirror that in show-branch. Also removes the dubiously useful "--tags" option (as part of changing the meaning for "--all"). Signed-off-by: Brian Gernhardt <benji@silverinsanity.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Brian Gernhardt committed Dec 22, 2006 at 08:58 UTC f49006b0c79bb74bc500a9a3a883e929fa0f803e
2 files changed +32 -18
Documentation/git-show-branch.txt
+6 -4
@@ -8,7 +8,7 @@ git-show-branch - Show branches and their commits
8 SYNOPSIS
9 --------
10 [verse]
11 -'git-show-branch' [--all] [--heads] [--tags] [--topo-order] [--current]
11 +'git-show-branch' [--all] [--remotes] [--topo-order] [--current]
12 [--more=<n> | --list | --independent | --merge-base]
13 [--no-name | --sha1-name] [--topics] [<rev> | <glob>]...
14
@@ -37,9 +37,11 @@ OPTIONS
37 branches under $GIT_DIR/refs/heads/topic, giving
38 `topic/*` would show all of them.
39
40 ---all --heads --tags::
41 - Show all refs under $GIT_DIR/refs, $GIT_DIR/refs/heads,
42 - and $GIT_DIR/refs/tags, respectively.
40 +-r|--remotes::
41 + Show the remote-tracking branches.
42 +
43 +-a|--all::
44 + Show both remote-tracking branches and local branches.
45
46 --current::
47 With this option, the command includes the current
builtin-show-branch.c
+26 -14
@@ -4,7 +4,7 @@
4 #include "builtin.h"
5
6 static const char show_branch_usage[] =
7 -"git-show-branch [--sparse] [--current] [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...] | --reflog[=n] <branch>";
7 +"git-show-branch [--sparse] [--current] [--all] [--remotes] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...] | --reflog[=n] <branch>";
8
9 static int default_num;
10 static int default_alloc;
@@ -383,6 +383,20 @@ static int append_head_ref(const char *refname, const unsigned char *sha1, int f
383 return append_ref(refname + ofs, sha1, flag, cb_data);
384 }
385
386 +static int append_remote_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
387 +{
388 + unsigned char tmp[20];
389 + int ofs = 13;
390 + if (strncmp(refname, "refs/remotes/", ofs))
391 + return 0;
392 + /* If both heads/foo and tags/foo exists, get_sha1 would
393 + * get confused.
394 + */
395 + if (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1))
396 + ofs = 5;
397 + return append_ref(refname + ofs, sha1, flag, cb_data);
398 +}
399 +
400 static int append_tag_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
401 {
402 if (strncmp(refname, "refs/tags/", 10))
@@ -423,16 +437,16 @@ static int append_matching_ref(const char *refname, const unsigned char *sha1, i
437 return append_ref(refname, sha1, flag, cb_data);
438 }
439
426 -static void snarf_refs(int head, int tag)
440 +static void snarf_refs(int head, int remotes)
441 {
442 if (head) {
443 int orig_cnt = ref_name_cnt;
444 for_each_ref(append_head_ref, NULL);
445 sort_ref_range(orig_cnt, ref_name_cnt);
446 }
433 - if (tag) {
447 + if (remotes) {
448 int orig_cnt = ref_name_cnt;
435 - for_each_ref(append_tag_ref, NULL);
449 + for_each_ref(append_remote_ref, NULL);
450 sort_ref_range(orig_cnt, ref_name_cnt);
451 }
452 }
@@ -554,7 +568,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
568 struct commit_list *list = NULL, *seen = NULL;
569 unsigned int rev_mask[MAX_REVS];
570 int num_rev, i, extra = 0;
557 - int all_heads = 0, all_tags = 0;
571 + int all_heads = 0, all_remotes = 0;
572 int all_mask, all_revs;
573 int lifo = 1;
574 char head[128];
@@ -586,12 +600,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
600 ac--; av++;
601 break;
602 }
589 - else if (!strcmp(arg, "--all"))
590 - all_heads = all_tags = 1;
591 - else if (!strcmp(arg, "--heads"))
592 - all_heads = 1;
593 - else if (!strcmp(arg, "--tags"))
594 - all_tags = 1;
603 + else if (!strcmp(arg, "--all") || !strcmp(arg, "-a"))
604 + all_heads = all_remotes = 1;
605 + else if (!strcmp(arg, "--remotes") || !strcmp(arg, "-r"))
606 + all_remotes = 1;
607 else if (!strcmp(arg, "--more"))
608 extra = 1;
609 else if (!strcmp(arg, "--list"))
@@ -636,11 +648,11 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
648 usage(show_branch_usage);
649
650 /* If nothing is specified, show all branches by default */
639 - if (ac + all_heads + all_tags == 0)
651 + if (ac + all_heads + all_remotes == 0)
652 all_heads = 1;
653
642 - if (all_heads + all_tags)
643 - snarf_refs(all_heads, all_tags);
654 + if (all_heads + all_remotes)
655 + snarf_refs(all_heads, all_remotes);
656 if (reflog) {
657 int reflen;
658 if (!ac)