diff options
| author | Junio C Hamano <gitster@pobox.com> | 2009-04-06 00:42:23 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2009-04-06 00:42:23 -0700 |
| commit | 87d2062b3984af5347519c38877b99bce06e6e8d (patch) | |
| tree | 888152f9e778342f6fa0fc71c7f601fd702916eb /log-tree.c | |
| parent | a6e5ef7d9cc34199fb6618e1fbb57f3615d002f6 (diff) | |
| parent | 871d21d42e0f782b7cb111beec8c252e9aa627ff (diff) | |
| download | git-87d2062b3984af5347519c38877b99bce06e6e8d.tar.gz | |
Merge branch 'sb/format-patch-patchname'
* sb/format-patch-patchname:
format_sanitized_subject: Don't trim past initial length of strbuf
log-tree: fix patch filename computation in "git format-patch"
format-patch: --numbered-files and --stdout aren't mutually exclusive
format-patch: --attach/inline uses filename instead of SHA1
format-patch: move get_patch_filename() into log-tree
format-patch: pass a commit to reopen_stdout()
format-patch: construct patch filename in one function
pretty.c: add %f format specifier to format_commit_message()
Diffstat (limited to 'log-tree.c')
| -rw-r--r-- | log-tree.c | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/log-tree.c b/log-tree.c index 9565c184db..5bd29e6994 100644 --- a/log-tree.c +++ b/log-tree.c @@ -179,13 +179,31 @@ static int has_non_ascii(const char *s) return 0; } -void log_write_email_headers(struct rev_info *opt, const char *name, +void get_patch_filename(struct commit *commit, int nr, const char *suffix, + struct strbuf *buf) +{ + int suffix_len = strlen(suffix) + 1; + int start_len = buf->len; + + strbuf_addf(buf, commit ? "%04d-" : "%d", nr); + if (commit) { + int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len; + + format_commit_message(commit, "%f", buf, DATE_NORMAL); + if (max_len < buf->len) + strbuf_setlen(buf, max_len); + strbuf_addstr(buf, suffix); + } +} + +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) { @@ -224,6 +242,7 @@ void log_write_email_headers(struct rev_info *opt, const char *name, 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" @@ -242,18 +261,21 @@ void log_write_email_headers(struct rev_info *opt, const char *name, mime_boundary_leader, opt->mime_boundary); extra_headers = subject_buffer; + get_patch_filename(opt->numbered_files ? NULL : commit, opt->nr, + opt->patch_suffix, &filename); snprintf(buffer, sizeof(buffer) - 1, "\n--%s%s\n" "Content-Type: text/x-patch;" - " name=\"%s.diff\"\n" + " name=\"%s\"\n" "Content-Transfer-Encoding: 8bit\n" "Content-Disposition: %s;" - " filename=\"%s.diff\"\n\n", + " filename=\"%s\"\n\n", mime_boundary_leader, opt->mime_boundary, - name, + filename.buf, opt->no_inline ? "attachment" : "inline", - name); + filename.buf); opt->diffopt.stat_sep = buffer; + strbuf_release(&filename); } *subject_p = subject; *extra_headers_p = extra_headers; @@ -333,8 +355,7 @@ void show_log(struct rev_info *opt) */ if (opt->commit_format == CMIT_FMT_EMAIL) { - log_write_email_headers(opt, sha1_to_hex(commit->object.sha1), - &subject, &extra_headers, + log_write_email_headers(opt, commit, &subject, &extra_headers, &need_8bit_cte); } else if (opt->commit_format != CMIT_FMT_USERFORMAT) { fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout); |
