Skip to content

Commit

Permalink
git log: add '--merges' flag to match '--no-merges'
Browse files Browse the repository at this point in the history
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 <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Jun 29, 2009
1 parent 4f2b15c commit b8e8db2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions revision.c
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->show_all = 1;
} else if (!strcmp(arg, "--remove-empty")) {
revs->remove_empty_trees = 1;
} else if (!strcmp(arg, "--merges")) {
revs->merges_only = 1;
} else if (!strcmp(arg, "--no-merges")) {
revs->no_merges = 1;
} else if (!strcmp(arg, "--boundary")) {
Expand Down Expand Up @@ -1676,6 +1678,8 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
return commit_ignore;
if (revs->no_merges && commit->parents && commit->parents->next)
return commit_ignore;
if (revs->merges_only && !(commit->parents && commit->parents->next))
return commit_ignore;
if (!commit_match(commit, revs))
return commit_ignore;
if (revs->prune && revs->dense) {
Expand Down
1 change: 1 addition & 0 deletions revision.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct rev_info {
unsigned int dense:1,
prune:1,
no_merges:1,
merges_only:1,
no_walk:1,
show_all:1,
remove_empty_trees:1,
Expand Down

0 comments on commit b8e8db2

Please sign in to comment.