Code

Merge branch 'rs/optim-text-wrap'
[git.git] / builtin-shortlog.c
index d96858f9adcf185e65d6028634bd981430a0f193..ecd2d45a00b1aacf9d3a19e2f934a14ca7e58c35 100644 (file)
@@ -139,8 +139,12 @@ static void read_from_stdin(struct shortlog *log)
 void shortlog_add_commit(struct shortlog *log, struct commit *commit)
 {
        const char *author = NULL, *buffer;
+       struct strbuf buf = STRBUF_INIT;
+       struct strbuf ufbuf = STRBUF_INIT;
+       struct pretty_print_context ctx = {0};
 
-       buffer = commit->buffer;
+       pretty_print_commit(CMIT_FMT_RAW, commit, &buf, &ctx);
+       buffer = buf.buf;
        while (*buffer && *buffer != '\n') {
                const char *eol = strchr(buffer, '\n');
 
@@ -157,20 +161,19 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
                die("Missing author: %s",
                    sha1_to_hex(commit->object.sha1));
        if (log->user_format) {
-               struct strbuf buf = STRBUF_INIT;
                struct pretty_print_context ctx = {0};
                ctx.abbrev = DEFAULT_ABBREV;
                ctx.subject = "";
                ctx.after_subject = "";
                ctx.date_mode = DATE_NORMAL;
-               pretty_print_commit(CMIT_FMT_USERFORMAT, commit, &buf, &ctx);
-               insert_one_record(log, author, buf.buf);
-               strbuf_release(&buf);
-               return;
-       }
-       if (*buffer)
+               pretty_print_commit(CMIT_FMT_USERFORMAT, commit, &ufbuf, &ctx);
+               buffer = ufbuf.buf;
+       } else if (*buffer) {
                buffer++;
+       }
        insert_one_record(log, author, !*buffer ? "<none>" : buffer);
+       strbuf_release(&ufbuf);
+       strbuf_release(&buf);
 }
 
 static void get_from_rev(struct rev_info *rev, struct shortlog *log)