From 3c020bd528d5dc320b82bd787670edfe6695f097 Mon Sep 17 00:00:00 2001 From: Antoine Pelisse Date: Sat, 5 Jan 2013 22:26:38 +0100 Subject: Use split_ident_line to parse author and committer Currently blame.c::get_acline(), pretty.c::pp_user_info() and shortlog.c::insert_one_record() are parsing author name, email, time and tz themselves. Use ident.c::split_ident_line() for better code reuse. Signed-off-by: Antoine Pelisse Signed-off-by: Junio C Hamano --- builtin/shortlog.c | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) (limited to 'builtin/shortlog.c') diff --git a/builtin/shortlog.c b/builtin/shortlog.c index b316cf37ca..03c6cd7e86 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -40,40 +40,24 @@ static void insert_one_record(struct shortlog *log, char emailbuf[1024]; size_t len; const char *eol; - const char *boemail, *eoemail; struct strbuf subject = STRBUF_INIT; + struct ident_split ident; - boemail = strchr(author, '<'); - if (!boemail) - return; - eoemail = strchr(boemail, '>'); - if (!eoemail) + if (split_ident_line(&ident, author, strlen(author))) return; /* copy author name to namebuf, to support matching on both name and email */ - memcpy(namebuf, author, boemail - author); - len = boemail - author; - while (len > 0 && isspace(namebuf[len-1])) - len--; + len = ident.name_end - ident.name_begin; + memcpy(namebuf, ident.name_begin, len); namebuf[len] = 0; /* copy email name to emailbuf, to allow email replacement as well */ - memcpy(emailbuf, boemail+1, eoemail - boemail); - emailbuf[eoemail - boemail - 1] = 0; - - if (!map_user(&log->mailmap, emailbuf, sizeof(emailbuf), namebuf, sizeof(namebuf))) { - while (author < boemail && isspace(*author)) - author++; - for (len = 0; - len < sizeof(namebuf) - 1 && author + len < boemail; - len++) - namebuf[len] = author[len]; - while (0 < len && isspace(namebuf[len-1])) - len--; - namebuf[len] = '\0'; - } - else - len = strlen(namebuf); + len = ident.mail_end - ident.mail_begin; + memcpy(emailbuf, ident.mail_begin, len); + emailbuf[len] = 0; + + map_user(&log->mailmap, emailbuf, sizeof(emailbuf), namebuf, sizeof(namebuf)); + len = strlen(namebuf); if (log->email) { size_t room = sizeof(namebuf) - len - 1; -- cgit v1.2.1 From ea02ffa38571084007eb7c63f650d0011e44a3dd Mon Sep 17 00:00:00 2001 From: Antoine Pelisse Date: Sat, 5 Jan 2013 22:26:40 +0100 Subject: mailmap: simplify map_user() interface Simplify map_user(), mostly to avoid copies of string buffers. It also simplifies caller functions. map_user() directly receive pointers and length from the commit buffer as mail and name. If mapping of the user and mail can be done, the pointer is updated to a new location. Lengths are also updated if necessary. The caller of map_user() can then copy the new email and name if necessary. Signed-off-by: Antoine Pelisse Signed-off-by: Junio C Hamano --- builtin/shortlog.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'builtin/shortlog.c') diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 03c6cd7e86..1eeed0ffd8 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -36,36 +36,28 @@ static void insert_one_record(struct shortlog *log, const char *dot3 = log->common_repo_prefix; char *buffer, *p; struct string_list_item *item; - char namebuf[1024]; - char emailbuf[1024]; - size_t len; + const char *mailbuf, *namebuf; + size_t namelen, maillen; const char *eol; struct strbuf subject = STRBUF_INIT; + struct strbuf namemailbuf = STRBUF_INIT; struct ident_split ident; if (split_ident_line(&ident, author, strlen(author))) return; - /* copy author name to namebuf, to support matching on both name and email */ - len = ident.name_end - ident.name_begin; - memcpy(namebuf, ident.name_begin, len); - namebuf[len] = 0; + namebuf = ident.name_begin; + mailbuf = ident.mail_begin; + namelen = ident.name_end - ident.name_begin; + maillen = ident.mail_end - ident.mail_begin; - /* copy email name to emailbuf, to allow email replacement as well */ - len = ident.mail_end - ident.mail_begin; - memcpy(emailbuf, ident.mail_begin, len); - emailbuf[len] = 0; + map_user(&log->mailmap, &mailbuf, &maillen, &namebuf, &namelen); + strbuf_add(&namemailbuf, namebuf, namelen); - map_user(&log->mailmap, emailbuf, sizeof(emailbuf), namebuf, sizeof(namebuf)); - len = strlen(namebuf); + if (log->email) + strbuf_addf(&namemailbuf, " <%.*s>", (int)maillen, mailbuf); - if (log->email) { - size_t room = sizeof(namebuf) - len - 1; - int maillen = strlen(emailbuf); - snprintf(namebuf + len, room, " <%.*s>", maillen, emailbuf); - } - - item = string_list_insert(&log->list, namebuf); + item = string_list_insert(&log->list, namemailbuf.buf); if (item->util == NULL) item->util = xcalloc(1, sizeof(struct string_list)); -- cgit v1.2.1