git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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');
>  	}
Previous: Linus TorvaldsNext: Linus Torvalds
Message 15 of 17 in “Tabs in commit messages - de-tabify option in strbuf_stripspace()?”
  1. Linus TorvaldsMar 16, 2016
  2. Stefan BellerMar 16, 2016
  3. Linus TorvaldsMar 16, 2016
  4. Randall S. BeckerMar 16, 2016
  5. Junio C HamanoMar 16, 2016
  6. Linus TorvaldsMar 16, 2016
  7. Stefan BellerMar 16, 2016
  8. Stefan BellerMar 16, 2016
  9. Marc BranchaudMar 16, 2016
  10. Duy NguyenMar 16, 2016
  11. Linus TorvaldsMar 16, 2016
  12. Junio C HamanoMar 16, 2016
  13. Matthieu MoyMar 20, 2016
  14. Linus TorvaldsMar 16, 2016
  15. Junio C HamanoMar 16, 2016
  16. Linus TorvaldsMar 16, 2016
  17. Jeff KingMar 16, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.