Merge branch 'nd/graph-width-padded' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 11 Jul 2016 17:44:09 +0000 (10:44 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 11 Jul 2016 17:44:09 +0000 (10:44 -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 
pretty.c

diff --combined pretty.c
+++ b/pretty.c
@@@ -1022,9 -1022,15 +1022,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;
  
@@@ -1063,7 -1069,7 +1069,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);
@@@ -1299,6 -1305,7 +1305,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) {