show-branch: make the current branch and merge commits stand out.
This changes the character used to mark the commits that is on the branch from '+' to '*' for the current branch, to make it stand out. Also we show '-' for merge commits. When you have a handful branches with relatively long diversion, it is easier to see which one is the current branch this way. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 11, 2006 at 14:02 UTC
ebedc3195258a6382f58c8c6b54b21db922440af
5 files changed
+64
-49
Documentation/git-show-branch.txt
+8
-7
@@ -81,13 +81,14 @@ OUTPUT
81
------
82
Given N <references>, the first N lines are the one-line
83
description from their commit message. The branch head that is
84
-pointed at by $GIT_DIR/HEAD is prefixed with an asterisk '*'
85
-character while other heads are prefixed with a '!' character.
84
+pointed at by $GIT_DIR/HEAD is prefixed with an asterisk `*`
85
+character while other heads are prefixed with a `!` character.
86
87
Following these N lines, one-line log for each commit is
88
displayed, indented N places. If a commit is on the I-th
89
-branch, the I-th indentation character shows a '+' sign;
90
-otherwise it shows a space. Each commit shows a short name that
89
+branch, the I-th indentation character shows a `+` sign;
90
+otherwise it shows a space. Merge commits are denoted by
91
+a `-` sign. Each commit shows a short name that
92
can be used as an extended SHA1 to name that commit.
93
94
The following example shows three branches, "master", "fixes"
@@ -95,7 +96,7 @@ and "mhf":
96
97
------------------------------------------------
98
$ git show-branch master fixes mhf
98
-! [master] Add 'git show-branch'.
99
+* [master] Add 'git show-branch'.
100
! [fixes] Introduce "reset type" flag to "git reset"
101
! [mhf] Allow "+remote:local" refspec to cause --force when fetching.
102
---
@@ -109,13 +110,13 @@ $ git show-branch master fixes mhf
110
+ [mhf~6] Retire git-parse-remote.
111
+ [mhf~7] Multi-head fetch.
112
+ [mhf~8] Start adding the $GIT_DIR/remotes/ support.
112
-+++ [master] Add 'git show-branch'.
113
+*++ [master] Add 'git show-branch'.
114
------------------------------------------------
115
116
These three branches all forked from a common commit, [master],
117
whose commit message is "Add 'git show-branch'. "fixes" branch
118
adds one commit 'Introduce "reset type"'. "mhf" branch has many
118
-other commits.
119
+other commits. The current branch is "master".
120
121
122
EXAMPLE
Documentation/howto/revert-branch-rebase.txt
+12
-12
@@ -32,16 +32,16 @@ merge introduced 5 commits or so:
32
33
------------------------------------------------
34
$ git show-branch --more=4 master master^2 | head
35
-! [master] Merge refs/heads/portable from http://www.cs.berkeley....
35
+* [master] Merge refs/heads/portable from http://www.cs.berkeley....
36
! [master^2] Replace C99 array initializers with code.
37
--
38
-+ [master] Merge refs/heads/portable from http://www.cs.berkeley....
39
-++ [master^2] Replace C99 array initializers with code.
40
-++ [master^2~1] Replace unsetenv() and setenv() with older putenv().
41
-++ [master^2~2] Include sys/time.h in daemon.c.
42
-++ [master^2~3] Fix ?: statements.
43
-++ [master^2~4] Replace zero-length array decls with [].
44
-+ [master~1] tutorial note about git branch
38
+- [master] Merge refs/heads/portable from http://www.cs.berkeley....
39
+*+ [master^2] Replace C99 array initializers with code.
40
+*+ [master^2~1] Replace unsetenv() and setenv() with older putenv().
41
+*+ [master^2~2] Include sys/time.h in daemon.c.
42
+*+ [master^2~3] Fix ?: statements.
43
+*+ [master^2~4] Replace zero-length array decls with [].
44
+* [master~1] tutorial note about git branch
45
------------------------------------------------
46
47
The '--more=4' above means "after we reach the merge base of refs,
@@ -193,8 +193,8 @@ $ git show-branch --more=1 master pu rc
193
+ [pu~4] Document "git cherry-pick" and "git revert"
194
+ [pu~5] Remove git-apply-patch-script.
195
+ [pu~6] Redo "revert" using three-way merge machinery.
196
- + [rc] Merge refs/heads/master from .
197
-+++ [master] Revert "Replace zero-length array decls with []."
198
- + [rc~1] Merge refs/heads/master from .
199
-+++ [master~1] Merge refs/heads/portable from http://www.cs.berkeley....
196
+ - [rc] Merge refs/heads/master from .
197
+++* [master] Revert "Replace zero-length array decls with []."
198
+ - [rc~1] Merge refs/heads/master from .
199
+... [master~1] Merge refs/heads/portable from http://www.cs.berkeley....
200
------------------------------------------------
Documentation/tutorial.txt
+25
-24
@@ -968,8 +968,8 @@ $ git show-branch master mybranch
968
* [master] Merge work in mybranch
969
! [mybranch] Some work.
970
--
971
-+ [master] Merge work in mybranch
972
-++ [mybranch] Some work.
971
+- [master] Merge work in mybranch
972
+*+ [mybranch] Some work.
973
------------------------------------------------
974
975
The first two lines indicate that it is showing the two branches
@@ -979,7 +979,8 @@ top-of-the-tree commits, you are currently on `master` branch
979
the later output lines is used to show commits contained in the
980
`master` branch, and the second column for the `mybranch`
981
branch. Three commits are shown along with their log messages.
982
-All of them have plus `+` characters in the first column, which
982
+All of them have non blank characters in the first column (`*`
983
+shows an ordinary commit on the current branch, `.` is a merge commit), which
984
means they are now part of the `master` branch. Only the "Some
985
work" commit has the plus `+` character in the second column,
986
because `mybranch` has not been merged to incorporate these
@@ -1024,7 +1025,7 @@ $ git show-branch master mybranch
1025
! [master] Merge work in mybranch
1026
* [mybranch] Merge work in mybranch
1027
--
1027
-++ [master] Merge work in mybranch
1028
+-- [master] Merge work in mybranch
1029
------------------------------------------------
1030
1031
@@ -1199,9 +1200,9 @@ $ git show-branch --more=3 master mybranch
1200
! [master] Merge work in mybranch
1201
* [mybranch] Merge work in mybranch
1202
--
1202
-++ [master] Merge work in mybranch
1203
-++ [master^2] Some work.
1204
-++ [master^] Some fun.
1203
+-- [master] Merge work in mybranch
1204
++* [master^2] Some work.
1205
++* [master^] Some fun.
1206
------------
1207
1208
Remember, before running `git merge`, our `master` head was at
@@ -1223,8 +1224,8 @@ $ git show-branch
1224
! [mybranch] Some work.
1225
--
1226
+ [mybranch] Some work.
1226
-+ [master] Some fun.
1227
-++ [mybranch^] New day.
1227
+* [master] Some fun.
1228
+*+ [mybranch^] New day.
1229
------------
1230
1231
Now we are ready to experiment with the merge by hand.
@@ -1743,8 +1744,8 @@ $ git show-branch
1744
+ [diff-fix] Fix rename detection.
1745
+ [diff-fix~1] Better common substring algorithm.
1746
+ [commit-fix] Fix commit message normalization.
1746
- + [master] Release candidate #1
1747
-+++ [diff-fix~2] Pretty-print messages.
1747
+ * [master] Release candidate #1
1748
+++* [diff-fix~2] Pretty-print messages.
1749
------------
1750
1751
Both fixes are tested well, and at this point, you want to merge
@@ -1764,13 +1765,13 @@ $ git show-branch
1765
! [diff-fix] Fix rename detection.
1766
* [master] Merge fix in commit-fix
1767
---
1767
- + [master] Merge fix in commit-fix
1768
-+ + [commit-fix] Fix commit message normalization.
1769
- + [master~1] Merge fix in diff-fix
1770
- ++ [diff-fix] Fix rename detection.
1771
- ++ [diff-fix~1] Better common substring algorithm.
1772
- + [master~2] Release candidate #1
1773
-+++ [master~3] Pretty-print messages.
1768
+ - [master] Merge fix in commit-fix
1769
++ * [commit-fix] Fix commit message normalization.
1770
+ - [master~1] Merge fix in diff-fix
1771
+ +* [diff-fix] Fix rename detection.
1772
+ +* [diff-fix~1] Better common substring algorithm.
1773
+ * [master~2] Release candidate #1
1774
+++* [master~3] Pretty-print messages.
1775
------------
1776
1777
However, there is no particular reason to merge in one branch
@@ -1797,12 +1798,12 @@ $ git show-branch
1798
! [diff-fix] Fix rename detection.
1799
* [master] Octopus merge of branches 'diff-fix' and 'commit-fix'
1800
---
1800
- + [master] Octopus merge of branches 'diff-fix' and 'commit-fix'
1801
-+ + [commit-fix] Fix commit message normalization.
1802
- ++ [diff-fix] Fix rename detection.
1803
- ++ [diff-fix~1] Better common substring algorithm.
1804
- + [master~1] Release candidate #1
1805
-+++ [master~2] Pretty-print messages.
1801
+ - [master] Octopus merge of branches 'diff-fix' and 'commit-fix'
1802
++ * [commit-fix] Fix commit message normalization.
1803
+ +* [diff-fix] Fix rename detection.
1804
+ +* [diff-fix~1] Better common substring algorithm.
1805
+ * [master~1] Release candidate #1
1806
+++* [master~2] Pretty-print messages.
1807
------------
1808
1809
Note that you should not do Octopus because you can. An octopus
show-branch.c
+16
-3
@@ -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 head_at = -1;
549
550
git_config(git_show_branch_config);
551
setup_git_directory();
@@ -675,6 +676,8 @@ int main(int ac, char **av)
676
}
677
/* header lines never need name */
678
show_one_commit(rev[i], 1);
679
+ if (is_head)
680
+ head_at = i;
681
}
682
if (0 <= extra) {
683
for (i = 0; i < num_rev; i++)
@@ -703,9 +706,19 @@ int main(int ac, char **av)
706
shown_merge_point |= ((this_flag & all_revs) == all_revs);
707
708
if (1 < num_rev) {
706
- for (i = 0; i < num_rev; i++)
707
- putchar((this_flag & (1u << (i + REV_SHIFT)))
708
- ? '+' : ' ');
709
+ int is_merge = !!(commit->parents && commit->parents->next);
710
+ for (i = 0; i < num_rev; i++) {
711
+ int mark;
712
+ if (!(this_flag & (1u << (i + REV_SHIFT))))
713
+ mark = ' ';
714
+ else if (is_merge)
715
+ mark = '-';
716
+ else if (i == head_at)
717
+ mark = '*';
718
+ else
719
+ mark = '+';
720
+ putchar(mark);
721
+ }
722
putchar(' ');
723
}
724
show_one_commit(commit, no_name);
t/t1200-tutorial.sh
+3
-3
@@ -118,8 +118,8 @@ cat > show-branch.expect << EOF
118
* [master] Merged "mybranch" changes.
119
! [mybranch] Some work.
120
--
121
-+ [master] Merged "mybranch" changes.
122
-++ [mybranch] Some work.
121
+- [master] Merged "mybranch" changes.
122
+*+ [mybranch] Some work.
123
EOF
124
125
git show-branch --topo-order master mybranch > show-branch.output
@@ -142,7 +142,7 @@ cat > show-branch2.expect << EOF
142
! [master] Merged "mybranch" changes.
143
* [mybranch] Merged "mybranch" changes.
144
--
145
-++ [master] Merged "mybranch" changes.
145
+-- [master] Merged "mybranch" changes.
146
EOF
147
148
git show-branch --topo-order master mybranch > show-branch2.output