All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: Tabs in commit messages - de-tabify option in strbuf_stripspace()?
Date: Tue, 15 Mar 2016 21:46:53 -0700	[thread overview]
Message-ID: <xmqqzitz58si.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <CA+55aFw8roOTTuFknzh3zRkCbgaMGmtxMRk-ctBdJ8Wsu041bA@mail.gmail.com> (Linus Torvalds's message of "Tue, 15 Mar 2016 21:05:01 -0700")

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.

>  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');
>  	}

  reply	other threads:[~2016-03-16  4:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-16  0:16 Tabs in commit messages - de-tabify option in strbuf_stripspace()? Linus Torvalds
2016-03-16  0:23 ` Stefan Beller
2016-03-16  0:45   ` Linus Torvalds
2016-03-16  0:34 ` Randall S. Becker
2016-03-16  0:45 ` Junio C Hamano
2016-03-16  0:48   ` Linus Torvalds
2016-03-16  1:00     ` Stefan Beller
2016-03-16  1:02       ` Stefan Beller
2016-03-16 14:27         ` Marc Branchaud
2016-03-16 14:50           ` Duy Nguyen
2016-03-16 16:15           ` Linus Torvalds
2016-03-16 16:47             ` Junio C Hamano
2016-03-20 13:29           ` Matthieu Moy
2016-03-16  4:05     ` Linus Torvalds
2016-03-16  4:46       ` Junio C Hamano [this message]
2016-03-16  4:57         ` Linus Torvalds
2016-03-16  5:17           ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqzitz58si.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.