threads / patch / 51064

patchdoc/gitattributes: add Octave

Subject: [PATCH] doc/gitattributes: add Octave

## tl;dr

22 messages between May 10, 2019 and May 29, 2019. Diffs are folded; open one to read it.

replies: 21people: 5as markdown or json

Boxuan Li· May 10, 2019, 00:47 UTC · lore

`matlab` pattern is also suitable for source code in the GNU Octave language.

Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
---
 Documentation/gitattributes.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to Documentation/gitattributes.txt +1 −1
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 4fb20cd0e9..1b28381bda 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -819,7 +819,7 @@ patterns are available:
 
 - `java` suitable for source code in the Java language.
 
-- `matlab` suitable for source code in the MATLAB language.
+- `matlab` suitable for source code in the MATLAB/Octave language.
 
 - `objc` suitable for source code in the Objective-C language.
 
-- 
2.21.0.777.g83232e3864
Philip Oakley· May 10, 2019, 23:09 UTC · re: Boxuan Li · lore

Re: [PATCH] doc/gitattributes: add Octave

On 10/05/2019 01:47, Boxuan Li wrote:
Show 21 quoted lines
> `matlab` pattern is also suitable for source code
> in the GNU Octave language.
>
> Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
> ---
>   Documentation/gitattributes.txt | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
> index 4fb20cd0e9..1b28381bda 100644
> --- a/Documentation/gitattributes.txt
> +++ b/Documentation/gitattributes.txt
> @@ -819,7 +819,7 @@ patterns are available:
>   
>   - `java` suitable for source code in the Java language.
>   
> -- `matlab` suitable for source code in the MATLAB language.
> +- `matlab` suitable for source code in the MATLAB/Octave language.
>   
>   - `objc` suitable for source code in the Objective-C language.
>   

Looks good to me. Will help Octave users searching on their name for the Open Source variant of Matlab. -- Philip

Ævar Arnfjörð Bjarmason· May 10, 2019, 23:26 UTC · re: Boxuan Li · lore

Re: [PATCH] doc/gitattributes: add Octave

On Fri, May 10 2019, Boxuan Li wrote:
Show 20 quoted lines
> `matlab` pattern is also suitable for source code
> in the GNU Octave language.
>
> Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
> ---
>  Documentation/gitattributes.txt | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
> index 4fb20cd0e9..1b28381bda 100644
> --- a/Documentation/gitattributes.txt
> +++ b/Documentation/gitattributes.txt
> @@ -819,7 +819,7 @@ patterns are available:
>
>  - `java` suitable for source code in the Java language.
>
> -- `matlab` suitable for source code in the MATLAB language.
> +- `matlab` suitable for source code in the MATLAB/Octave language.
>
>  - `objc` suitable for source code in the Objective-C language.
I've never used either, but browsing our patterns I see:
         "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",

I.e. that last bit matches ^%%, and then here: https://en.wikibooks.org/wiki/MATLAB_Programming/Differences_between_Octave_and_MATLAB

    MATLAB uses the percent sign '%' to begin a comment. Octave uses
    both the hash symbol # and the percent sign % interchangeably.

So here we have the "function" pattern matching a comment, right? (this doesn't have any tests) and we'd want to add "#" to Octave, but not MATLAB.

I see both tend to use the ".m" extension. Anyway, isn't it better to add an "octave" pattern, and document that they're mostly the same (although it looks like we can add #-comments, to future-proof ourselves?

LI, BO XUAN· May 11, 2019, 02:36 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: [PATCH] doc/gitattributes: add Octave

On Sat, May 11, 2019 at 7:26 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:

Show 38 quoted lines
>
>
> On Fri, May 10 2019, Boxuan Li wrote:
>
> > `matlab` pattern is also suitable for source code
> > in the GNU Octave language.
> >
> > Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
> > ---
> >  Documentation/gitattributes.txt | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
> > index 4fb20cd0e9..1b28381bda 100644
> > --- a/Documentation/gitattributes.txt
> > +++ b/Documentation/gitattributes.txt
> > @@ -819,7 +819,7 @@ patterns are available:
> >
> >  - `java` suitable for source code in the Java language.
> >
> > -- `matlab` suitable for source code in the MATLAB language.
> > +- `matlab` suitable for source code in the MATLAB/Octave language.
> >
> >  - `objc` suitable for source code in the Objective-C language.
>
> I've never used either, but browsing our patterns I see:
>
>          "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
>
> I.e. that last bit matches ^%%, and then here:
> https://en.wikibooks.org/wiki/MATLAB_Programming/Differences_between_Octave_and_MATLAB
>
>     MATLAB uses the percent sign '%' to begin a comment. Octave uses
>     both the hash symbol # and the percent sign % interchangeably.
>
> So here we have the "function" pattern matching a comment, right? (this
> doesn't have any tests) and we'd want to add "#" to Octave, but not
> MATLAB.

Thanks, that's a great catch! Actually, '%%' is used to start a code section in Matlab (https://www.mathworks.com/help/matlab/matlab_prog/run-sections-of-programs.html), while Octave uses both '%%' and '##' (https://octave.org/doc/interpreter/Sections.html).

>
> I see both tend to use the ".m" extension. Anyway, isn't it better to
> add an "octave" pattern, and document that they're mostly the same
I agree. I'll send an updated patch soon.
> (although it looks like we can add #-comments, to future-proof
> ourselves?
Boxuan Li· May 11, 2019, 04:08 UTC · re: LI, BO XUAN · lore

[PATCH v2] userdiff.c & doc/gitattributes.txt: add Octave

Octave pattern is almost the same as matlab. Besides, octave also uses '%%%' or '##' to begin code sections.

Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
---
v1: use matlab pattern for octave language
---
 Documentation/gitattributes.txt | 2 ++
 userdiff.c                      | 5 +++++
 2 files changed, 7 insertions(+)
Show changes to 2 files +7 −0

Documentation/gitattributes.txt, userdiff.c

diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 4fb20cd0e9..45374c7dd3 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -821,6 +821,8 @@ patterns are available:
 
 - `matlab` suitable for source code in the MATLAB language.
 
+- `octave` suitable for source code in the Octave language.
+
 - `objc` suitable for source code in the Objective-C language.
 
 - `pascal` suitable for source code in the Pascal/Delphi language.
diff --git a/userdiff.c b/userdiff.c
index 3a78fbf504..6e9b56f1d6 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -60,6 +60,11 @@ PATTERNS("java",
 PATTERNS("matlab",
 	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
 	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
+PATTERNS("octave",
+     /* Mostly the same as matlab. In addition, Octave
+      * supports '##' and '%%%' for code sections */
+     "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
+     "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
 PATTERNS("objc",
 	 /* Negate C statements that can look like functions */
 	 "!^[ \t]*(do|for|if|else|return|switch|while)\n"
-- 
2.21.0.777.g83232e3864
Boxuan Li· May 11, 2019, 04:13 UTC · re: LI, BO XUAN · lore

[PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave

Octave pattern is almost the same as matlab. Besides, octave also uses '%%%' or '##' to begin code sections.

Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
---
Update from v2: fix indentation
---
 Documentation/gitattributes.txt | 2 ++
 userdiff.c                      | 5 +++++
 2 files changed, 7 insertions(+)
Show changes to 2 files +7 −0

Documentation/gitattributes.txt, userdiff.c

diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 4fb20cd0e9..45374c7dd3 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -821,6 +821,8 @@ patterns are available:
 
 - `matlab` suitable for source code in the MATLAB language.
 
+- `octave` suitable for source code in the Octave language.
+
 - `objc` suitable for source code in the Objective-C language.
 
 - `pascal` suitable for source code in the Pascal/Delphi language.
diff --git a/userdiff.c b/userdiff.c
index 3a78fbf504..7d07b82116 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -60,6 +60,11 @@ PATTERNS("java",
 PATTERNS("matlab",
 	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
 	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
+PATTERNS("octave",
+	 /* Mostly the same as matlab. In addition, Octave
+	  * supports '##' and '%%%' for code sections */
+	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
+	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
 PATTERNS("objc",
 	 /* Negate C statements that can look like functions */
 	 "!^[ \t]*(do|for|if|else|return|switch|while)\n"
-- 
2.21.0.777.g83232e3864
Junio C Hamano· May 15, 2019, 05:35 UTC · re: Boxuan Li · lore

Re: [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave

Boxuan Li <liboxuan@connect.hku.hk> writes:
> Octave pattern is almost the same as matlab. Besides,
> octave also uses '%%%' or '##' to begin code sections.

My reading of the above hiccupped at around "Besides, octave also uses...".

Checking the differences in patterns, I think
	... the same as matlab, except that '%%%' and '##' can also
	be used to begin code sections, in addition to '%%' that is
	understood by both.

may be easier to read. It makes it clear that you'd want to stay away from %%% and ## if you want to be compatible.

Thanks.
Show 37 quoted lines
> Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
> ---
> Update from v2: fix indentation
> ---
>  Documentation/gitattributes.txt | 2 ++
>  userdiff.c                      | 5 +++++
>  2 files changed, 7 insertions(+)
>
> diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
> index 4fb20cd0e9..45374c7dd3 100644
> --- a/Documentation/gitattributes.txt
> +++ b/Documentation/gitattributes.txt
> @@ -821,6 +821,8 @@ patterns are available:
>  
>  - `matlab` suitable for source code in the MATLAB language.
>  
> +- `octave` suitable for source code in the Octave language.
> +
>  - `objc` suitable for source code in the Objective-C language.
>  
>  - `pascal` suitable for source code in the Pascal/Delphi language.
> diff --git a/userdiff.c b/userdiff.c
> index 3a78fbf504..7d07b82116 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -60,6 +60,11 @@ PATTERNS("java",
>  PATTERNS("matlab",
>  	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
>  	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
> +PATTERNS("octave",
> +	 /* Mostly the same as matlab. In addition, Octave
> +	  * supports '##' and '%%%' for code sections */
> +	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
> +	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
>  PATTERNS("objc",
>  	 /* Negate C statements that can look like functions */
>  	 "!^[ \t]*(do|for|if|else|return|switch|while)\n"
Johannes Sixt· May 15, 2019, 05:57 UTC · re: Boxuan Li · lore

Re: [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave

Am 11.05.19 um 06:13 schrieb Boxuan Li:
> Octave pattern is almost the same as matlab. Besides,
> octave also uses '%%%' or '##' to begin code sections.
> 
Show 13 quoted lines
> @@ -60,6 +60,11 @@ PATTERNS("java",
>  PATTERNS("matlab",
>  	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
>  	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
> +PATTERNS("octave",
> +	 /* Mostly the same as matlab. In addition, Octave
> +	  * supports '##' and '%%%' for code sections */
> +	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
> +	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
>  PATTERNS("objc",
>  	 /* Negate C statements that can look like functions */
>  	 "!^[ \t]*(do|for|if|else|return|switch|while)\n"
> 

In Matlab, are %%% and ## valid syntax? If not, instead of introducing a new language, please just extend the Matlab rule to treat %%% and ## as you need for Octave and mark your Octave files as Matlab.

-- Hannes
LI, BO XUAN· May 15, 2019, 06:15 UTC · re: Johannes Sixt · lore

Re: [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave

On Wed, May 15, 2019 at 1:57 PM Johannes Sixt <j6t@kdbg.org> wrote:
Show 25 quoted lines
>
> Am 11.05.19 um 06:13 schrieb Boxuan Li:
> > Octave pattern is almost the same as matlab. Besides,
> > octave also uses '%%%' or '##' to begin code sections.
> >
>
> > @@ -60,6 +60,11 @@ PATTERNS("java",
> >  PATTERNS("matlab",
> >        "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
> >        "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
> > +PATTERNS("octave",
> > +      /* Mostly the same as matlab. In addition, Octave
> > +       * supports '##' and '%%%' for code sections */
> > +      "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
> > +      "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
> >  PATTERNS("objc",
> >        /* Negate C statements that can look like functions */
> >        "!^[ \t]*(do|for|if|else|return|switch|while)\n"
> >
>
> In Matlab, are %%% and ## valid syntax? If not, instead of introducing a
> new language, please just extend the Matlab rule to treat %%% and ## as
> you need for Octave and mark your Octave files as Matlab.
>
> -- Hannes
Hi Hannes,
'##' is not valid syntax in Matlab scripts.
'%%%' is valid syntax in Matlab. However, it is not used as a section divider.

ref: https://www.mathworks.com/help/matlab/matlab_prog/run-sections-of-programs.html ref: https://octave.org/doc/interpreter/Sections.html

Best regards, Boxuan

Johannes Sixt· May 15, 2019, 17:46 UTC · re: LI, BO XUAN · lore

Re: [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave

Am 15.05.19 um 08:15 schrieb LI, BO XUAN:
Show 28 quoted lines
> On Wed, May 15, 2019 at 1:57 PM Johannes Sixt <j6t@kdbg.org> wrote:
>>
>> Am 11.05.19 um 06:13 schrieb Boxuan Li:
>>> Octave pattern is almost the same as matlab. Besides,
>>> octave also uses '%%%' or '##' to begin code sections.
>>>
>>
>>> @@ -60,6 +60,11 @@ PATTERNS("java",
>>>  PATTERNS("matlab",
>>>        "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
>>>        "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
>>> +PATTERNS("octave",
>>> +      /* Mostly the same as matlab. In addition, Octave
>>> +       * supports '##' and '%%%' for code sections */
>>> +      "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
>>> +      "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
>>>  PATTERNS("objc",
>>>        /* Negate C statements that can look like functions */
>>>        "!^[ \t]*(do|for|if|else|return|switch|while)\n"
>>>
>>
>> In Matlab, are %%% and ## valid syntax? If not, instead of introducing a
>> new language, please just extend the Matlab rule to treat %%% and ## as
>> you need for Octave and mark your Octave files as Matlab.
> 
> '##' is not valid syntax in Matlab scripts.
> 
> '%%%' is valid syntax in Matlab. However, it is not used as a section divider.

In Matlab, is %%% followed by space at the beginning of a line *commonly* used for something different? If I were to make a guess, I would say no. If I'm right, it does not hurt to merge the Octave rules into the Matlab rules.

-- Hannes
Junio C Hamano· May 16, 2019, 09:19 UTC · re: Johannes Sixt · lore

Re: [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave

Johannes Sixt <j6t@kdbg.org> writes:
> In Matlab, is %%% followed by space at the beginning of a line
> *commonly* used for something different? If I were to make a guess, I
> would say no. If I'm right, it does not hurt to merge the Octave rules
> into the Matlab rules.

That is true because we are not syntax-aware and error-highlighting text editor. If we were, I'd suspect that your stance may probably be different. But instead we apply these patterns to a program that is assumed to be correctly written.

And from that point of view, I agree with you that it would not hurt to make the existing patterns for Matlab slightly more receptive so that a correctly written programs in either language would be matched appropriately.

But would it hurt to have two similar entries, with a clear description on how they are different, in our code there, given how infrequently individual entries have historically been updated?

Johannes Sixt· May 16, 2019, 19:20 UTC · re: Junio C Hamano · lore

Re: [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave

Am 16.05.19 um 11:19 schrieb Junio C Hamano:
Show 11 quoted lines
> Johannes Sixt <j6t@kdbg.org> writes:
> 
>> In Matlab, is %%% followed by space at the beginning of a line
>> *commonly* used for something different? If I were to make a guess, I
>> would say no. If I'm right, it does not hurt to merge the Octave rules
>> into the Matlab rules.
> 
> That is true because we are not syntax-aware and error-highlighting
> text editor.  If we were, I'd suspect that your stance may probably
> be different.  But instead we apply these patterns to a program that
> is assumed to be correctly written.
Correct!
Show 8 quoted lines
> And from that point of view, I agree with you that it would not hurt
> to make the existing patterns for Matlab slightly more receptive so
> that a correctly written programs in either language would be matched
> appropriately.
> 
> But would it hurt to have two similar entries, with a clear
> description on how they are different, in our code there, given how
> infrequently individual entries have historically been updated?

Would it hurt? Probably not. Should we open the door for everybody's favorite dialect? Probably not, either.

See, we do not even have separate entries for C and C++. Heck, we don't have an XML entry, because the HTML entry is good enough, and there are probably many more XML users than Matlab and Octave users together.

I'd prefer to keep this list at the minimum necessary as long as it is hard-coded in C. I would take a different stance if this were some configuration file that we ship.

-- Hannes
Junio C Hamano· May 16, 2019, 23:33 UTC · re: Johannes Sixt · lore

Re: [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave

Johannes Sixt <j6t@kdbg.org> writes:
> I'd prefer to keep this list at the minimum necessary as long as it is
> hard-coded in C.
Yeah, I know that feeling.
> I would take a different stance if this were some
> configuration file that we ship.
Hmm, now you reminded me of my ancient wish.

Perhaps it is not too bad to ship $(sharedir)/git-core/userdiff that can be read using git_config_from_file() interface, using a very narrow callback function that understands only diff.*.xfuncname and diff.*.wordregex and discards everything else, without even following the include/includeIf stuff? As long as that can be done safely and without too much overhead, we could get rid of the hardcoded patterns in userdiff.c::builtin_drivers[] and that would be wonderful ;-)

LI, BO XUAN· May 17, 2019, 12:19 UTC · re: Junio C Hamano · lore

Re: [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave

On Fri, May 17, 2019 at 7:34 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 8 quoted lines
>
> Johannes Sixt <j6t@kdbg.org> writes:
>
> > I'd prefer to keep this list at the minimum necessary as long as it is
> > hard-coded in C.
>
> Yeah, I know that feeling.
>
So do we reach a consensus? Should I merge the Octave rules into Matlab rules?

Best regards, Boxuan

Show 14 quoted lines
> > I would take a different stance if this were some
> > configuration file that we ship.
>
> Hmm, now you reminded me of my ancient wish.
>
> Perhaps it is not too bad to ship $(sharedir)/git-core/userdiff that
> can be read using git_config_from_file() interface, using a very
> narrow callback function that understands only diff.*.xfuncname and
> diff.*.wordregex and discards everything else, without even
> following the include/includeIf stuff?  As long as that can be done
> safely and without too much overhead, we could get rid of the
> hardcoded patterns in userdiff.c::builtin_drivers[] and that would
> be wonderful ;-)
>
Johannes Sixt· May 17, 2019, 19:47 UTC · re: LI, BO XUAN · lore

Re: [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave

Am 17.05.19 um 14:19 schrieb LI, BO XUAN:
Show 10 quoted lines
> On Fri, May 17, 2019 at 7:34 AM Junio C Hamano <gitster@pobox.com> wrote:
>>
>> Johannes Sixt <j6t@kdbg.org> writes:
>>
>>> I'd prefer to keep this list at the minimum necessary as long as it is
>>> hard-coded in C.
>>
>> Yeah, I know that feeling.
> 
> So do we reach a consensus? Should I merge the Octave rules into Matlab rules?

Yes, please, that would be very much appreciated. Bonus points if you add some test cases for the hunk header patterns to the t/t4018 directory.

-- Hannes
Boxuan Li· May 15, 2019, 05:55 UTC · re: LI, BO XUAN · lore

[PATCH v4] userdiff.c & doc/gitattributes.txt: add Octave

Octave pattern is almost the same as matlab, except that '%%%' and '##' can also be used to begin code sections, in addition to '%%' that is understood by both.

Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
---
Thanks to all the reviewers above, this is the fourth version:
v1: use matlab pattern for octave
v2: add a new octave pattern
v3: fix indentation problem of v2
v4: improve doc and commit message
---
 Documentation/gitattributes.txt | 2 ++
 userdiff.c                      | 5 +++++
 2 files changed, 7 insertions(+)
Show changes to 2 files +7 −0

Documentation/gitattributes.txt, userdiff.c

diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 4fb20cd0e9..45374c7dd3 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -821,6 +821,8 @@ patterns are available:
 
 - `matlab` suitable for source code in the MATLAB language.
 
+- `octave` suitable for source code in the Octave language.
+
 - `objc` suitable for source code in the Objective-C language.
 
 - `pascal` suitable for source code in the Pascal/Delphi language.
diff --git a/userdiff.c b/userdiff.c
index 3a78fbf504..1127a4c6b1 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -60,6 +60,11 @@ PATTERNS("java",
 PATTERNS("matlab",
 	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
 	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
+PATTERNS("octave",
+	 /* Mostly the same as matlab, except that '%%%' and '##' can also be used
+	  * to begin code sections, in addition to '%%' that is understood by both. */
+	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
+	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
 PATTERNS("objc",
 	 /* Negate C statements that can look like functions */
 	 "!^[ \t]*(do|for|if|else|return|switch|while)\n"
-- 
2.21.0.777.g83232e3864
Boxuan Li· May 18, 2019, 03:46 UTC · re: LI, BO XUAN · lore

[PATCH v5] userdiff: add Octave

Octave pattern is almost the same as matlab, except that '%%%' and '##' can also be used to begin code sections, in addition to '%%' that is understood by both. Octave pattern is merged into Matlab pattern. Test cases for the hunk header patterns of matlab and octave under t/t4018 are added.

Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
---
v1: use matlab pattern for octave
v2: add a new octave pattern
v3: fix indentation problem of v2
v4: improve doc and commit message
v5: merge octave pattern into matlab and add test cases
---
 Documentation/gitattributes.txt | 2 +-
 t/t4018/matlab-class-definition | 5 +++++
 t/t4018/matlab-function         | 4 ++++
 t/t4018/matlab-octave-section-1 | 3 +++
 t/t4018/matlab-octave-section-2 | 3 +++
 t/t4018/matlab-section          | 3 +++
 userdiff.c                      | 5 ++++-
 7 files changed, 23 insertions(+), 2 deletions(-)
 create mode 100644 t/t4018/matlab-class-definition
 create mode 100644 t/t4018/matlab-function
 create mode 100644 t/t4018/matlab-octave-section-1
 create mode 100644 t/t4018/matlab-octave-section-2
 create mode 100644 t/t4018/matlab-section
Show changes to 7 files +23 −2

Documentation/gitattributes.txt, t/t4018/matlab-class-definition, t/t4018/matlab-function, t/t4018/matlab-octave-section-1, t/t4018/matlab-octave-section-2, t/t4018/matlab-section, userdiff.c

diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 4fb20cd0e9..e657a6b7b7 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -819,7 +819,7 @@ patterns are available:
 
 - `java` suitable for source code in the Java language.
 
-- `matlab` suitable for source code in the MATLAB language.
+- `matlab` suitable for source code in the MATLAB and Octave language.
 
 - `objc` suitable for source code in the Objective-C language.
 
diff --git a/t/t4018/matlab-class-definition b/t/t4018/matlab-class-definition
new file mode 100644
index 0000000000..84daedfb4e
--- /dev/null
+++ b/t/t4018/matlab-class-definition
@@ -0,0 +1,5 @@
+classdef RIGHT
+    properties
+        ChangeMe
+    end
+end
diff --git a/t/t4018/matlab-function b/t/t4018/matlab-function
new file mode 100644
index 0000000000..897a9b13ff
--- /dev/null
+++ b/t/t4018/matlab-function
@@ -0,0 +1,4 @@
+function y = RIGHT()
+x = 5;
+y = ChangeMe + x;
+end
diff --git a/t/t4018/matlab-octave-section-1 b/t/t4018/matlab-octave-section-1
new file mode 100644
index 0000000000..3bb6c4670e
--- /dev/null
+++ b/t/t4018/matlab-octave-section-1
@@ -0,0 +1,3 @@
+%%% RIGHT section
+# this is octave script
+ChangeMe = 1;
diff --git a/t/t4018/matlab-octave-section-2 b/t/t4018/matlab-octave-section-2
new file mode 100644
index 0000000000..ab2980f7f2
--- /dev/null
+++ b/t/t4018/matlab-octave-section-2
@@ -0,0 +1,3 @@
+## RIGHT section
+# this is octave script
+ChangeMe = 1;
diff --git a/t/t4018/matlab-section b/t/t4018/matlab-section
new file mode 100644
index 0000000000..5ea59a5de0
--- /dev/null
+++ b/t/t4018/matlab-section
@@ -0,0 +1,3 @@
+%% RIGHT section
+% this is understood by both matlab and octave
+ChangeMe = 1;
diff --git a/userdiff.c b/userdiff.c
index 3a78fbf504..bcae006abe 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -58,7 +58,10 @@ PATTERNS("java",
 	 "|[-+*/<>%&^|=!]="
 	 "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
 PATTERNS("matlab",
-	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
+	 /* Octave pattern is mostly the same as matlab, except that '%%%' and
+	  * '##' can also be used to begin code sections, in addition to '%%'
+	  * that is understood by both. */
+	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
 	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
 PATTERNS("objc",
 	 /* Negate C statements that can look like functions */
-- 
2.21.0.777.g83232e3864
Johannes Sixt· May 20, 2019, 19:26 UTC · re: Boxuan Li · lore

Re: [PATCH v5] userdiff: add Octave

Am 18.05.19 um 05:46 schrieb Boxuan Li:
Show 6 quoted lines
> Octave pattern is almost the same as matlab, except
> that '%%%' and '##' can also be used to begin code sections,
> in addition to '%%' that is understood by both. Octave
> pattern is merged into Matlab pattern. Test cases for
> the hunk header patterns of matlab and octave under
> t/t4018 are added.

Thank you! This patch looks good. With or without the grammar and style fixes below:

Acked-by: Johannes Sixt <j6t@kdbg.org>
Junio will very likely appreciate if you resend with these fixes applied.
Show 9 quoted lines
> 
> Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
> ---
> v1: use matlab pattern for octave
> v2: add a new octave pattern
> v3: fix indentation problem of v2
> v4: improve doc and commit message
> v5: merge octave pattern into matlab and add test cases
> ---
Show 10 quoted lines
> diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
> index 4fb20cd0e9..e657a6b7b7 100644
> --- a/Documentation/gitattributes.txt
> +++ b/Documentation/gitattributes.txt
> @@ -819,7 +819,7 @@ patterns are available:
>  
>  - `java` suitable for source code in the Java language.
>  
> -- `matlab` suitable for source code in the MATLAB language.
> +- `matlab` suitable for source code in the MATLAB and Octave language.
s/language/languages/
>  
>  - `objc` suitable for source code in the Objective-C language.
>  
Show 12 quoted lines
> diff --git a/userdiff.c b/userdiff.c
> index 3a78fbf504..bcae006abe 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -58,7 +58,10 @@ PATTERNS("java",
>  	 "|[-+*/<>%&^|=!]="
>  	 "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
>  PATTERNS("matlab",
> -	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
> +	 /* Octave pattern is mostly the same as matlab, except that '%%%' and
> +	  * '##' can also be used to begin code sections, in addition to '%%'
> +	  * that is understood by both. */
	/*
	 * We write multi-line
	 * comments like this.
	 */
Show 5 quoted lines
> +	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
>  	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
>  PATTERNS("objc",
>  	 /* Negate C statements that can look like functions */
> 
-- Hannes
Boxuan Li· May 21, 2019, 14:57 UTC · re: Johannes Sixt · lore

[PATCH v6] userdiff: add Octave

Octave pattern is almost the same as matlab, except that '%%%' and '##' can also be used to begin code sections, in addition to '%%' that is understood by both. Octave pattern is merged into Matlab pattern. Test cases for the hunk header patterns of matlab and octave under t/t4018 are added.

Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
Acked-by: Johannes Sixt <j6t@kdbg.org>
---
Thanks to review from Johannes, update from v5:
Fix grammar and style
---
 Documentation/gitattributes.txt | 2 +-
 t/t4018/matlab-class-definition | 5 +++++
 t/t4018/matlab-function         | 4 ++++
 t/t4018/matlab-octave-section-1 | 3 +++
 t/t4018/matlab-octave-section-2 | 3 +++
 t/t4018/matlab-section          | 3 +++
 userdiff.c                      | 7 ++++++-
 7 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100644 t/t4018/matlab-class-definition
 create mode 100644 t/t4018/matlab-function
 create mode 100644 t/t4018/matlab-octave-section-1
 create mode 100644 t/t4018/matlab-octave-section-2
 create mode 100644 t/t4018/matlab-section
Show changes to 7 files +25 −2

Documentation/gitattributes.txt, t/t4018/matlab-class-definition, t/t4018/matlab-function, t/t4018/matlab-octave-section-1, t/t4018/matlab-octave-section-2, t/t4018/matlab-section, userdiff.c

diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 4fb20cd0e9..e387cc6dda 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -819,7 +819,7 @@ patterns are available:
 
 - `java` suitable for source code in the Java language.
 
-- `matlab` suitable for source code in the MATLAB language.
+- `matlab` suitable for source code in the MATLAB and Octave languages.
 
 - `objc` suitable for source code in the Objective-C language.
 
diff --git a/t/t4018/matlab-class-definition b/t/t4018/matlab-class-definition
new file mode 100644
index 0000000000..84daedfb4e
--- /dev/null
+++ b/t/t4018/matlab-class-definition
@@ -0,0 +1,5 @@
+classdef RIGHT
+    properties
+        ChangeMe
+    end
+end
diff --git a/t/t4018/matlab-function b/t/t4018/matlab-function
new file mode 100644
index 0000000000..897a9b13ff
--- /dev/null
+++ b/t/t4018/matlab-function
@@ -0,0 +1,4 @@
+function y = RIGHT()
+x = 5;
+y = ChangeMe + x;
+end
diff --git a/t/t4018/matlab-octave-section-1 b/t/t4018/matlab-octave-section-1
new file mode 100644
index 0000000000..3bb6c4670e
--- /dev/null
+++ b/t/t4018/matlab-octave-section-1
@@ -0,0 +1,3 @@
+%%% RIGHT section
+# this is octave script
+ChangeMe = 1;
diff --git a/t/t4018/matlab-octave-section-2 b/t/t4018/matlab-octave-section-2
new file mode 100644
index 0000000000..ab2980f7f2
--- /dev/null
+++ b/t/t4018/matlab-octave-section-2
@@ -0,0 +1,3 @@
+## RIGHT section
+# this is octave script
+ChangeMe = 1;
diff --git a/t/t4018/matlab-section b/t/t4018/matlab-section
new file mode 100644
index 0000000000..5ea59a5de0
--- /dev/null
+++ b/t/t4018/matlab-section
@@ -0,0 +1,3 @@
+%% RIGHT section
+% this is understood by both matlab and octave
+ChangeMe = 1;
diff --git a/userdiff.c b/userdiff.c
index 3a78fbf504..04270fb4d7 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -58,7 +58,12 @@ PATTERNS("java",
 	 "|[-+*/<>%&^|=!]="
 	 "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
 PATTERNS("matlab",
-	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
+	 /*
+	  * Octave pattern is mostly the same as matlab, except that '%%%' and
+	  * '##' can also be used to begin code sections, in addition to '%%'
+	  * that is understood by both.
+	  */
+	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
 	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
 PATTERNS("objc",
 	 /* Negate C statements that can look like functions */
-- 
2.21.0.777.g83232e3864
Junio C Hamano· May 28, 2019, 16:37 UTC · re: Johannes Sixt · lore

Re: [PATCH v5] userdiff: add Octave

Johannes Sixt <j6t@kdbg.org> writes:
> Junio will very likely appreciate if you resend with these fixes applied.

Heh, thanks, for spotting, but this round has already been in 'next' so any updates should be done incrementally X-<.

Johannes Sixt· May 28, 2019, 20:26 UTC · re: Junio C Hamano · lore

Re: [PATCH v5] userdiff: add Octave

Am 28.05.19 um 18:37 schrieb Junio C Hamano:
Show 7 quoted lines
> Johannes Sixt <j6t@kdbg.org> writes:
> 
>> Junio will very likely appreciate if you resend with these fixes applied.
> 
> Heh, thanks, for spotting, but this round has already been in 'next'
> so any updates should be done incrementally X-<.
> 

I don't terribly mind the small grammatic weakness and the style violation. No further action required from my point of view.

-- Hannes
Boxuan Li· May 29, 2019, 16:15 UTC · re: Johannes Sixt · lore

[PATCH] userdiff: fix grammar and style issues

Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
---
Based on 'next' branch
---
 Documentation/gitattributes.txt | 2 +-
 userdiff.c                      | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)
Show changes to 2 files +5 −3

Documentation/gitattributes.txt, userdiff.c

diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index ade5e6d400..2796dfc83b 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -819,7 +819,7 @@ patterns are available:
 
 - `java` suitable for source code in the Java language.
 
-- `matlab` suitable for source code in the MATLAB and Octave language.
+- `matlab` suitable for source code in the MATLAB and Octave languages.
 
 - `objc` suitable for source code in the Objective-C language.
 
diff --git a/userdiff.c b/userdiff.c
index 5a3bff3836..a47b24b320 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -58,9 +58,11 @@ PATTERNS("java",
 	 "|[-+*/<>%&^|=!]="
 	 "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
 PATTERNS("matlab",
-	 /* Octave pattern is mostly the same as matlab, except that '%%%' and
+	 /*
+	  * Octave pattern is mostly the same as matlab, except that '%%%' and
 	  * '##' can also be used to begin code sections, in addition to '%%'
-	  * that is understood by both. */
+	  * that is understood by both.
+	  */
 	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
 	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
 PATTERNS("objc",
-- 
2.21.0.777.g83232e3864

← back to recent threads