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

[PATCH] --count feature for git shortlog

From
Lawrence Siebert <lawrencesiebert@gmail.com>
Date
Jun 29, 2015, 01:22 UTC
Message-ID
<1435540922-12208-2-git-send-email-lawrencesiebert@gmail.com>
In-Reply-To
<1435540922-12208-1-git-send-email-lawrencesiebert@gmail.com>
--summary is per author --count counts all
Signed-off-by: Lawrence Siebert <lawrencesiebert@gmail.com>
---
 builtin/shortlog.c | 14 +++++++++-----
 shortlog.h         |  1 +
 2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index c0bab6a..4b79dc8 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -226,8 +226,10 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
 	int nongit = !startup_info->have_repository;
 
 	static const struct option options[] = {
+		 OPT_BOOL('N', "count", &log.show_count,
+			N_("display the total number of commits for all authors")),
 		OPT_BOOL('n', "numbered", &log.sort_by_number,
-			 N_("sort output according to the number of commits per author")),
+			 N_("Sort output according to the number of commits per author")),
 		OPT_BOOL('s', "summary", &log.summary,
 			 N_("Suppress commit descriptions, only provides commit count")),
 		OPT_BOOL('e', "email", &log.email,
@@ -290,8 +292,8 @@ static void add_wrapped_shortlog_msg(struct strbuf *sb, const char *s,
 void shortlog_output(struct shortlog *log)
 {
 	int i, j;
+  unsigned int count = 0;
 	struct strbuf sb = STRBUF_INIT;
-
 	if (log->sort_by_number)
 		qsort(log->list.items, log->list.nr, sizeof(struct string_list_item),
 			compare_by_number);
@@ -300,7 +302,9 @@ void shortlog_output(struct shortlog *log)
 
 		if (log->summary) {
 			printf("%6d\t%s\n", onelines->nr, log->list.items[i].string);
-		} else {
+		} else if (log->show_count) {
+        count += onelines->nr;
+    } else {
 			printf("%s (%d):\n", log->list.items[i].string, onelines->nr);
 			for (j = onelines->nr - 1; j >= 0; j--) {
 				const char *msg = onelines->items[j].string;
@@ -315,13 +319,13 @@ void shortlog_output(struct shortlog *log)
 			}
 			putchar('\n');
 		}
-
 		onelines->strdup_strings = 1;
 		string_list_clear(onelines, 0);
 		free(onelines);
 		log->list.items[i].util = NULL;
 	}
-
+  if (log->show_count) 
+    printf("%d\n", count);
 	strbuf_release(&sb);
 	log->list.strdup_strings = 1;
 	string_list_clear(&log->list, 1);
diff --git a/shortlog.h b/shortlog.h
index de4f86f..57797b7 100644
--- a/shortlog.h
+++ b/shortlog.h
@@ -8,6 +8,7 @@ struct shortlog {
 	int summary;
 	int wrap_lines;
 	int sort_by_number;
+	int show_count;
 	int wrap;
 	int in1;
 	int in2;
-- 
1.9.1
Previous: Lawrence SiebertNext: Lawrence Siebert
Message 2 of 15 in “--count feature for git shortlog”
  1. --count feature for git shortlogLawrence Siebert, Jun 29, 2015
  2. --count feature for git shortlogLawrence Siebert, Jun 29, 2015
  3. --count feature for git shortlogLawrence Siebert, Jun 29, 2015
  4. Junio C HamanoJun 29, 2015
  5. Lawrence SiebertJun 29, 2015
  6. Junio C HamanoJun 29, 2015
  7. Lawrence SiebertJun 29, 2015
  8. Johannes SchindelinJun 30, 2015
  9. John KeepingJun 30, 2015
  10. Junio C HamanoJul 3, 2015
  11. Lawrence SiebertJul 3, 2015
  12. Jakub NarębskiJul 21, 2015
  13. Lawrence SiebertJul 1, 2015
  14. Jeff KingJul 1, 2015
  15. Junio C HamanoJul 1, 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.