Code

Merge branch 'maint'
authorJunio C Hamano <gitster@pobox.com>
Sat, 15 Mar 2008 07:09:20 +0000 (00:09 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 15 Mar 2008 07:09:33 +0000 (00:09 -0700)
* maint:
  format-patch: generate MIME header as needed even when there is format.header

1  2 
builtin-log.c
commit.h
log-tree.c
log-tree.h
pretty.c

diff --cc builtin-log.c
index d983cbc7bc98f1b28332c18946e5111a6dcba9ab,99d69f079132ed67e2d5bc83bf95e6e60ba22f6f..5c00725f030460ba34c702b9ad31e577ca70d361
@@@ -636,85 -580,11 +636,87 @@@ static void gen_message_id(struct rev_i
        const char *committer = git_committer_info(IDENT_WARN_ON_NO_NAME);
        const char *email_start = strrchr(committer, '<');
        const char *email_end = strrchr(committer, '>');
 -      if(!email_start || !email_end || email_start > email_end - 1)
 +      struct strbuf buf;
 +      if (!email_start || !email_end || email_start > email_end - 1)
                die("Could not extract email from committer identity.");
 -      snprintf(dest, length, "%s.%lu.git.%.*s", base,
 -               (unsigned long) time(NULL),
 -               (int)(email_end - email_start - 1), email_start + 1);
 +      strbuf_init(&buf, 0);
 +      strbuf_addf(&buf, "%s.%lu.git.%.*s", base,
 +                  (unsigned long) time(NULL),
 +                  (int)(email_end - email_start - 1), email_start + 1);
 +      info->message_id = strbuf_detach(&buf, NULL);
 +}
 +
 +static void make_cover_letter(struct rev_info *rev, int use_stdout,
 +                            int numbered, int numbered_files,
 +                            struct commit *origin,
 +                            int nr, struct commit **list, struct commit *head)
 +{
 +      const char *committer;
 +      char *head_sha1;
 +      const char *subject_start = NULL;
 +      const char *body = "*** SUBJECT HERE ***\n\n*** BLURB HERE ***\n";
 +      const char *msg;
 +      const char *extra_headers = rev->extra_headers;
 +      struct shortlog log;
 +      struct strbuf sb;
 +      int i;
 +      const char *encoding = "utf-8";
 +      struct diff_options opts;
++      int need_8bit_cte = 0;
 +
 +      if (rev->commit_format != CMIT_FMT_EMAIL)
 +              die("Cover letter needs email format");
 +
 +      if (!use_stdout && reopen_stdout(numbered_files ?
 +                              NULL : "cover-letter", 0, rev->total))
 +              return;
 +
 +      head_sha1 = sha1_to_hex(head->object.sha1);
 +
-       log_write_email_headers(rev, head_sha1, &subject_start, &extra_headers);
++      log_write_email_headers(rev, head_sha1, &subject_start, &extra_headers,
++                              &need_8bit_cte);
 +
 +      committer = git_committer_info(0);
 +
 +      msg = body;
 +      strbuf_init(&sb, 0);
 +      pp_user_info(NULL, CMIT_FMT_EMAIL, &sb, committer, DATE_RFC2822,
 +                   encoding);
 +      pp_title_line(CMIT_FMT_EMAIL, &msg, &sb, subject_start, extra_headers,
-                     encoding, 0);
++                    encoding, need_8bit_cte);
 +      pp_remainder(CMIT_FMT_EMAIL, &msg, &sb, 0);
 +      printf("%s\n", sb.buf);
 +
 +      strbuf_release(&sb);
 +
 +      shortlog_init(&log);
 +      log.wrap_lines = 1;
 +      log.wrap = 72;
 +      log.in1 = 2;
 +      log.in2 = 4;
 +      for (i = 0; i < nr; i++)
 +              shortlog_add_commit(&log, list[i]);
 +
 +      shortlog_output(&log);
 +
 +      /*
 +       * We can only do diffstat with a unique reference point
 +       */
 +      if (!origin)
 +              return;
 +
 +      memcpy(&opts, &rev->diffopt, sizeof(opts));
 +      opts.output_format = DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
 +
 +      diff_setup_done(&opts);
 +
 +      diff_tree_sha1(origin->tree->object.sha1,
 +                     head->tree->object.sha1,
 +                     "", &opts);
 +      diffcore_std(&opts);
 +      diff_flush(&opts);
 +
 +      printf("\n");
  }
  
  static const char *clean_message_id(const char *msg_id)
diff --cc commit.h
index a1e95914263355e2021f54be4837ed25f1210757,000528a67b0f087793da2001d69993260bdaeb4a..2f63bc8b2fac0d748e13d4435d550d61002092b3
+++ b/commit.h
@@@ -70,22 -70,7 +70,22 @@@ extern void pretty_print_commit(enum cm
                                  struct strbuf *,
                                  int abbrev, const char *subject,
                                  const char *after_subject, enum date_mode,
-                               int non_ascii_present);
+                               int need_8bit_cte);
 +void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
 +                 const char *line, enum date_mode dmode,
 +                 const char *encoding);
 +void pp_title_line(enum cmit_fmt fmt,
 +                 const char **msg_p,
 +                 struct strbuf *sb,
 +                 const char *subject,
 +                 const char *after_subject,
 +                 const char *encoding,
-                  int plain_non_ascii);
++                 int need_8bit_cte);
 +void pp_remainder(enum cmit_fmt fmt,
 +                const char **msg_p,
 +                struct strbuf *sb,
 +                int indent);
 +
  
  /** Removes the first commit from a list sorted by date, and adds all
   * of its parents.
diff --cc log-tree.c
index 608f697cf3860245510bff907a643d9b6143e724,dd94f393a06a0c8a7fc6420af0b9487df47ec4a4..5b2963998cc497177d913b6224799531d45dbb4a
@@@ -137,72 -137,6 +137,77 @@@ static int has_non_ascii(const char *s
        return 0;
  }
  
-                            const char **subject_p, const char **extra_headers_p)
 +void log_write_email_headers(struct rev_info *opt, const char *name,
++                           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;
++
++      *need_8bit_cte_p = 0; /* unknown */
 +      if (opt->total > 0) {
 +              static char buffer[64];
 +              snprintf(buffer, sizeof(buffer),
 +                       "Subject: [%s %0*d/%d] ",
 +                       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);
 +      if (opt->message_id)
 +              printf("Message-Id: <%s>\n", opt->message_id);
 +      if (opt->ref_message_id)
 +              printf("In-Reply-To: <%s>\nReferences: <%s>\n",
 +                     opt->ref_message_id, opt->ref_message_id);
 +      if (opt->mime_boundary) {
 +              static char subject_buffer[1024];
 +              static char buffer[1024];
++              *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;
 +
 +              snprintf(buffer, sizeof(buffer) - 1,
 +                       "--%s%s\n"
 +                       "Content-Type: text/x-patch;"
 +                       " name=\"%s.diff\"\n"
 +                       "Content-Transfer-Encoding: 8bit\n"
 +                       "Content-Disposition: %s;"
 +                       " filename=\"%s.diff\"\n\n",
 +                       mime_boundary_leader, opt->mime_boundary,
 +                       name,
 +                       opt->no_inline ? "attachment" : "inline",
 +                       name);
 +              opt->diffopt.stat_sep = buffer;
 +      }
 +      *subject_p = subject;
 +      *extra_headers_p = extra_headers;
 +}
 +
  void show_log(struct rev_info *opt, const char *sep)
  {
        struct strbuf msgbuf;
         */
  
        if (opt->commit_format == CMIT_FMT_EMAIL) {
 -              char *sha1 = sha1_to_hex(commit->object.sha1);
 -              if (opt->total > 0) {
 -                      static char buffer[64];
 -                      snprintf(buffer, sizeof(buffer),
 -                                      "Subject: [%s %0*d/%d] ",
 -                                      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", sha1);
 -              if (opt->message_id)
 -                      printf("Message-Id: <%s>\n", opt->message_id);
 -              if (opt->ref_message_id)
 -                      printf("In-Reply-To: <%s>\nReferences: <%s>\n",
 -                             opt->ref_message_id, opt->ref_message_id);
 -              if (opt->mime_boundary) {
 -                      static char subject_buffer[1024];
 -                      static char buffer[1024];
 -
 -                      need_8bit_cte = -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;
 -
 -                      snprintf(buffer, sizeof(buffer) - 1,
 -                               "--%s%s\n"
 -                               "Content-Type: text/x-patch;"
 -                               " name=\"%s.diff\"\n"
 -                               "Content-Transfer-Encoding: 8bit\n"
 -                               "Content-Disposition: %s;"
 -                               " filename=\"%s.diff\"\n\n",
 -                               mime_boundary_leader, opt->mime_boundary,
 -                               sha1,
 -                               opt->no_inline ? "attachment" : "inline",
 -                               sha1);
 -                      opt->diffopt.stat_sep = buffer;
 -              }
 +              log_write_email_headers(opt, sha1_to_hex(commit->object.sha1),
-                                       &subject, &extra_headers);
++                                      &subject, &extra_headers,
++                                      &need_8bit_cte);
        } else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
                fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout);
                if (opt->commit_format != CMIT_FMT_ONELINE)
diff --cc log-tree.h
index 0cc9344eabdd0046edf360958376b2037ef643dc,b33f7cd7ac2ef6a2587109c4ee618d63ccedae96..8946ff377ca455dd1c4efaa609ce9af382005836
@@@ -13,7 -13,5 +13,9 @@@ int log_tree_commit(struct rev_info *, 
  int log_tree_opt_parse(struct rev_info *, const char **, int);
  void show_log(struct rev_info *opt, const char *sep);
  void show_decorations(struct commit *commit);
-                            const char **subject_p, const char **extra_headers_p);
 +void log_write_email_headers(struct rev_info *opt, const char *name,
++                           const char **subject_p,
++                           const char **extra_headers_p,
++                           int *need_8bit_cte_p);
  
  #endif
diff --cc pretty.c
index 703f52176bf0b5cbf52cf1f77ba55ba6d87fac94,0963bb08c125c8fc0c4d8ee5e8ff293145678158..16bfb86cd3ce6d6b471cdc313114563ca78837dc
+++ b/pretty.c
@@@ -630,13 -653,13 +630,13 @@@ static void pp_header(enum cmit_fmt fmt
        }
  }
  
 -static void pp_title_line(enum cmit_fmt fmt,
 -                        const char **msg_p,
 -                        struct strbuf *sb,
 -                        const char *subject,
 -                        const char *after_subject,
 -                        const char *encoding,
 -                        int need_8bit_cte)
 +void pp_title_line(enum cmit_fmt fmt,
 +                 const char **msg_p,
 +                 struct strbuf *sb,
 +                 const char *subject,
 +                 const char *after_subject,
 +                 const char *encoding,
-                  int plain_non_ascii)
++                 int need_8bit_cte)
  {
        struct strbuf title;