@@ -2028,27 +2028,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
strbuf_addch(&buf, '\n');
}
- if (extra_to.nr)
- strbuf_addstr(&buf, "To: ");
- for (i = 0; i < extra_to.nr; i++) {
- if (i)
- strbuf_addstr(&buf, " ");
- strbuf_addstr(&buf, extra_to.items[i].string);
- if (i + 1 < extra_to.nr)
- strbuf_addch(&buf, ',');
- strbuf_addch(&buf, '\n');
- }
-
- if (extra_cc.nr)
- strbuf_addstr(&buf, "Cc: ");
- for (i = 0; i < extra_cc.nr; i++) {
- if (i)
- strbuf_addstr(&buf, " ");
- strbuf_addstr(&buf, extra_cc.items[i].string);
- if (i + 1 < extra_cc.nr)
- strbuf_addch(&buf, ',');
- strbuf_addch(&buf, '\n');
- }
+ recipients_to_header_buf("To", &buf, &extra_to);
+ recipients_to_header_buf("Cc", &buf, &extra_cc);
rev.extra_headers = to_free = strbuf_detach(&buf, NULL);
@@ -426,6 +426,21 @@ void fmt_output_email_subject(struct strbuf *sb, struct rev_info *opt)
}
}
+void recipients_to_header_buf(const char *hdr, struct strbuf *buf,
+ const struct string_list *recipients)
+{
+ for (int i = 0; i < recipients->nr; i++) {
+ if (!i)
+ strbuf_addf(buf, "%s: ", hdr);
+ else
+ strbuf_addstr(buf, " ");
+ strbuf_addstr(buf, recipients->items[i].string);
+ if (i + 1 < recipients->nr)
+ strbuf_addch(buf, ',');
+ strbuf_addch(buf, '\n');
+ }
+}
+
void log_write_email_headers(struct rev_info *opt, struct commit *commit,
const char **extra_headers_p,
int *need_8bit_cte_p,
@@ -25,6 +25,8 @@ void format_decorations_extended(struct strbuf *sb, const struct commit *commit,
#define format_decorations(strbuf, commit, color) \
format_decorations_extended((strbuf), (commit), (color), " (", ", ", ")")
void show_decorations(struct rev_info *opt, struct commit *commit);
+void recipients_to_header_buf(const char *hdr, struct strbuf *buf,
+ const struct string_list *recipients);
void log_write_email_headers(struct rev_info *opt, struct commit *commit,
const char **extra_headers_p,
int *need_8bit_cte_p,
The To and Cc headers are handled identically (the only difference is the header name tag), so we might as well reuse the same code for both instead of duplicating it. Signed-off-by: Zev Weiss <zev@bewilderbeest.net> --- builtin/log.c | 23 ++--------------------- log-tree.c | 15 +++++++++++++++ log-tree.h | 2 ++ 3 files changed, 19 insertions(+), 21 deletions(-)