show-branch: --current includes the current branch.
With this, the command includes the current branch to the list of revs to be shown when it is not given on the command line. This is handy to use in the configuration file like this: [showbranch] default = --current default = heads/* ; primary branches, not topics under ; subdirectories Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 11, 2006 at 00:16 UTC
1aa68d67358be1ee20da57b0c3bd1f9863fe41a4
2 files changed
+46
-16
Documentation/git-show-branch.txt
+11
-2
@@ -7,7 +7,10 @@ git-show-branch - Show branches and their commits.
7
8
SYNOPSIS
9
--------
10
-'git-show-branch [--all] [--heads] [--tags] [--topo-order] [--more=<n> | --list | --independent | --merge-base] [--no-name | --sha1-name] [<rev> | <glob>]...'
10
+[verse]
11
+git-show-branch [--all] [--heads] [--tags] [--topo-order] [--current]
12
+ [--more=<n> | --list | --independent | --merge-base]
13
+ [--no-name | --sha1-name] [<rev> | <glob>]...
14
15
DESCRIPTION
16
-----------
@@ -38,6 +41,11 @@ OPTIONS
41
Show all refs under $GIT_DIR/refs, $GIT_DIR/refs/heads,
42
and $GIT_DIR/refs/tags, respectively.
43
44
+--current::
45
+ With this option, the command includes the current
46
+ branch to the list of revs to be shown when it is not
47
+ given on the command line.
48
+
49
--topo-order::
50
By default, the branches and their commits are shown in
51
reverse chronological order. This option makes them
@@ -134,7 +142,8 @@ it, having the following in the configuration file may help:
142
------------
143
144
With this,`git show-branch` without extra parameters would show
137
-only the primary branches.
145
+only the primary branches. In addition, if you happen to be on
146
+your topic branch, it is shown as well.
147
148
149
show-branch.c
+35
-14
@@ -5,7 +5,7 @@
5
#include "refs.h"
6
7
static const char show_branch_usage[] =
8
-"git-show-branch [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [<refs>...]";
8
+"git-show-branch [--current] [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [<refs>...]";
9
10
static int default_num = 0;
11
static int default_alloc = 0;
@@ -435,12 +435,12 @@ static void snarf_refs(int head, int tag)
435
}
436
}
437
438
-static int rev_is_head(char *head_path, int headlen,
439
- char *name,
438
+static int rev_is_head(char *head_path, int headlen, char *name,
439
unsigned char *head_sha1, unsigned char *sha1)
440
{
441
int namelen;
443
- if ((!head_path[0]) || memcmp(head_sha1, sha1, 20))
442
+ if ((!head_path[0]) ||
443
+ (head_sha1 && sha1 && memcmp(head_sha1, sha1, 20)))
444
return 0;
445
namelen = strlen(name);
446
if ((headlen < namelen) ||
@@ -545,6 +545,7 @@ int main(int ac, char **av)
545
int sha1_name = 0;
546
int shown_merge_point = 0;
547
int topo_order = 0;
548
+ int with_current_branch = 0;
549
int head_at = -1;
550
551
git_config(git_show_branch_config);
@@ -574,6 +575,8 @@ int main(int ac, char **av)
575
extra = -1;
576
else if (!strcmp(arg, "--no-name"))
577
no_name = 1;
578
+ else if (!strcmp(arg, "--current"))
579
+ with_current_branch = 1;
580
else if (!strcmp(arg, "--sha1-name"))
581
sha1_name = 1;
582
else if (!strncmp(arg, "--more=", 7))
@@ -605,6 +608,34 @@ int main(int ac, char **av)
608
ac--; av++;
609
}
610
611
+ head_path_p = resolve_ref(git_path("HEAD"), head_sha1, 1);
612
+ if (head_path_p) {
613
+ head_path_len = strlen(head_path_p);
614
+ memcpy(head_path, head_path_p, head_path_len + 1);
615
+ }
616
+ else {
617
+ head_path_len = 0;
618
+ head_path[0] = 0;
619
+ }
620
+
621
+ if (with_current_branch && head_path_p) {
622
+ int has_head = 0;
623
+ for (i = 0; !has_head && i < ref_name_cnt; i++) {
624
+ /* We are only interested in adding the branch
625
+ * HEAD points at.
626
+ */
627
+ if (rev_is_head(head_path,
628
+ head_path_len,
629
+ ref_name[i],
630
+ head_sha1, NULL))
631
+ has_head++;
632
+ }
633
+ if (!has_head) {
634
+ int pfxlen = strlen(git_path("refs/heads/"));
635
+ append_one_rev(head_path + pfxlen);
636
+ }
637
+ }
638
+
639
if (!ref_name_cnt) {
640
fprintf(stderr, "No revs to be shown.\n");
641
exit(0);
@@ -640,16 +671,6 @@ int main(int ac, char **av)
671
if (0 <= extra)
672
join_revs(&list, &seen, num_rev, extra);
673
643
- head_path_p = resolve_ref(git_path("HEAD"), head_sha1, 1);
644
- if (head_path_p) {
645
- head_path_len = strlen(head_path_p);
646
- memcpy(head_path, head_path_p, head_path_len + 1);
647
- }
648
- else {
649
- head_path_len = 0;
650
- head_path[0] = 0;
651
- }
652
-
674
if (merge_base)
675
return show_merge_base(seen, num_rev);
676