]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pretty: use fmt_output_email_subject()
authorRené Scharfe <l.s.r@web.de>
Wed, 1 Mar 2017 11:37:07 +0000 (12:37 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Mar 2017 23:09:17 +0000 (15:09 -0800)
Add the email-style subject prefix (e.g. "Subject: [PATCH] ") directly
when it's needed instead of letting log_write_email_headers() prepare
it in a static buffer in advance.  This simplifies storage ownership and
code flow.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/log.c
builtin/shortlog.c
commit.h
log-tree.c
log-tree.h
pretty.c

index 55d20cc2d88ab03d96f0476b222be3b2f6832ed9..281af8c1ecb04c7be05d9a17a1d5f3bd43420c85 100644 (file)
@@ -989,8 +989,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
            open_next_file(NULL, rev->numbered_files ? NULL : "cover-letter", rev, quiet))
                return;
 
-       log_write_email_headers(rev, head, &pp.subject, &pp.after_subject,
-                               &need_8bit_cte);
+       log_write_email_headers(rev, head, &pp.after_subject, &need_8bit_cte);
 
        for (i = 0; !need_8bit_cte && i < nr; i++) {
                const char *buf = get_commit_buffer(list[i], NULL);
@@ -1005,6 +1004,8 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
        msg = body;
        pp.fmt = CMIT_FMT_EMAIL;
        pp.date_mode.type = DATE_RFC2822;
+       pp.rev = rev;
+       pp.print_email_subject = 1;
        pp_user_info(&pp, NULL, &sb, committer, encoding);
        pp_title_line(&pp, &msg, &sb, encoding, need_8bit_cte);
        pp_remainder(&pp, &msg, &sb, 0);
index ba0e1154a9f0b95f60e5bcb6cdb716bf0f6ef366..21402ae8b735f1ae90b1283dd45b05ad775d7fa1 100644 (file)
@@ -143,7 +143,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
 
        ctx.fmt = CMIT_FMT_USERFORMAT;
        ctx.abbrev = log->abbrev;
-       ctx.subject = "";
+       ctx.print_email_subject = 1;
        ctx.after_subject = "";
        ctx.date_mode.type = DATE_NORMAL;
        ctx.output_encoding = get_log_output_encoding();
index afd14f318c0c4d18f3a03781d3229f2fdc0f64c6..e818aff07e684d34c65dcee7c8a58b24c4bfb079 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -142,21 +142,24 @@ static inline int cmit_fmt_is_mail(enum cmit_fmt fmt)
        return (fmt == CMIT_FMT_EMAIL || fmt == CMIT_FMT_MBOXRD);
 }
 
+struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
+
 struct pretty_print_context {
        /*
         * Callers should tweak these to change the behavior of pp_* functions.
         */
        enum cmit_fmt fmt;
        int abbrev;
-       const char *subject;
        const char *after_subject;
        int preserve_subject;
        struct date_mode date_mode;
        unsigned date_mode_explicit:1;
+       int print_email_subject;
        int expand_tabs_in_log;
        int need_8bit_cte;
        char *notes_message;
        struct reflog_walk_info *reflog_info;
+       struct rev_info *rev;
        const char *output_encoding;
        struct string_list *mailmap;
        int color;
@@ -175,7 +178,6 @@ struct userformat_want {
 };
 
 extern int has_non_ascii(const char *text);
-struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
 extern const char *logmsg_reencode(const struct commit *commit,
                                   char **commit_encoding,
                                   const char *output_encoding);
index 44febb75abf7948145bfe669553a05a800e503f0..4618dd04ca1b6bd2bf53481f39851fb4e5d02336 100644 (file)
@@ -349,11 +349,9 @@ void fmt_output_email_subject(struct strbuf *sb, struct rev_info *opt)
 }
 
 void log_write_email_headers(struct rev_info *opt, struct commit *commit,
-                            const char **subject_p,
                             const char **extra_headers_p,
                             int *need_8bit_cte_p)
 {
-       static struct strbuf subject = STRBUF_INIT;
        const char *extra_headers = opt->extra_headers;
        const char *name = oid_to_hex(opt->zero_commit ?
                                      &null_oid : &commit->object.oid);
@@ -415,9 +413,6 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
                opt->diffopt.stat_sep = buffer;
                strbuf_release(&filename);
        }
-       strbuf_reset(&subject);
-       fmt_output_email_subject(&subject, opt);
-       *subject_p = subject.buf;
        *extra_headers_p = extra_headers;
 }
 
@@ -602,8 +597,10 @@ void show_log(struct rev_info *opt)
         */
 
        if (cmit_fmt_is_mail(opt->commit_format)) {
-               log_write_email_headers(opt, commit, &ctx.subject, &extra_headers,
+               log_write_email_headers(opt, commit, &extra_headers,
                                        &ctx.need_8bit_cte);
+               ctx.rev = opt;
+               ctx.print_email_subject = 1;
        } else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
                fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), opt->diffopt.file);
                if (opt->commit_format != CMIT_FMT_ONELINE)
index dd75dd7770ec249bab97b2e57cb79b6e9542d928..48f11fb740ddf670cac819cb733cbc736cc30d0e 100644 (file)
@@ -22,7 +22,6 @@ void format_decorations_extended(struct strbuf *sb, const struct commit *commit,
                             format_decorations_extended((strbuf), (commit), (color), " (", ", ", ")")
 void show_decorations(struct rev_info *opt, struct commit *commit);
 void log_write_email_headers(struct rev_info *opt, struct commit *commit,
-                            const char **subject_p,
                             const char **extra_headers_p,
                             int *need_8bit_cte_p);
 void load_ref_decorations(int flags);
index 37b2c3b1f9954d79bf799a3af979e8c337698b79..faeb3d97f6d81d99f5add92d33133e96ea4dcdcc 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -1590,8 +1590,9 @@ void pp_title_line(struct pretty_print_context *pp,
                                pp->preserve_subject ? "\n" : " ");
 
        strbuf_grow(sb, title.len + 1024);
-       if (pp->subject) {
-               strbuf_addstr(sb, pp->subject);
+       if (pp->print_email_subject) {
+               if (pp->rev)
+                       fmt_output_email_subject(sb, pp->rev);
                if (needs_rfc2047_encoding(title.buf, title.len, RFC2047_SUBJECT))
                        add_rfc2047(sb, title.buf, title.len,
                                                encoding, RFC2047_SUBJECT);
@@ -1801,7 +1802,7 @@ void pretty_print_commit(struct pretty_print_context *pp,
        }
 
        pp_header(pp, encoding, commit, &msg, sb);
-       if (pp->fmt != CMIT_FMT_ONELINE && !pp->subject) {
+       if (pp->fmt != CMIT_FMT_ONELINE && !pp->print_email_subject) {
                strbuf_addch(sb, '\n');
        }