From d421cb6163363741fcaaf33a99650195eabde494 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 15 Jul 2009 12:52:20 +0200 Subject: [PATCH] shortlog: refactor insert_one_record() This just splits insert_one_record() into one part which assumes that the key is an email ident of the form "A U Thor " (that needs to respect .mailmap) and a second part which does not. Signed-off-by: Johannes Schindelin --- builtin-shortlog.c | 81 +++++++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/builtin-shortlog.c b/builtin-shortlog.c index 6a3812ee18..a684422667 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) -- 2.11.4.GIT