Re: Tabs in commit messages - de-tabify option in strbuf_stripspace()?
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 16, 2016, 04:46 UTC
- Message-ID
- <xmqqzitz58si.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <CA+55aFw8roOTTuFknzh3zRkCbgaMGmtxMRk-ctBdJ8Wsu041bA@mail.gmail.com>
Linus Torvalds <torvalds@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.
Show 35 quoted lines
> 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');
> }