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

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 <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Jun 29, 2009 at 10:28 UTC b8e8db281cea9641253233a2bf8d01ab1f908abe
2 files changed +5
revision.c
+4
@@ -1077,6 +1077,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1077 revs->show_all = 1;
1078 } else if (!strcmp(arg, "--remove-empty")) {
1079 revs->remove_empty_trees = 1;
1080 + } else if (!strcmp(arg, "--merges")) {
1081 + revs->merges_only = 1;
1082 } else if (!strcmp(arg, "--no-merges")) {
1083 revs->no_merges = 1;
1084 } else if (!strcmp(arg, "--boundary")) {
@@ -1676,6 +1678,8 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
1678 return commit_ignore;
1679 if (revs->no_merges && commit->parents && commit->parents->next)
1680 return commit_ignore;
1681 + if (revs->merges_only && !(commit->parents && commit->parents->next))
1682 + return commit_ignore;
1683 if (!commit_match(commit, revs))
1684 return commit_ignore;
1685 if (revs->prune && revs->dense) {
revision.h
+1
@@ -36,6 +36,7 @@ struct rev_info {
36 unsigned int dense:1,
37 prune:1,
38 no_merges:1,
39 + merges_only:1,
40 no_walk:1,
41 show_all:1,
42 remove_empty_trees:1,