[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