Merge branch 'rs/log-email-subject'
authorJunio C Hamano <gitster@pobox.com>
Fri, 10 Mar 2017 21:24:24 +0000 (13:24 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Mar 2017 21:24:24 +0000 (13:24 -0800)
Code clean-up.

* rs/log-email-subject:
pretty: use fmt_output_email_subject()
log-tree: factor out fmt_output_email_subject()

1  2 
builtin/shortlog.c
commit.h
pretty.c
diff --combined builtin/shortlog.c
index c9585d475d90c41554465f870e530c16ab93199f,21402ae8b735f1ae90b1283dd45b05ad775d7fa1..f78bb4818d7a5254d7c3c2c34d1f370cd3aa9327
@@@ -117,15 -117,11 +117,15 @@@ static void read_from_stdin(struct shor
  {
        struct strbuf author = STRBUF_INIT;
        struct strbuf oneline = STRBUF_INIT;
 +      static const char *author_match[2] = { "Author: ", "author " };
 +      static const char *committer_match[2] = { "Commit: ", "committer " };
 +      const char **match;
  
 +      match = log->committer ? committer_match : author_match;
        while (strbuf_getline_lf(&author, stdin) != EOF) {
                const char *v;
 -              if (!skip_prefix(author.buf, "Author: ", &v) &&
 -                  !skip_prefix(author.buf, "author ", &v))
 +              if (!skip_prefix(author.buf, match[0], &v) &&
 +                  !skip_prefix(author.buf, match[1], &v))
                        continue;
                while (strbuf_getline_lf(&oneline, stdin) != EOF &&
                       oneline.len)
@@@ -144,18 -140,15 +144,18 @@@ void shortlog_add_commit(struct shortlo
        struct strbuf author = STRBUF_INIT;
        struct strbuf oneline = STRBUF_INIT;
        struct pretty_print_context ctx = {0};
 +      const char *fmt;
  
        ctx.fmt = CMIT_FMT_USERFORMAT;
        ctx.abbrev = log->abbrev;
-       ctx.subject = "";
+       ctx.print_email_subject = 1;
        ctx.after_subject = "";
        ctx.date_mode.type = DATE_NORMAL;
        ctx.output_encoding = get_log_output_encoding();
  
 -      format_commit_message(commit, "%an <%ae>", &author, &ctx);
 +      fmt = log->committer ? "%cn <%ce>" : "%an <%ae>";
 +
 +      format_commit_message(commit, fmt, &author, &ctx);
        if (!log->summary) {
                if (log->user_format)
                        pretty_print_commit(&ctx, commit, &oneline);
@@@ -245,8 -238,6 +245,8 @@@ int cmd_shortlog(int argc, const char *
        int nongit = !startup_info->have_repository;
  
        const struct option options[] = {
 +              OPT_BOOL('c', "committer", &log.committer,
 +                       N_("Group by committer rather than author")),
                OPT_BOOL('n', "numbered", &log.sort_by_number,
                         N_("sort output according to the number of commits per author")),
                OPT_BOOL('s', "summary", &log.summary,
diff --combined commit.h
index 9c12abb91110151e3a982c4d8baf8753d0382441,e818aff07e684d34c65dcee7c8a58b24c4bfb079..528272ac9bacebf263c3c9a33bad4dd81bddd4d8
+++ b/commit.h
@@@ -142,21 -142,24 +142,24 @@@ static inline int cmit_fmt_is_mail(enu
        return (fmt == CMIT_FMT_EMAIL || fmt == CMIT_FMT_MBOXRD);
  }
  
+ struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
  struct pretty_print_context {
        /*
         * Callers should tweak these to change the behavior of pp_* functions.
         */
        enum cmit_fmt fmt;
        int abbrev;
-       const char *subject;
        const char *after_subject;
        int preserve_subject;
        struct date_mode date_mode;
        unsigned date_mode_explicit:1;
+       int print_email_subject;
        int expand_tabs_in_log;
        int need_8bit_cte;
        char *notes_message;
        struct reflog_walk_info *reflog_info;
+       struct rev_info *rev;
        const char *output_encoding;
        struct string_list *mailmap;
        int color;
@@@ -175,7 -178,6 +178,6 @@@ struct userformat_want 
  };
  
  extern int has_non_ascii(const char *text);
- struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
  extern const char *logmsg_reencode(const struct commit *commit,
                                   char **commit_encoding,
                                   const char *output_encoding);
@@@ -355,7 -357,7 +357,7 @@@ extern const char *find_commit_header(c
                                      size_t *out_len);
  
  /* Find the end of the log message, the right place for a new trailer. */
 -extern int ignore_non_trailer(struct strbuf *sb);
 +extern int ignore_non_trailer(const char *buf, size_t len);
  
  typedef void (*each_mergetag_fn)(struct commit *commit, struct commit_extra_header *extra,
                                 void *cb_data);
diff --combined pretty.c
index 5e683830d9d66a6a1b50a26ab8c3a8338b33198b,faeb3d97f6d81d99f5add92d33133e96ea4dcdcc..d0f86f5d85cab6c470871cdd6e5ead526259bf6a
+++ b/pretty.c
@@@ -10,7 -10,6 +10,7 @@@
  #include "color.h"
  #include "reflog-walk.h"
  #include "gpg-interface.h"
 +#include "trailer.h"
  
  static char *user_format;
  static struct cmt_fmt_map {
@@@ -890,16 -889,6 +890,16 @@@ const char *format_subject(struct strbu
        return msg;
  }
  
 +static void format_trailers(struct strbuf *sb, const char *msg)
 +{
 +      struct trailer_info info;
 +
 +      trailer_info_get(&info, msg);
 +      strbuf_add(sb, info.trailer_start,
 +                 info.trailer_end - info.trailer_start);
 +      trailer_info_release(&info);
 +}
 +
  static void parse_commit_message(struct format_commit_context *c)
  {
        const char *msg = c->message + c->message_off;
@@@ -1303,12 -1292,6 +1303,12 @@@ static size_t format_commit_one(struct 
                strbuf_addstr(sb, msg + c->body_off);
                return 1;
        }
 +
 +      if (starts_with(placeholder, "(trailers)")) {
 +              format_trailers(sb, msg + c->subject_off);
 +              return strlen("(trailers)");
 +      }
 +
        return 0;       /* unknown placeholder */
  }
  
@@@ -1607,8 -1590,9 +1607,9 @@@ void pp_title_line(struct pretty_print_
                                pp->preserve_subject ? "\n" : " ");
  
        strbuf_grow(sb, title.len + 1024);
-       if (pp->subject) {
-               strbuf_addstr(sb, pp->subject);
+       if (pp->print_email_subject) {
+               if (pp->rev)
+                       fmt_output_email_subject(sb, pp->rev);
                if (needs_rfc2047_encoding(title.buf, title.len, RFC2047_SUBJECT))
                        add_rfc2047(sb, title.buf, title.len,
                                                encoding, RFC2047_SUBJECT);
@@@ -1818,7 -1802,7 +1819,7 @@@ void pretty_print_commit(struct pretty_
        }
  
        pp_header(pp, encoding, commit, &msg, sb);
-       if (pp->fmt != CMIT_FMT_ONELINE && !pp->subject) {
+       if (pp->fmt != CMIT_FMT_ONELINE && !pp->print_email_subject) {
                strbuf_addch(sb, '\n');
        }