Merge branch 'nd/graph-width-padded'
authorJunio C Hamano <gitster@pobox.com>
Wed, 6 Jul 2016 20:38:12 +0000 (13:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Jul 2016 20:38:12 +0000 (13:38 -0700)
"log --graph --format=" learned that "%>|(N)" specifies the width
relative to the terminal's left edge, not relative to the area to
draw text that is to the right of the ancestry-graph section. It
also now accepts negative N that means the column limit is relative
to the right border.

* nd/graph-width-padded:
pretty.c: support <direction>|(<negative number>) forms
pretty: pass graph width to pretty formatting for use in '%>|(N)'

1  2 
commit.h
log-tree.c
pretty.c
diff --combined commit.h
index 1e04d3ae07ebe863ca5841dee6130688bf59b152,0c923f05f73eacecf38602208c28211acd0b8f9e..78ed513c75401b0d1fa821dc18baad833201b4e6
+++ b/commit.h
@@@ -131,17 -131,11 +131,17 @@@ enum cmit_fmt 
        CMIT_FMT_FULLER,
        CMIT_FMT_ONELINE,
        CMIT_FMT_EMAIL,
 +      CMIT_FMT_MBOXRD,
        CMIT_FMT_USERFORMAT,
  
        CMIT_FMT_UNSPECIFIED
  };
  
 +static inline int cmit_fmt_is_mail(enum cmit_fmt fmt)
 +{
 +      return (fmt == CMIT_FMT_EMAIL || fmt == CMIT_FMT_MBOXRD);
 +}
 +
  struct pretty_print_context {
        /*
         * Callers should tweak these to change the behavior of pp_* functions.
         * should not be counted on by callers.
         */
        struct string_list in_body_headers;
+       int graph_width;
  };
  
  struct userformat_want {
diff --combined log-tree.c
index 48daf84d3b495502eb38795fe69426cf978c5896,8d393150c094f55638e4035e9c6121973d3ce9db..9f678abc92a82ce8c0feac6b66044291b730aac9
@@@ -603,7 -603,7 +603,7 @@@ void show_log(struct rev_info *opt
         * Print header line of header..
         */
  
 -      if (opt->commit_format == CMIT_FMT_EMAIL) {
 +      if (cmit_fmt_is_mail(opt->commit_format)) {
                log_write_email_headers(opt, commit, &ctx.subject, &extra_headers,
                                        &ctx.need_8bit_cte);
        } else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
        ctx.output_encoding = get_log_output_encoding();
        if (opt->from_ident.mail_begin && opt->from_ident.name_begin)
                ctx.from_ident = &opt->from_ident;
+       if (opt->graph)
+               ctx.graph_width = graph_width(opt->graph);
        pretty_print_commit(&ctx, commit, &msgbuf);
  
        if (opt->add_signoff)
  
        if ((ctx.fmt != CMIT_FMT_USERFORMAT) &&
            ctx.notes_message && *ctx.notes_message) {
 -              if (ctx.fmt == CMIT_FMT_EMAIL) {
 +              if (cmit_fmt_is_mail(ctx.fmt)) {
                        strbuf_addstr(&msgbuf, "---\n");
                        opt->shown_dashes = 1;
                }
diff --combined pretty.c
index 929e5aef9760cd3a111f1c6339d012b301173bd8,1c67b23968051ad818bac719d4f00342a681cb5e..330a5e0015bb925b0c76c903aa666712e85ed102
+++ b/pretty.c
@@@ -92,7 -92,6 +92,7 @@@ static void setup_commit_formats(void
                { "medium",     CMIT_FMT_MEDIUM,        0,      8 },
                { "short",      CMIT_FMT_SHORT,         0,      0 },
                { "email",      CMIT_FMT_EMAIL,         0,      0 },
 +              { "mboxrd",     CMIT_FMT_MBOXRD,        0,      0 },
                { "fuller",     CMIT_FMT_FULLER,        0,      8 },
                { "full",       CMIT_FMT_FULL,          0,      8 },
                { "oneline",    CMIT_FMT_ONELINE,       1,      0 }
@@@ -445,7 -444,7 +445,7 @@@ void pp_user_info(struct pretty_print_c
        if (pp->mailmap)
                map_user(pp->mailmap, &mailbuf, &maillen, &namebuf, &namelen);
  
 -      if (pp->fmt == CMIT_FMT_EMAIL) {
 +      if (cmit_fmt_is_mail(pp->fmt)) {
                if (pp->from_ident && ident_cmp(pp->from_ident, &ident)) {
                        struct strbuf buf = STRBUF_INIT;
  
                            show_ident_date(&ident, &pp->date_mode));
                break;
        case CMIT_FMT_EMAIL:
 +      case CMIT_FMT_MBOXRD:
                strbuf_addf(sb, "Date: %s\n",
                            show_ident_date(&ident, DATE_MODE(RFC2822)));
                break;
@@@ -537,7 -535,7 +537,7 @@@ static void add_merge_info(const struc
  {
        struct commit_list *parent = commit->parents;
  
 -      if ((pp->fmt == CMIT_FMT_ONELINE) || (pp->fmt == CMIT_FMT_EMAIL) ||
 +      if ((pp->fmt == CMIT_FMT_ONELINE) || (cmit_fmt_is_mail(pp->fmt)) ||
            !parent || !parent->next)
                return;
  
@@@ -1024,9 -1022,15 +1024,15 @@@ static size_t parse_padding_placeholder
                int width;
                if (!end || end == start)
                        return 0;
-               width = strtoul(start, &next, 10);
+               width = strtol(start, &next, 10);
                if (next == start || width == 0)
                        return 0;
+               if (width < 0) {
+                       if (to_column)
+                               width += term_columns();
+                       if (width < 0)
+                               return 0;
+               }
                c->padding = to_column ? -width : width;
                c->flush_type = flush_type;
  
@@@ -1065,7 -1069,7 +1071,7 @@@ static size_t format_commit_one(struct 
        switch (placeholder[0]) {
        case 'C':
                if (starts_with(placeholder + 1, "(auto)")) {
 -                      c->auto_color = 1;
 +                      c->auto_color = want_color(c->pretty_ctx->color);
                        return 7; /* consumed 7 bytes, "C(auto)" */
                } else {
                        int ret = parse_color(sb, placeholder, c);
@@@ -1301,6 -1305,7 +1307,7 @@@ static size_t format_and_pad_commit(str
                if (!start)
                        start = sb->buf;
                occupied = utf8_strnwidth(start, -1, 1);
+               occupied += c->pretty_ctx->graph_width;
                padding = (-padding) - occupied;
        }
        while (1) {
@@@ -1616,7 -1621,7 +1623,7 @@@ void pp_title_line(struct pretty_print_
        if (pp->after_subject) {
                strbuf_addstr(sb, pp->after_subject);
        }
 -      if (pp->fmt == CMIT_FMT_EMAIL) {
 +      if (cmit_fmt_is_mail(pp->fmt)) {
                strbuf_addch(sb, '\n');
        }
  
@@@ -1699,16 -1704,6 +1706,16 @@@ static void pp_handle_indent(struct pre
                strbuf_add(sb, line, linelen);
  }
  
 +static int is_mboxrd_from(const char *line, int len)
 +{
 +      /*
 +       * a line matching /^From $/ here would only have len == 4
 +       * at this point because is_empty_line would've trimmed all
 +       * trailing space
 +       */
 +      return len > 4 && starts_with(line + strspn(line, ">"), "From ");
 +}
 +
  void pp_remainder(struct pretty_print_context *pp,
                  const char **msg_p,
                  struct strbuf *sb,
                else if (pp->expand_tabs_in_log)
                        strbuf_add_tabexpand(sb, pp->expand_tabs_in_log,
                                             line, linelen);
 -              else
 +              else {
 +                      if (pp->fmt == CMIT_FMT_MBOXRD &&
 +                                      is_mboxrd_from(line, linelen))
 +                              strbuf_addch(sb, '>');
 +
                        strbuf_add(sb, line, linelen);
 +              }
                strbuf_addch(sb, '\n');
        }
  }
@@@ -1767,14 -1757,14 +1774,14 @@@ void pretty_print_commit(struct pretty_
        encoding = get_log_output_encoding();
        msg = reencoded = logmsg_reencode(commit, NULL, encoding);
  
 -      if (pp->fmt == CMIT_FMT_ONELINE || pp->fmt == CMIT_FMT_EMAIL)
 +      if (pp->fmt == CMIT_FMT_ONELINE || cmit_fmt_is_mail(pp->fmt))
                indent = 0;
  
        /*
         * We need to check and emit Content-type: to mark it
         * as 8-bit if we haven't done so.
         */
 -      if (pp->fmt == CMIT_FMT_EMAIL && need_8bit_cte == 0) {
 +      if (cmit_fmt_is_mail(pp->fmt) && need_8bit_cte == 0) {
                int i, ch, in_body;
  
                for (in_body = i = 0; (ch = msg[i]); i++) {
        msg = skip_empty_lines(msg);
  
        /* These formats treat the title line specially. */
 -      if (pp->fmt == CMIT_FMT_ONELINE || pp->fmt == CMIT_FMT_EMAIL)
 +      if (pp->fmt == CMIT_FMT_ONELINE || cmit_fmt_is_mail(pp->fmt))
                pp_title_line(pp, &msg, sb, encoding, need_8bit_cte);
  
        beginning_of_body = sb->len;
         * format.  Make sure we did not strip the blank line
         * between the header and the body.
         */
 -      if (pp->fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
 +      if (cmit_fmt_is_mail(pp->fmt) && sb->len <= beginning_of_body)
                strbuf_addch(sb, '\n');
  
        unuse_commit_buffer(commit, reencoded);