convert some get_pathspec() calls to parse_pathspec()
[gitweb.git] / builtin / shortlog.c
index 03c6cd7e868ff7451a719586534105a9b6c0fc40..1434f8fee487751abe069250c611bdaed2fa5857 100644 (file)
@@ -10,9 +10,7 @@
 #include "parse-options.h"
 
 static char const * const shortlog_usage[] = {
-       N_("git shortlog [-n] [-s] [-e] [-w] [rev-opts] [--] [<commit-id>... ]"),
-       "",
-       N_("[rev-opts] are documented in git-rev-list(1)"),
+       N_("git shortlog [<options>] [<revision range>] [[--] [<path>...]]"),
        NULL
 };
 
@@ -36,36 +34,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));
 
@@ -147,6 +137,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
                ctx.subject = "";
                ctx.after_subject = "";
                ctx.date_mode = DATE_NORMAL;
+               ctx.output_encoding = get_log_output_encoding();
                pretty_print_commit(&ctx, commit, &ufbuf);
                buffer = ufbuf.buf;
        } else if (*buffer) {
@@ -290,9 +281,8 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
 static void add_wrapped_shortlog_msg(struct strbuf *sb, const char *s,
                                     const struct shortlog *log)
 {
-       int col = strbuf_add_wrapped_text(sb, s, log->in1, log->in2, log->wrap);
-       if (col != log->wrap)
-               strbuf_addch(sb, '\n');
+       strbuf_add_wrapped_text(sb, s, log->in1, log->in2, log->wrap);
+       strbuf_addch(sb, '\n');
 }
 
 void shortlog_output(struct shortlog *log)