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

[PATCH 1/2] shortlog: refactor insert_one_record()

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 15, 2009, 11:16 UTC
Message-ID
<alpine.DEB.1.00.0907151316130.4410@intel-tinevez-2-302>
In-Reply-To
<7v8wiqfj60.fsf@alter.siamese.dyndns.org>

This just splits insert_one_record() into one part which assumes that the key is an email ident of the form "A U Thor <author@example.com>" (that needs to respect .mailmap) and a second part which does not.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin-shortlog.c |   81 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 44 insertions(+), 37 deletions(-)
diff --git a/builtin-shortlog.c b/builtin-shortlog.c
index 6a3812e..a684422 100644
--- a/builtin-shortlog.c
+++ b/builtin-shortlog.c
@@ -32,19 +32,57 @@ static int compare_by_number(const void *a1, const void *a2)
 const char *format_subject(struct strbuf *sb, const char *msg,
 			   const char *line_separator);
 
-static void insert_one_record(struct shortlog *log,
-			      const char *author,
-			      const char *oneline)
+static void insert_one_record1(struct shortlog *log,
+		const char *name, const char *oneline)
 {
 	const char *dot3 = log->common_repo_prefix;
 	char *buffer, *p;
 	struct string_list_item *item;
+	const char *eol;
+	struct strbuf subject = STRBUF_INIT;
+
+	item = string_list_insert(name, &log->list);
+	if (item->util == NULL)
+		item->util = xcalloc(1, sizeof(struct string_list));
+
+	/* Skip any leading whitespace, including any blank lines. */
+	while (*oneline && isspace(*oneline))
+		oneline++;
+	eol = strchr(oneline, '\n');
+	if (!eol)
+		eol = oneline + strlen(oneline);
+	if (!prefixcmp(oneline, "[PATCH")) {
+		char *eob = strchr(oneline, ']');
+		if (eob && (!eol || eob < eol))
+			oneline = eob + 1;
+	}
+	while (*oneline && isspace(*oneline) && *oneline != '\n')
+		oneline++;
+	format_subject(&subject, oneline, " ");
+	buffer = strbuf_detach(&subject, NULL);
+
+	if (dot3) {
+		int dot3len = strlen(dot3);
+		if (dot3len > 5) {
+			while ((p = strstr(buffer, dot3)) != NULL) {
+				int taillen = strlen(p) - dot3len;
+				memcpy(p, "/.../", 5);
+				memmove(p + 5, p + dot3len, taillen + 1);
+			}
+		}
+	}
+
+	string_list_append(buffer, item->util);
+}
+
+static void insert_one_record(struct shortlog *log,
+			      const char *author,
+			      const char *oneline)
+{
 	char namebuf[1024];
 	char emailbuf[1024];
 	size_t len;
-	const char *eol;
 	const char *boemail, *eoemail;
-	struct strbuf subject = STRBUF_INIT;
 
 	boemail = strchr(author, '<');
 	if (!boemail)
@@ -84,38 +122,7 @@ static void insert_one_record(struct shortlog *log,
 		snprintf(namebuf + len, room, " <%.*s>", maillen, emailbuf);
 	}
 
-	item = string_list_insert(namebuf, &log->list);
-	if (item->util == NULL)
-		item->util = xcalloc(1, sizeof(struct string_list));
-
-	/* Skip any leading whitespace, including any blank lines. */
-	while (*oneline && isspace(*oneline))
-		oneline++;
-	eol = strchr(oneline, '\n');
-	if (!eol)
-		eol = oneline + strlen(oneline);
-	if (!prefixcmp(oneline, "[PATCH")) {
-		char *eob = strchr(oneline, ']');
-		if (eob && (!eol || eob < eol))
-			oneline = eob + 1;
-	}
-	while (*oneline && isspace(*oneline) && *oneline != '\n')
-		oneline++;
-	format_subject(&subject, oneline, " ");
-	buffer = strbuf_detach(&subject, NULL);
-
-	if (dot3) {
-		int dot3len = strlen(dot3);
-		if (dot3len > 5) {
-			while ((p = strstr(buffer, dot3)) != NULL) {
-				int taillen = strlen(p) - dot3len;
-				memcpy(p, "/.../", 5);
-				memmove(p + 5, p + dot3len, taillen + 1);
-			}
-		}
-	}
-
-	string_list_append(buffer, item->util);
+	insert_one_record1(log, namebuf, oneline);
 }
 
 static void read_from_stdin(struct shortlog *log)
-- 
1.6.3.284.g6fecc
Previous: Junio C HamanoNext: Johannes Schindelin
Message 3 of 8 in “More 'shortlog' statistics models?”
  1. Linus TorvaldsJul 15, 2009
  2. Junio C HamanoJul 15, 2009
  3. 1/2 shortlog: refactor insert_one_record()Johannes Schindelin, Jul 15, 2009
  4. 2/2 shortlog: add '--sort-key' and '--sort-key-regexp' optionsJohannes Schindelin, Jul 15, 2009
  5. Linus TorvaldsJul 15, 2009
  6. Michał KiedrowiczJul 15, 2009
  7. Jakub NarebskiJul 15, 2009
  8. Sverre RabbelierJul 15, 2009

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.