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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Boxuan Li committed
May 18, 2019 at 11:46 UTC
91bf382fcf51af04f25ba22e1b70ac13cce4bd0b
7 files changed
+23
-2
Documentation/gitattributes.txt
+1
-1
@@ -819,7 +819,7 @@ patterns are available:
819
820
- `java` suitable for source code in the Java language.
821
822
-- `matlab` suitable for source code in the MATLAB language.
822
+- `matlab` suitable for source code in the MATLAB and Octave language.
823
824
- `objc` suitable for source code in the Objective-C language.
825
t/t4018/matlab-class-definition
new
+5
@@ -0,0 +1,5 @@
1
+classdef RIGHT
2
+ properties
3
+ ChangeMe
4
+ end
5
+end
t/t4018/matlab-function
new
+4
@@ -0,0 +1,4 @@
1
+function y = RIGHT()
2
+x = 5;
3
+y = ChangeMe + x;
4
+end
t/t4018/matlab-octave-section-1
new
+3
@@ -0,0 +1,3 @@
1
+%%% RIGHT section
2
+# this is octave script
3
+ChangeMe = 1;
t/t4018/matlab-octave-section-2
new
+3
@@ -0,0 +1,3 @@
1
+## RIGHT section
2
+# this is octave script
3
+ChangeMe = 1;
t/t4018/matlab-section
new
+3
@@ -0,0 +1,3 @@
1
+%% RIGHT section
2
+% this is understood by both matlab and octave
3
+ChangeMe = 1;
userdiff.c
+4
-1
@@ -58,7 +58,10 @@ PATTERNS("java",
58
"|[-+*/<>%&^|=!]="
59
"|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
60
PATTERNS("matlab",
61
- "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
61
+ /* Octave pattern is mostly the same as matlab, except that '%%%' and
62
+ * '##' can also be used to begin code sections, in addition to '%%'
63
+ * that is understood by both. */
64
+ "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
65
"[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
66
PATTERNS("objc",
67
/* Negate C statements that can look like functions */