Linus Torvalds <torva...@linux-foundation.org> writes:

> Here's a first try at it. It does tab expansion only for the cases
> that indent the commit message, so for things like "pretty=email" it
> makes no difference at all.

It also ignores that byte counts of non-HT bytes may not necessarily
match display columns.  There is utf8_width() function exported from
utf8.c for that purpose.

I think it is fine to make it default for the pretty=medium, but it
would be nicer to introduce a new command line option --no-untabify
to optionally disable the expansion.

>  pretty.c | 20 +++++++++++++++++++-
>  1 file changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/pretty.c b/pretty.c
> index 92b2870a7eab..dcd6105d1eb2 100644
> --- a/pretty.c
> +++ b/pretty.c
> @@ -1652,8 +1652,26 @@ void pp_remainder(struct pretty_print_context *pp,
>               first = 0;
>  
>               strbuf_grow(sb, linelen + indent + 20);
> -             if (indent)
> +             if (indent) {
> +                     int i, last = 0, pos = 0;
> +
>                       strbuf_addchars(sb, ' ', indent);
> +                     for (i = 0; i < linelen; i++) {
> +                             int expand;
> +                             if (line[i] != '\t')
> +                                     continue;
> +                             strbuf_add(sb, line+last, i-last);
> +                             pos += i-last;
> +                             expand = (pos + 8) & ~7;
> +                             strbuf_addchars(sb, ' ', expand - pos);
> +                             pos = expand;
> +                             last = i+1;
> +                     }
> +
> +                     // Handle the tail non-tab content
> +                     line += last;
> +                     linelen -= last;
> +             }
>               strbuf_add(sb, line, linelen);
>               strbuf_addch(sb, '\n');
>       }
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to