Code

Merge branch 'mn/maint-iconv-autoconf'
[git.git] / log-tree.c
index aee9995531903808ec6b8a47f1ac9887267391a7..59d63eb67e57ab55bdca6493fa8b28b0c870ff21 100644 (file)
@@ -25,6 +25,7 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
        struct object *obj = parse_object(sha1);
        if (!obj)
                return 0;
+       refname = prettify_refname(refname);
        add_name_decoration("", refname, obj);
        while (obj->type == OBJ_TAG) {
                obj = ((struct tag *)obj)->tagged;
@@ -187,27 +188,23 @@ void get_patch_filename(struct commit *commit, int nr, const char *suffix,
 
        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);
-               /*
-                * Replace characters at the end with the suffix if the
-                * filename is too long
-                */
-               if (buf->len + suffix_len > FORMAT_PATCH_NAME_MAX + start_len)
-                       strbuf_splice(buf,
-                               start_len + FORMAT_PATCH_NAME_MAX - suffix_len,
-                               suffix_len, suffix, suffix_len);
-               else
-                       strbuf_addstr(buf, suffix);
+               if (max_len < buf->len)
+                       strbuf_setlen(buf, max_len);
+               strbuf_addstr(buf, suffix);
        }
 }
 
-void log_write_email_headers(struct rev_info *opt, const char *name,
+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) {
@@ -246,6 +243,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"
@@ -264,18 +262,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;
@@ -355,8 +356,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);