{"thread":{"id":"19965","subject":"git log: add '--merges' flag to match '--no-merges'","startedAt":"2009-06-29T17:28:25Z","lastAt":"2009-06-29T18:15:18Z","messageCount":2,"participants":["Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"117170","messageId":"alpine.LFD.2.01.0906291015210.3605@localhost.localdomain","threadId":"19965","inReplyTo":null,"subject":"git log: add '--merges' flag to match '--no-merges'","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2009-06-29T17:28:25Z","receivedAt":"2009-06-29T17:28:25Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nI do various statistics on git, and one of the things I look at is merges, \nbecause they are often interesting events to count (\"how many merges vs \nhow much 'real development'\" kind of statistics). And you can do it with \nsome fairly straightforward scripting, ie\n\n\tgit rev-list --parents HEAD |\n\t\tgrep ' .* ' |\n\t\tgit diff-tree --always -s --pretty=oneline --stdin |\n\t\tless -S\n\nwill do it.\n\nBut I finally got irritated with the fact that we can skip merges with \n'--no-merges', but we can't do the trivial reverse operation.\n\nSo this just adds a '--merges' flag that _only_ shows merges. Now you can \ndo the above with just a\n\n\tgit log --merges --pretty=oneline\n\nwhich is a lot simpler. It also means that we automatically get a lot of \nstatistics for free, eg\n\n\tgit shortlog -ns --merges\n\ndoes exactly what you'd want it to do.\n\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n---\n revision.c |    4 ++++\n revision.h |    1 +\n 2 files changed, 5 insertions(+), 0 deletions(-)\n\ndiff --git a/revision.c b/revision.c\nindex bf58448..a31434b 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1077,6 +1077,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg\n \t\trevs->show_all = 1;\n \t} else if (!strcmp(arg, \"--remove-empty\")) {\n \t\trevs->remove_empty_trees = 1;\n+\t} else if (!strcmp(arg, \"--merges\")) {\n+\t\trevs->merges_only = 1;\n \t} else if (!strcmp(arg, \"--no-merges\")) {\n \t\trevs->no_merges = 1;\n \t} else if (!strcmp(arg, \"--boundary\")) {\n@@ -1676,6 +1678,8 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)\n \t\treturn commit_ignore;\n \tif (revs->no_merges && commit->parents && commit->parents->next)\n \t\treturn commit_ignore;\n+\tif (revs->merges_only && !(commit->parents && commit->parents->next))\n+\t\treturn commit_ignore;\n \tif (!commit_match(commit, revs))\n \t\treturn commit_ignore;\n \tif (revs->prune && revs->dense) {\ndiff --git a/revision.h b/revision.h\nindex 227164c..fb74492 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -36,6 +36,7 @@ struct rev_info {\n \tunsigned int\tdense:1,\n \t\t\tprune:1,\n \t\t\tno_merges:1,\n+\t\t\tmerges_only:1,\n \t\t\tno_walk:1,\n \t\t\tshow_all:1,\n \t\t\tremove_empty_trees:1,\n"},{"id":"117171","messageId":"alpine.LFD.2.01.0906291112520.3605@localhost.localdomain","threadId":"19965","inReplyTo":"alpine.LFD.2.01.0906291015210.3605@localhost.localdomain","subject":"Re: git log: add '--merges' flag to match '--no-merges'","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2009-06-29T18:15:18Z","receivedAt":"2009-06-29T18:15:18Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Mon, 29 Jun 2009, Linus Torvalds wrote:\n> \n> So this just adds a '--merges' flag that _only_ shows merges.\n\nSide note: if somebody wants to make this flag be called \"--merges-only\", \nand then adds a \"--merges\" flag that clears both the no_merges and \nmerges_only flag, I wouldn't complain. That _might_ be useful to override \ndefault behaviour (say, if some alias/command were to default to not \nshowing merges, then adding \"--merges\" would make it show all commits).\n\nDunno. I don't personally much care, but I thought I'd mention it as an \nalternative approach to this issue.\n\n\t\tLinus\n"}]}