Merge branch 'bc/format-patch-cover-no-attach'
authorJunio C Hamano <gitster@pobox.com>
Wed, 23 May 2018 05:38:21 +0000 (14:38 +0900)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 May 2018 05:38:21 +0000 (14:38 +0900)
"git format-patch --cover --attach" created a broken MIME multipart
message for the cover letter, which has been fixed by keeping the
cover letter as plain text file.

* bc/format-patch-cover-no-attach:
format-patch: make cover letters always text/plain

1  2 
builtin/log.c
log-tree.c
diff --combined builtin/log.c
index 75f7ff044178f58b9302d3e9f767986195307d94,dc7f5f4642152a141e43786fe4655256be75fccb..a15599f4f031d6d6b23f68f83dbc935f36d41ae3
@@@ -518,7 -518,7 +518,7 @@@ static int show_tag_object(const struc
  {
        unsigned long size;
        enum object_type type;
 -      char *buf = read_sha1_file(oid->hash, &type, &size);
 +      char *buf = read_object_file(oid, &type, &size);
        int offset = 0;
  
        if (!buf)
        return 0;
  }
  
 -static int show_tree_object(const unsigned char *sha1,
 +static int show_tree_object(const struct object_id *oid,
                struct strbuf *base,
                const char *pathname, unsigned mode, int stage, void *context)
  {
@@@ -1019,7 -1019,7 +1019,7 @@@ static void make_cover_letter(struct re
            open_next_file(NULL, rev->numbered_files ? NULL : "cover-letter", rev, quiet))
                return;
  
-       log_write_email_headers(rev, head, &pp.after_subject, &need_8bit_cte);
+       log_write_email_headers(rev, head, &pp.after_subject, &need_8bit_cte, 0);
  
        for (i = 0; !need_8bit_cte && i < nr; i++) {
                const char *buf = get_commit_buffer(list[i], NULL);
  
        diff_setup_done(&opts);
  
 -      diff_tree_oid(&origin->tree->object.oid,
 -                    &head->tree->object.oid,
 +      diff_tree_oid(get_commit_tree_oid(origin),
 +                    get_commit_tree_oid(head),
                      "", &opts);
        diffcore_std(&opts);
        diff_flush(&opts);
@@@ -1873,12 -1873,12 +1873,12 @@@ static void print_commit(char sign, str
  {
        if (!verbose) {
                fprintf(file, "%c %s\n", sign,
 -                     find_unique_abbrev(commit->object.oid.hash, abbrev));
 +                     find_unique_abbrev(&commit->object.oid, abbrev));
        } else {
                struct strbuf buf = STRBUF_INIT;
                pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf);
                fprintf(file, "%c %s %s\n", sign,
 -                     find_unique_abbrev(commit->object.oid.hash, abbrev),
 +                     find_unique_abbrev(&commit->object.oid, abbrev),
                       buf.buf);
                strbuf_release(&buf);
        }
diff --combined log-tree.c
index 66329d089d8521b8335cfc373f127b16c4f860ed,b00a56f57ee0c91728a5daf218e33da9922527e7..724bae0de25b5b6e22dfecee233ff999be880dd5
@@@ -177,7 -177,7 +177,7 @@@ static void show_parents(struct commit 
        struct commit_list *p;
        for (p = commit->parents; p ; p = p->next) {
                struct commit *parent = p->item;
 -              fprintf(file, " %s", find_unique_abbrev(parent->object.oid.hash, abbrev));
 +              fprintf(file, " %s", find_unique_abbrev(&parent->object.oid, abbrev));
        }
  }
  
@@@ -185,7 -185,7 +185,7 @@@ static void show_children(struct rev_in
  {
        struct commit_list *p = lookup_decoration(&opt->children, &commit->object);
        for ( ; p; p = p->next) {
 -              fprintf(opt->diffopt.file, " %s", find_unique_abbrev(p->item->object.oid.hash, abbrev));
 +              fprintf(opt->diffopt.file, " %s", find_unique_abbrev(&p->item->object.oid, abbrev));
        }
  }
  
@@@ -362,7 -362,8 +362,8 @@@ void fmt_output_email_subject(struct st
  
  void log_write_email_headers(struct rev_info *opt, struct commit *commit,
                             const char **extra_headers_p,
-                            int *need_8bit_cte_p)
+                            int *need_8bit_cte_p,
+                            int maybe_multipart)
  {
        const char *extra_headers = opt->extra_headers;
        const char *name = oid_to_hex(opt->zero_commit ?
                               opt->ref_message_ids->items[i].string);
                graph_show_oneline(opt->graph);
        }
-       if (opt->mime_boundary) {
+       if (opt->mime_boundary && maybe_multipart) {
                static char subject_buffer[1024];
                static char buffer[1024];
                struct strbuf filename =  STRBUF_INIT;
@@@ -488,9 -489,9 +489,9 @@@ static int is_common_merge(const struc
                && !commit->parents->next->next);
  }
  
 -static void show_one_mergetag(struct commit *commit,
 -                            struct commit_extra_header *extra,
 -                            void *data)
 +static int show_one_mergetag(struct commit *commit,
 +                           struct commit_extra_header *extra,
 +                           void *data)
  {
        struct rev_info *opt = (struct rev_info *)data;
        struct object_id oid;
        hash_object_file(extra->value, extra->len, type_name(OBJ_TAG), &oid);
        tag = lookup_tag(&oid);
        if (!tag)
 -              return; /* error message already given */
 +              return -1; /* error message already given */
  
        strbuf_init(&verify_message, 256);
        if (parse_tag_buffer(tag, extra->value, extra->len))
  
        show_sig_lines(opt, status, verify_message.buf);
        strbuf_release(&verify_message);
 +      return 0;
  }
  
 -static void show_mergetag(struct rev_info *opt, struct commit *commit)
 +static int show_mergetag(struct rev_info *opt, struct commit *commit)
  {
 -      for_each_mergetag(show_one_mergetag, commit, opt);
 +      return for_each_mergetag(show_one_mergetag, commit, opt);
  }
  
  void show_log(struct rev_info *opt)
  
                if (!opt->graph)
                        put_revision_mark(opt, commit);
 -              fputs(find_unique_abbrev(commit->object.oid.hash, abbrev_commit), opt->diffopt.file);
 +              fputs(find_unique_abbrev(&commit->object.oid, abbrev_commit), opt->diffopt.file);
                if (opt->print_parents)
                        show_parents(commit, abbrev_commit, opt->diffopt.file);
                if (opt->children.name)
  
        if (cmit_fmt_is_mail(opt->commit_format)) {
                log_write_email_headers(opt, commit, &extra_headers,
-                                       &ctx.need_8bit_cte);
+                                       &ctx.need_8bit_cte, 1);
                ctx.rev = opt;
                ctx.print_email_subject = 1;
        } else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
  
                if (!opt->graph)
                        put_revision_mark(opt, commit);
 -              fputs(find_unique_abbrev(commit->object.oid.hash, abbrev_commit),
 +              fputs(find_unique_abbrev(&commit->object.oid,
 +                                       abbrev_commit),
                      opt->diffopt.file);
                if (opt->print_parents)
                        show_parents(commit, abbrev_commit, opt->diffopt.file);
                        show_children(opt, commit, abbrev_commit);
                if (parent)
                        fprintf(opt->diffopt.file, " (from %s)",
 -                             find_unique_abbrev(parent->object.oid.hash,
 -                                                abbrev_commit));
 +                             find_unique_abbrev(&parent->object.oid, abbrev_commit));
                fputs(diff_get_color_opt(&opt->diffopt, DIFF_RESET), opt->diffopt.file);
                show_decorations(opt, commit);
                if (opt->commit_format == CMIT_FMT_ONELINE) {
@@@ -807,7 -807,7 +808,7 @@@ static int log_tree_diff(struct rev_inf
                return 0;
  
        parse_commit_or_die(commit);
 -      oid = &commit->tree->object.oid;
 +      oid = get_commit_tree_oid(commit);
  
        /* Root commit? */
        parents = get_saved_parents(opt, commit);
                         * we merged _in_.
                         */
                        parse_commit_or_die(parents->item);
 -                      diff_tree_oid(&parents->item->tree->object.oid,
 +                      diff_tree_oid(get_commit_tree_oid(parents->item),
                                      oid, "", &opt->diffopt);
                        log_tree_diff_flush(opt);
                        return !opt->loginfo;
                struct commit *parent = parents->item;
  
                parse_commit_or_die(parent);
 -              diff_tree_oid(&parent->tree->object.oid,
 +              diff_tree_oid(get_commit_tree_oid(parent),
                              oid, "", &opt->diffopt);
                log_tree_diff_flush(opt);