git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/4] log: add --count option to git log

From
Lawrence Siebert <lawrencesiebert@gmail.com>
Date
Jul 2, 2015, 23:50 UTC
Message-ID
<1435881011-13879-3-git-send-email-lawrencesiebert@gmail.com>
In-Reply-To
<1435881011-13879-1-git-send-email-lawrencesiebert@gmail.com>

adds --count from git rev-list to git log, without --use-bitmap-index for the moment.

Signed-off-by: Lawrence Siebert <lawrencesiebert@gmail.com>
---
 builtin/log.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
diff --git a/builtin/log.c b/builtin/log.c
index 8781049..4aaff3a 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -25,6 +25,7 @@
 #include "version.h"
 #include "mailmap.h"
 #include "gpg-interface.h"
+#include "list-objects.h"
 
 /* Set a default date-time format for git log ("log.date" config variable) */
 static const char *default_date_mode = NULL;
@@ -317,12 +318,40 @@ static void finish_early_output(struct rev_info *rev)
 	show_early_header(rev, "done", n);
 }
 
+static void show_object(struct object *obj,
+			const struct name_path *path, const char *component,
+			void *cb_data)
+{
+	return;
+}
+
+static void show_commit(struct commit *commit, void *data)
+{
+	struct rev_info *revs = (struct rev_info *)data;
+	if (commit->object.flags & PATCHSAME)
+		revs->count_same++;
+	else if (commit->object.flags & SYMMETRIC_LEFT)
+		revs->count_left++;
+	else
+		revs->count_right++;
+	if (commit->parents) {
+		free_commit_list(commit->parents);
+		commit->parents = NULL;
+	}
+	free_commit_buffer(commit);
+}
+
 static int cmd_log_walk(struct rev_info *rev)
 {
 	struct commit *commit;
 	int saved_nrl = 0;
 	int saved_dcctc = 0;
 
+	if (rev->count) {
+		prepare_revision_walk(rev);
+		traverse_commit_list(rev, show_commit, show_object, rev);
+		get_commit_count(rev);
+	}
 	if (rev->early_output)
 		setup_early_output(rev);
 
-- 
1.9.1
Previous: Matthieu MoyNext: Matthieu Moy
Message 6 of 17 in “git log --count”
  1. 0/4 git log --countLawrence Siebert, Jul 2, 2015
  2. 1/4 list-object: add get_commit_count functionLawrence Siebert, Jul 2, 2015
  3. Matthieu MoyJul 3, 2015
  4. Lawrence SiebertJul 3, 2015
  5. Matthieu MoyJul 3, 2015
  6. 2/4 log: add --count option to git logLawrence Siebert, Jul 2, 2015
  7. Matthieu MoyJul 3, 2015
  8. Lawrence SiebertJul 3, 2015
  9. Matthieu MoyJul 3, 2015
  10. 3/4 log --count: added testLawrence Siebert, Jul 2, 2015
  11. Matthieu MoyJul 3, 2015
  12. Lawrence SiebertJul 3, 2015
  13. Matthieu MoyJul 3, 2015
  14. Matthieu MoyJul 3, 2015
  15. Junio C HamanoJul 4, 2015
  16. Junio C HamanoJul 4, 2015
  17. 4/4 git-log: update man documentation for --countLawrence Siebert, Jul 2, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.