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

Re: Re* [PATCH v7 1/1] sideband: highlight keywords in remote sideband output

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 18, 2018, 14:40 UTC
Message-ID
<xmqqmutjagc7.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20180818060911.GC241538@aiede.svl.corp.google.com>
Jonathan Nieder <jrnieder@gmail.com> writes:
Show 8 quoted lines
>> --- a/sideband.c
>> +++ b/sideband.c
>> @@ -75,7 +75,7 @@ static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
>
> Not about this patch: should the 'n' parameter be a size_t instead of
> an int?  It doesn't matter in practice (since the caller has an int,
> it can never be more than INT_MAX) but it might make the intent
> clearer.

I tend to agree, but I think a separate "clean-up" patch to do so is more appropriate than rolling it into this fix.

Show 10 quoted lines
>>  		/*
>>  		 * Match case insensitively, so we colorize output from existing
>>  		 * servers regardless of the case that they use for their
>> 		 * messages. We only highlight the word precisely, so
>> 		 * "successful" stays uncolored.
>> 		 */
>> 		if (!strncasecmp(p->keyword, src, len) && !isalnum(src[len])) {
>
> Not about this patch: should this check "&& src[len] == ':'" instead,
> as discussed upthread?

I originally was of an opinion that we should take only lowercase keyword followed by a colon, primarily because that is what we produce. Then "the real world need" told us that we are better off catching the keyword case-insensitively. Recalling that lesson, I am not sure I would support "let's limit to the colon, rejecting any other punctionation letter".

In any case, we should make such a policy decision outside a patch like this one that is about fixing a behaviour which all users would consider as a bug regardless of the policy they support.

Show 9 quoted lines
>> @@ -100,8 +103,8 @@ static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
>>  		}
>>  	}
>>  
>> -	strbuf_add(dest, src, n);
>> +	if (0 < n)
>> +		strbuf_add(dest, src, n);
>
> This check seems unnecessary.  strbuf_add can cope fine with !n.

I was primarily interested in catching negatives, and !n was a mere optimization, but you are correct to point out that negative n at this point in the codeflow is a BUG().

Previous: Jonathan NiederNext: Junio C Hamano
Message 6 of 17 in “sideband: highlight keywords in remote sideband output”
  1. 0/1 sideband: highlight keywords in remote sideband outputHan-Wen Nienhuys, Aug 7, 2018
  2. 1/1 sideband: highlight keywords in remote sideband outputHan-Wen Nienhuys, Aug 7, 2018
  3. Junio C HamanoAug 17, 2018
  4. Re* [PATCH v7 1/1] sideband: highlight keywords in remote sideband outputJunio C Hamano, Aug 17, 2018
  5. Jonathan NiederAug 18, 2018
  6. Junio C HamanoAug 18, 2018
  7. Junio C HamanoAug 18, 2018
  8. Junio C HamanoAug 18, 2018
  9. Jeff KingAug 18, 2018
  10. Junio C HamanoAug 20, 2018
  11. Han-Wen NienhuysAug 20, 2018
  12. Han-Wen NienhuysAug 20, 2018
  13. Junio C HamanoAug 20, 2018
  14. Jonathan NiederAug 18, 2018
  15. Junio C HamanoAug 18, 2018
  16. Junio C HamanoAug 7, 2018
  17. Han-Wen NienhuysAug 8, 2018

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.