Skip to content

Commit b8e8db2

Browse files
torvaldsgitster
authored andcommitted
git log: add '--merges' flag to match '--no-merges'
I do various statistics on git, and one of the things I look at is merges, because they are often interesting events to count ("how many merges vs how much 'real development'" kind of statistics). And you can do it with some fairly straightforward scripting, ie git rev-list --parents HEAD | grep ' .* ' | git diff-tree --always -s --pretty=oneline --stdin | less -S will do it. But I finally got irritated with the fact that we can skip merges with '--no-merges', but we can't do the trivial reverse operation. So this just adds a '--merges' flag that _only_ shows merges. Now you can do the above with just a git log --merges --pretty=oneline which is a lot simpler. It also means that we automatically get a lot of statistics for free, eg git shortlog -ns --merges does exactly what you'd want it to do. Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4f2b15c commit b8e8db2

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

revision.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
10771077
revs->show_all = 1;
10781078
} else if (!strcmp(arg, "--remove-empty")) {
10791079
revs->remove_empty_trees = 1;
1080+
} else if (!strcmp(arg, "--merges")) {
1081+
revs->merges_only = 1;
10801082
} else if (!strcmp(arg, "--no-merges")) {
10811083
revs->no_merges = 1;
10821084
} else if (!strcmp(arg, "--boundary")) {
@@ -1676,6 +1678,8 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
16761678
return commit_ignore;
16771679
if (revs->no_merges && commit->parents && commit->parents->next)
16781680
return commit_ignore;
1681+
if (revs->merges_only && !(commit->parents && commit->parents->next))
1682+
return commit_ignore;
16791683
if (!commit_match(commit, revs))
16801684
return commit_ignore;
16811685
if (revs->prune && revs->dense) {

revision.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct rev_info {
3636
unsigned int dense:1,
3737
prune:1,
3838
no_merges:1,
39+
merges_only:1,
3940
no_walk:1,
4041
show_all:1,
4142
remove_empty_trees:1,

0 commit comments

Comments
 (0)