static int reopen_stdout(struct commit *commit, struct rev_info *rev) { struct strbuf filename = STRBUF_INIT; int suffix_len = strlen(fmt_patch_suffix) + 1; if (output_directory) { strbuf_addstr(&filename, output_directory); if (filename.len >= PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len) return error("name of output directory is too long"); if (filename.buf[filename.len - 1] != '/') strbuf_addch(&filename, '/'); } get_patch_filename(commit, rev->nr, fmt_patch_suffix, &filename); if (!DIFF_OPT_TST(&rev->diffopt, QUIET)) fprintf(realstdout, "%s\n", filename.buf + outdir_offset); if (freopen(filename.buf, "w", stdout) == NULL) return error("Cannot open patch file %s", filename.buf); strbuf_release(&filename); return 0; }
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) { const char *subject = NULL; const char *extra_headers = opt->extra_headers; const char *name = sha1_to_hex(commit->object.sha1); *need_8bit_cte_p = 0; /* unknown */ if (opt->total > 0) { static char buffer[64]; snprintf(buffer, sizeof(buffer), "Subject: [%s%s%0*d/%d] ", opt->subject_prefix, *opt->subject_prefix ? " " : "", digits_in_number(opt->total), opt->nr, opt->total); subject = buffer; } else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) { static char buffer[256]; snprintf(buffer, sizeof(buffer), "Subject: [%s] ", opt->subject_prefix); subject = buffer; } else { subject = "Subject: "; } printf("From %s Mon Sep 17 00:00:00 2001\n", name); graph_show_oneline(opt->graph); if (opt->message_id) { printf("Message-Id: <%s>\n", opt->message_id); graph_show_oneline(opt->graph); } if (opt->ref_message_ids && opt->ref_message_ids->nr > 0) { int i, n; n = opt->ref_message_ids->nr; printf("In-Reply-To: <%s>\n", opt->ref_message_ids->items[n-1].string); for (i = 0; i < n; i++) printf("%s<%s>\n", (i > 0 ? "\t" : "References: "), opt->ref_message_ids->items[i].string); graph_show_oneline(opt->graph); } if (opt->mime_boundary) { static char subject_buffer[1024]; static char buffer[1024]; struct strbuf filename = STRBUF_INIT; *need_8bit_cte_p = -1; /* NEVER */ snprintf(subject_buffer, sizeof(subject_buffer) - 1, "%s" "MIME-Version: 1.0\n" "Content-Type: multipart/mixed;" " boundary=\"%s%s\"\n" "\n" "This is a multi-part message in MIME " "format.\n" "--%s%s\n" "Content-Type: text/plain; " "charset=UTF-8; format=fixed\n" "Content-Transfer-Encoding: 8bit\n\n", extra_headers ? extra_headers : "", mime_boundary_leader, opt->mime_boundary, mime_boundary_leader, opt->mime_boundary); extra_headers = subject_buffer; get_patch_filename(opt->numbered_files ? NULL : commit, NULL, opt->nr, opt->patch_suffix, &filename); snprintf(buffer, sizeof(buffer) - 1, "\n--%s%s\n" "Content-Type: text/x-patch;" " name=\"%s\"\n" "Content-Transfer-Encoding: 8bit\n" "Content-Disposition: %s;" " filename=\"%s\"\n\n", mime_boundary_leader, opt->mime_boundary, filename.buf, opt->no_inline ? "attachment" : "inline", filename.buf); opt->diffopt.stat_sep = buffer; strbuf_release(&filename); } *subject_p = subject; *extra_headers_p = extra_headers; }