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

Re: [PATCH v2] userdiff: support Bash

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 21, 2020, 18:39 UTC
Message-ID
<xmqq8sbz8lvb.fsf@gitster.c.googlers.com>
In-Reply-To
<a07042af-d16c-1975-c0d1-f22f4fec5827@kdbg.org>
Johannes Sixt <j6t@kdbg.org> writes:
Show 23 quoted lines
>> diff --git a/t/t4018/bash-missing-parentheses b/t/t4018/bash-missing-parentheses
>> new file mode 100644
>> index 0000000000..d112761300
>> --- /dev/null
>> +++ b/t/t4018/bash-missing-parentheses
>> @@ -0,0 +1,4 @@
>> +functionRIGHT { # non-match
>> +    :
>> +    echo 'ChangeMe'
>> +}
>
> To check for a non-match, you write the test like this:
>
> 	function RIGHT () {
> 	}
> 	# the following must not be picked up:
> 	functionWrong {
> 		:
> 		ChangeMe
> 	}
>
> That is, you present a positive match, and then expect that the
> subsequent negative match is not picked up.
All good suggestions, but I especially appreciate this one ;-).
Show 16 quoted lines
>> diff --git a/userdiff.c b/userdiff.c
>> index fde02f225b..8830019f05 100644
>> --- a/userdiff.c
>> +++ b/userdiff.c
>> @@ -23,6 +23,28 @@ IPATTERN("ada",
>>  	 "[a-zA-Z][a-zA-Z0-9_]*"
>>  	 "|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?"
>>  	 "|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"),
>> +PATTERNS("bash",
>> +	 /* Optional leading indentation */
>> +	 "^[ \t]*"
>> +	 /* Start of function definition */
>> +	 "("
>
> The purpose of this outer-most pair of parentheses is actually to mark
> the captured text, not so much "the function definition".

This, too (I called it "here comes the whole thing" in my suggested version ).

Show 12 quoted lines
>> +	 /* Start of POSIX/Bashism grouping */
>> +	 "("
>
> You could omit the comment if you indent the parts that are inside the
> parentheses:
>
> 	"("
> 		"..."
> 	"|"
> 		"..."
> 	")"
>
An excellent readability suggestion.

Thanks for a review. Especially the parts that mine didn't touch (i.e. the proposed log message).

Show 18 quoted lines
> (But perhaps don't indent between the outer-most parentheses; it would
> get us too far to the right. But judge yourself.)
>
>> +	 /* POSIX identifier with mandatory parentheses */
>> +	 "[a-zA-Z_][a-zA-Z0-9_]*[ \t]*\\([ \t]*\\))"
>> +	 /* Bashism identifier with optional parentheses */
>> +	 "|(function[ \t]+[a-zA-Z_][a-zA-Z0-9_]*(([ \t]*\\([ \t]*\\))|([ \t]+))"
>> +	 /* End of POSIX/Bashism grouping */
>> +	 ")"
>> +	 /* Optional whitespace */
>> +	 "[ \t]*"
>> +	 /* Compound command starting with `{`, `(`, `((` or `[[` */
>> +	 "(\\{|\\(\\(?|\\[\\[)"
>> +	 /* End of function definition */
>> +	 ")",
>> +	 /* -- */
>> +	 /* Characters not in the default $IFS value */
>> +	 "[^ \t]+"),
Previous: Johannes SixtNext: Victor Engmark
Message 5 of 9 in “userdiff: support Bash”
  1. userdiff: support BashVictor Engmark, Oct 20, 2020
  2. Junio C HamanoOct 20, 2020
  3. userdiff: support BashVictor Engmark, Oct 21, 2020
  4. Johannes SixtOct 21, 2020
  5. Junio C HamanoOct 21, 2020
  6. Victor EngmarkOct 21, 2020
  7. userdiff: support BashVictor Engmark, Oct 21, 2020
  8. Johannes SixtOct 22, 2020
  9. Junio C HamanoOct 22, 2020

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.