list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* Make "git log --count" work like "git rev-list"
@ 2019-01-05 22:46 Linus Torvalds
  2019-01-09 17:21 ` Stefan Beller
  2019-01-09 19:54 ` Jeff King
  0 siblings, 2 replies; 7+ messages in thread
From: Linus Torvalds @ 2019-01-05 22:46 UTC (permalink / raw)
  To: Junio Hamano C; +Cc: Git List Mailing

[-- Attachment #1: Type: text/plain, Size: 1005 bytes --]

This is a ridiculous patch. And I understand entirely if nobody else
cares, because I don't think anybody else has ever even noticed.

It turns out that I still use "git rev-list" outside of some hard-core
scripting for one silly reason: the linux-next statistics are all
about non-merge commits, and so to do a rough comparison with
linux-next, I do

        git rev-list --count --no-merges v4.20..

to get an approximate idea of how much I've merged compared to what is
in linux-next.

(See also

for the graphical view of it all, even though it looks a bit odd right
now because of how linux-next wasn't being updated over the holidats
and right at the 4.19 release).

Anyway, I've occasionally thought to myself that I should just fix
"git log" to learn that too, so that I wouldn't have to type out "git
rev-list". Because "git log" does actually take the "--count"
argument, it just doesn't honor it.

This is that patch.


[-- Attachment #2: 0001-git-log-honor-the-count-argument.patch --]
[-- Type: text/x-patch, Size: 2570 bytes --]

From e3bc5387404bcefbd86081fbc82a93fc5c9efa99 Mon Sep 17 00:00:00 2001
From: Linus Torvalds <>
Date: Sat, 5 Jan 2019 14:39:41 -0800
Subject: [PATCH] git log: honor the '--count' argument

"git log" is really the human-facing useful command that long long ago
used to scripted around "git rev-list".

In fact, if you want to use the old scripting code, you can still
approximate "git log" with something like

   git rev-list --pretty HEAD | less

but you'd be silly to do that, since "git log" is clearly a much nicer
interface and is what people should use.

Except I find myself still occasionally using "git rev-list" simply
because "git log" doesn't do one odd little quirk: commit counting.

So if you want to count the number of non-merge commits since the last
kernel version, you'd have to do something like

   git rev-list --count --no-merges v4.20..

because while "git log" actually silently _accepts_ the "--count"
argument, it doesn't do anything about it.

This little patch copies the rev-list code for counting to "git log".

Signed-off-by: Linus Torvalds <>
 builtin/log.c | 11 +++++++++++
 log-tree.c    | 10 ++++++++++
 2 files changed, 21 insertions(+)

diff --git a/builtin/log.c b/builtin/log.c
index e8e51068bd..62bef62f8a 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -411,6 +411,17 @@ static int cmd_log_walk(struct rev_info *rev)
 	if (close_file)
+	if (rev->count) {
+		if (rev->left_right && rev->cherry_mark)
+			printf("%d\t%d\t%d\n", rev->count_left, rev->count_right, rev->count_same);
+		else if (rev->left_right)
+			printf("%d\t%d\n", rev->count_left, rev->count_right);
+		else if (rev->cherry_mark)
+			printf("%d\t%d\n", rev->count_left + rev->count_right, rev->count_same);
+		else
+			printf("%d\n", rev->count_left + rev->count_right);
+	}
 	if (rev->diffopt.output_format & DIFF_FORMAT_CHECKDIFF &&
 	    rev->diffopt.flags.check_failed) {
 		return 02;
diff --git a/log-tree.c b/log-tree.c
index 10680c139e..49ff485320 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -913,6 +913,16 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)
 	struct log_info log;
 	int shown, close_file = opt->diffopt.close_file;
+	if (opt->count) {
+		if (commit->object.flags & PATCHSAME)
+			opt->count_same++;
+		else if (commit->object.flags & SYMMETRIC_LEFT)
+			opt->count_left++;
+		else
+			opt->count_right++;
+		return 1;
+	}
 	log.commit = commit;
 	log.parent = NULL;
 	opt->loginfo = &log;

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-01-11 15:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-05 22:46 Make "git log --count" work like "git rev-list" Linus Torvalds
2019-01-09 17:21 ` Stefan Beller
2019-01-09 17:44   ` Linus Torvalds
2019-01-09 19:54 ` Jeff King
2019-01-09 20:14   ` Stefan Beller
2019-01-10 22:19   ` Junio C Hamano
2019-01-11 15:35     ` Jeff King list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ \
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
 note: .onion URLs require Tor:

code repositories for project(s) associated with this inbox:

AGPL code for this site: git clone