userdiff: add a builtin pattern for dts files

The Linux kernel receives many patches to the devicetree files each release. The hunk header for those patches typically show nothing, making it difficult to figure out what node is being modified without applying the patch or opening the file and seeking to the context. Let's add a builtin 'dts' pattern to git so that users can get better diff output on dts files when they use the diff=dts driver. The regex has been constructed based on the spec at devicetree.org[1] and with some help from Johannes Sixt. [1] https://github.com/devicetree-org/devicetree-specification/releases/latest Cc: Rob Herring <robh+dt@kernel.org> Cc: Frank Rowand <frowand.list@gmail.com> Signed-off-by: Stephen Boyd <sboyd@kernel.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stephen Boyd committed Aug 19, 2019 at 14:22 UTC 3c81760bc66376c3ac69c39475cbe3b13e97e798
14 files changed +168
Documentation/gitattributes.txt
+2
@@ -810,6 +810,8 @@ patterns are available:
810
811 - `css` suitable for cascading style sheets.
812
813 +- `dts` suitable for devicetree (DTS) files.
814 +
815 - `fortran` suitable for source code in the Fortran language.
816
817 - `fountain` suitable for Fountain documents.
t/t4018-diff-funcname.sh
+1
@@ -31,6 +31,7 @@ diffpatterns="
31 cpp
32 csharp
33 css
34 + dts
35 fortran
36 fountain
37 golang
t/t4018/dts-labels new
+9
@@ -0,0 +1,9 @@
1 +/ {
2 + label_1: node1@ff00 {
3 + label2: RIGHT {
4 + vendor,some-property;
5 +
6 + ChangeMe = <0x45-30>;
7 + };
8 + };
9 +};
t/t4018/dts-node-unitless new
+8
@@ -0,0 +1,8 @@
1 +/ {
2 + label_1: node1 {
3 + RIGHT {
4 + prop-array = <1>, <4>;
5 + ChangeMe = <0xffeedd00>;
6 + };
7 + };
8 +};
t/t4018/dts-nodes new
+8
@@ -0,0 +1,8 @@
1 +/ {
2 + label_1: node1@ff00 {
3 + RIGHT@deadf00,4000 {
4 + #size-cells = <1>;
5 + ChangeMe = <0xffeedd00>;
6 + };
7 + };
8 +};
t/t4018/dts-nodes-comment1 new
+8
@@ -0,0 +1,8 @@
1 +/ {
2 + label_1: node1@ff00 {
3 + RIGHT@deadf00,4000 /* &a comment */ {
4 + #size-cells = <1>;
5 + ChangeMe = <0xffeedd00>;
6 + };
7 + };
8 +};
t/t4018/dts-nodes-comment2 new
+8
@@ -0,0 +1,8 @@
1 +/ {
2 + label_1: node1@ff00 {
3 + RIGHT@deadf00,4000 { /* a trailing comment */
4 + #size-cells = <1>;
5 + ChangeMe = <0xffeedd00>;
6 + };
7 + };
8 +};
t/t4018/dts-reference new
+9
@@ -0,0 +1,9 @@
1 +&label_1 {
2 + TEST = <455>;
3 +};
4 +
5 +&RIGHT {
6 + vendor,some-property;
7 +
8 + ChangeMe = <0x45-30>;
9 +};
t/t4018/dts-root new
+5
@@ -0,0 +1,5 @@
1 +/RIGHT { /* Technically just supposed to be a slash */
2 + #size-cells = <1>;
3 +
4 + ChangeMe = <0xffeedd00>;
5 +};
t/t4034-diff-words.sh
+1
@@ -303,6 +303,7 @@ test_language_driver bibtex
303 test_language_driver cpp
304 test_language_driver csharp
305 test_language_driver css
306 +test_language_driver dts
307 test_language_driver fortran
308 test_language_driver html
309 test_language_driver java
t/t4034/dts/expect new
+37
@@ -0,0 +1,37 @@
1 +<BOLD>diff --git a/pre b/post<RESET>
2 +<BOLD>index b6a9051..7803aee 100644<RESET>
3 +<BOLD>--- a/pre<RESET>
4 +<BOLD>+++ b/post<RESET>
5 +<CYAN>@@ -1,32 +1,32 @@<RESET>
6 +/ {<RESET>
7 + <RED>this_handle<RESET><GREEN>HANDLE_2<RESET>: <RED>node<RESET><GREEN>new-node<RESET>@<RED>f00<RESET><GREEN>eeda<RESET> {
8 + compatible = "<RED>mydev<RESET><GREEN>vendor,compat<RESET>";
9 + string-prop = <RED>start<RESET><GREEN>end<RESET>: "hello <RED>world!<RESET><GREEN>world?<RESET>" <RED>end<RESET><GREEN>start<RESET>: ;
10 + <RED>#size-cells<RESET><GREEN>#address-cells<RESET> = <<RED>0+0<RESET><GREEN>0+40<RESET>>;
11 + reg = <<RED>0xf00<RESET><GREEN>0xeeda<RESET>>;
12 + prop = <<GREEN>(<RESET>1<GREEN>)<RESET>>;
13 + prop = <<GREEN>(<RESET>-1e10<GREEN>)<RESET>>;
14 + prop = <(!<RED>3<RESET><GREEN>1<RESET>)>;
15 + prop = <(~<RED>3<RESET><GREEN>1<RESET>)>;
16 + prop = <(<RED>3<RESET><GREEN>1<RESET>*<RED>4<RESET><GREEN>2<RESET>)>;
17 + prop = <(<RED>3<RESET><GREEN>1<RESET>&<RED>4<RESET><GREEN>2<RESET>)>;
18 + prop = <(<RED>3<RESET><GREEN>1<RESET>*<RED>4<RESET><GREEN>2<RESET>)>;
19 + prop = <(<RED>3<RESET><GREEN>1<RESET>/<RED>4<RESET><GREEN>2<RESET>)>;
20 + prop = <(<RED>3<RESET><GREEN>1<RESET>%<RED>4<RESET><GREEN>2<RESET>)>;
21 + prop = <(<RED>3+4<RESET><GREEN>1+2<RESET>)>;
22 + prop = <(<RED>3-4<RESET><GREEN>1-2<RESET>)>;
23 + prop = /bits/ <RED>64<RESET><GREEN>32<RESET> <(<RED>3<RESET><GREEN>1<RESET><<<RED>4<RESET><GREEN>2<RESET>)>;
24 + prop = <(<RED>3<RESET><GREEN>1<RESET>>><RED>4<RESET><GREEN>2<RESET>)>;
25 + prop = <(<RED>3<RESET><GREEN>1<RESET>&<RED>4<RESET><GREEN>2<RESET>)>;
26 + prop = <(<RED>3<RESET><GREEN>1<RESET>^<RED>4<RESET><GREEN>2<RESET>)>;
27 + prop = <(<RED>3<RESET><GREEN>1<RESET>|<RED>4<RESET><GREEN>2<RESET>)>;
28 + prop = <(<RED>3<RESET><GREEN>1<RESET>&&<RED>4<RESET><GREEN>2<RESET>)>;
29 + prop = <(<RED>3<RESET><GREEN>1<RESET>||<RED>4<RESET><GREEN>2<RESET>)>;
30 + prop = <(<RED>4?5<RESET><GREEN>1?2<RESET>:3)>;
31 + list = <&<RED>this_handle<RESET><GREEN>HANDLE_2<RESET>>, <0 0 0 <RED>0<RESET><GREEN>1<RESET>>;
32 + };<RESET>
33 +
34 + &<RED>phandle<RESET><GREEN>phandle2<RESET> {
35 + <RED>pre-phandle<RESET><GREEN>prop_handle<RESET> = <&<RED>this_handle<RESET><GREEN>HANDLE_2<RESET>>;
36 + };<RESET>
37 +};<RESET>
t/t4034/dts/post new
+32
@@ -0,0 +1,32 @@
1 +/ {
2 + HANDLE_2: new-node@eeda {
3 + compatible = "vendor,compat";
4 + string-prop = end: "hello world?" start: ;
5 + #address-cells = <0+40>;
6 + reg = <0xeeda>;
7 + prop = <(1)>;
8 + prop = <(-1e10)>;
9 + prop = <(!1)>;
10 + prop = <(~1)>;
11 + prop = <(1*2)>;
12 + prop = <(1&2)>;
13 + prop = <(1*2)>;
14 + prop = <(1/2)>;
15 + prop = <(1%2)>;
16 + prop = <(1+2)>;
17 + prop = <(1-2)>;
18 + prop = /bits/ 32 <(1<<2)>;
19 + prop = <(1>>2)>;
20 + prop = <(1&2)>;
21 + prop = <(1^2)>;
22 + prop = <(1|2)>;
23 + prop = <(1&&2)>;
24 + prop = <(1||2)>;
25 + prop = <(1?2:3)>;
26 + list = <&HANDLE_2>, <0 0 0 1>;
27 + };
28 +
29 + &phandle2 {
30 + prop_handle = <&HANDLE_2>;
31 + };
32 +};
t/t4034/dts/pre new
+32
@@ -0,0 +1,32 @@
1 +/ {
2 + this_handle: node@f00 {
3 + compatible = "mydev";
4 + string-prop = start: "hello world!" end: ;
5 + #size-cells = <0+0>;
6 + reg = <0xf00>;
7 + prop = <1>;
8 + prop = <-1e10>;
9 + prop = <(!3)>;
10 + prop = <(~3)>;
11 + prop = <(3*4)>;
12 + prop = <(3&4)>;
13 + prop = <(3*4)>;
14 + prop = <(3/4)>;
15 + prop = <(3%4)>;
16 + prop = <(3+4)>;
17 + prop = <(3-4)>;
18 + prop = /bits/ 64 <(3<<4)>;
19 + prop = <(3>>4)>;
20 + prop = <(3&4)>;
21 + prop = <(3^4)>;
22 + prop = <(3|4)>;
23 + prop = <(3&&4)>;
24 + prop = <(3||4)>;
25 + prop = <(4?5:3)>;
26 + list = <&this_handle>, <0 0 0 0>;
27 + };
28 +
29 + &phandle {
30 + pre-phandle = <&this_handle>;
31 + };
32 +};
userdiff.c
+8
@@ -23,6 +23,14 @@ IPATTERN("ada",
23 "[a-zA-Z][a-zA-Z0-9_]*"
24 "|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?"
25 "|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"),
26 +PATTERNS("dts",
27 + "!;\n"
28 + /* lines beginning with a word optionally preceded by '&' or the root */
29 + "^[ \t]*((/|&?[a-zA-Z_]).*)",
30 + /* -- */
31 + /* Property names and math operators */
32 + "[a-zA-Z0-9,._+?#-]+"
33 + "|[-+*/%&^|!~]|>>|<<|&&|\\|\\|"),
34 IPATTERN("fortran",
35 "!^([C*]|[ \t]*!)\n"
36 "!^[ \t]*MODULE[ \t]+PROCEDURE[ \t]\n"