Skip to contentSkip to conversation

userdiff: Add a builtin pattern for dts files

PATCH Superseded Stephen Boyd 4 participants 7 messages Jan 11, 2019 – Jan 17, 2019 Documentation

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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]

[1] https://github.com/devicetree-org/devicetree-specification/releases/latest

---
 Documentation/gitattributes.txt |  2 ++
 t/t4018-diff-funcname.sh        |  1 +
 t/t4018/dts-labels              |  8 +++++++
 t/t4018/dts-node-unitless       |  8 +++++++
 t/t4018/dts-nodes               |  8 +++++++
 t/t4018/dts-reference           |  8 +++++++
 t/t4034-diff-words.sh           |  1 +
 t/t4034/dts/expect              | 37 +++++++++++++++++++++++++++++++++
 t/t4034/dts/post                | 32 ++++++++++++++++++++++++++++
 t/t4034/dts/pre                 | 32 ++++++++++++++++++++++++++++
 userdiff.c                      |  9 ++++++++
 11 files changed, 146 insertions(+)
 create mode 100644 t/t4018/dts-labels
 create mode 100644 t/t4018/dts-node-unitless
 create mode 100644 t/t4018/dts-nodes
 create mode 100644 t/t4018/dts-reference
 create mode 100644 t/t4034/dts/expect
 create mode 100644 t/t4034/dts/post
 create mode 100644 t/t4034/dts/pre
Documentation/gitattributes.txt +2 -0
index b8392fc3300c..14e5784b962d 100644
@@ -805,6 +805,8 @@ patterns are available:
 
 - `css` suitable for cascading style sheets.
 
+- `dts` suitable for devicetree (DTS) files.
+
 - `fortran` suitable for source code in the Fortran language.
 
 - `fountain` suitable for Fountain documents.
t/t4018-diff-funcname.sh +1 -0
index 22f9f88f0afc..8acd04b206d4 100755
@@ -31,6 +31,7 @@ diffpatterns="
 	cpp
 	csharp
 	css
+	dts
 	fortran
 	fountain
 	golang
t/t4018/dts-labels new file +8 -0
new file mode 100644
index 000000000000..27cd4921cfb6
@@ -0,0 +1,8 @@
+/ {
+	label_1: node1@ff00 {
+		label2: RIGHT {
+			vendor,some-property;
+			ChangeMe = <0x45-30>;
+		};
+	};
+};
t/t4018/dts-node-unitless new file +8 -0
new file mode 100644
index 000000000000..c5287d91416e
@@ -0,0 +1,8 @@
+/ {
+	label_1: node1 {
+		RIGHT {
+			prop-array = <1>, <4>;
+			ChangeMe = <0xffeedd00>;
+		};
+	};
+};
t/t4018/dts-nodes new file +8 -0
new file mode 100644
index 000000000000..5a4334bb1645
@@ -0,0 +1,8 @@
+/ {
+	label_1: node1@ff00 {
+		RIGHT@deadf00,4000 {
+			#size-cells = <1>;
+			ChangeMe = <0xffeedd00>;
+		};
+	};
+};
t/t4018/dts-reference new file +8 -0
new file mode 100644
index 000000000000..f115d4291d25
@@ -0,0 +1,8 @@
+&label_1 {
+	TEST = <455>;
+};
+
+&RIGHT {
+	vendor,some-property;
+	ChangeMe = <0x45-30>;
+};
t/t4034-diff-words.sh +1 -0
index 912df91226f2..9a93c2a3e0dd 100755
@@ -303,6 +303,7 @@ test_language_driver bibtex
 test_language_driver cpp
 test_language_driver csharp
 test_language_driver css
+test_language_driver dts
 test_language_driver fortran
 test_language_driver html
 test_language_driver java
t/t4034/dts/expect new file +37 -0
new file mode 100644
index 000000000000..ed6ad9c65f8b
@@ -0,0 +1,37 @@
+<BOLD>diff --git a/pre b/post<RESET>
+<BOLD>index ce95e99..7803aee 100644<RESET>
+<BOLD>--- a/pre<RESET>
+<BOLD>+++ b/post<RESET>
+<CYAN>@@ -1,32 +1,32 @@<RESET>
+/ {<RESET>
+	<RED>this_handle<RESET><GREEN>HANDLE_2<RESET>: <RED>node<RESET><GREEN>new-node<RESET>@<RED>f00<RESET><GREEN>eeda<RESET> {
+		compatible = "<RED>mydev<RESET><GREEN>vendor,compat<RESET>";
+		string-prop = <RED>start<RESET><GREEN>end<RESET>: "hello <RED>world!<RESET><GREEN>world?<RESET>" <RED>end<RESET><GREEN>start<RESET>: ;
+		<RED>#size-cells<RESET><GREEN>#address-cells<RESET> = <<RED>0+0<RESET><GREEN>0+40<RESET>>;
+		reg = <<RED>0xf00<RESET><GREEN>0xeeda<RESET>>;
+		prop = <<GREEN>(<RESET>1<GREEN>)<RESET>>;
+		prop = <<GREEN>(<RESET>-1e10<GREEN>)<RESET>>;
+		prop = <(!<RED>3<RESET><GREEN>1<RESET>)>;
+		prop = <(~<RED>3<RESET><GREEN>1<RESET>)>;
+		prop = <(<RED>3<RESET><GREEN>1<RESET>*<RED>4<RESET><GREEN>2<RESET>)>;
+		prop = <(<RED>3<RESET><GREEN>1<RESET>&<RED>4<RESET><GREEN>2<RESET>)>;
+		prop = <(<RED>3<RESET><GREEN>1<RESET>*<RED>4<RESET><GREEN>2<RESET>)>;
+		prop = <(<RED>3<RESET><GREEN>1<RESET>/<RED>4<RESET><GREEN>2<RESET>)>;
+		prop = <(<RED>3<RESET><GREEN>1<RESET>%<RED>4<RESET><GREEN>2<RESET>)>;
+		prop = <(<RED>3+4<RESET><GREEN>1+2<RESET>)>;
+		prop = <(<RED>3-4<RESET><GREEN>1-2<RESET>)>;
+		prop = /bits/ <RED>64<RESET><GREEN>32<RESET> <(<RED>3<RESET><GREEN>1<RESET><<<RED>4<RESET><GREEN>2<RESET>)>;
+		prop = <(<RED>3<RESET><GREEN>1<RESET>>><RED>4<RESET><GREEN>2<RESET>)>;
+		prop = <(<RED>3<RESET><GREEN>1<RESET>&<RED>4<RESET><GREEN>2<RESET>)>;
+		prop = <(<RED>3<RESET><GREEN>1<RESET>^<RED>4<RESET><GREEN>2<RESET>)>;
+		prop = <(<RED>3<RESET><GREEN>1<RESET>|<RED>4<RESET><GREEN>2<RESET>)>;
+		prop = <(<RED>3<RESET><GREEN>1<RESET>&&<RED>4<RESET><GREEN>2<RESET>)>;
+		prop = <(<RED>3<RESET><GREEN>1<RESET>||<RED>4<RESET><GREEN>2<RESET>)>;
+		prop = <(<RED>4?5<RESET><GREEN>1?2<RESET>:<RED>6<RESET><GREEN>3<RESET>)>;
+		list = <&<RED>this_handle<RESET><GREEN>HANDLE_2<RESET>>, <0 0 0 <RED>0<RESET><GREEN>1<RESET>>;
+	};<RESET>
+
+	&<RED>phandle<RESET><GREEN>phandle2<RESET> {
+		<RED>pre-phandle<RESET><GREEN>prop_handle<RESET> = <&<RED>this_handle<RESET><GREEN>HANDLE_2<RESET>>;
+	};<RESET>
+};<RESET>
t/t4034/dts/post new file +32 -0
new file mode 100644
index 000000000000..7803aee28093
@@ -0,0 +1,32 @@
+/ {
+	HANDLE_2: new-node@eeda {
+		compatible = "vendor,compat";
+		string-prop = end: "hello world?" start: ;
+		#address-cells = <0+40>;
+		reg = <0xeeda>;
+		prop = <(1)>;
+		prop = <(-1e10)>;
+		prop = <(!1)>;
+		prop = <(~1)>;
+		prop = <(1*2)>;
+		prop = <(1&2)>;
+		prop = <(1*2)>;
+		prop = <(1/2)>;
+		prop = <(1%2)>;
+		prop = <(1+2)>;
+		prop = <(1-2)>;
+		prop = /bits/ 32 <(1<<2)>;
+		prop = <(1>>2)>;
+		prop = <(1&2)>;
+		prop = <(1^2)>;
+		prop = <(1|2)>;
+		prop = <(1&&2)>;
+		prop = <(1||2)>;
+		prop = <(1?2:3)>;
+		list = <&HANDLE_2>, <0 0 0 1>;
+	};
+
+	&phandle2 {
+		prop_handle = <&HANDLE_2>;
+	};
+};
t/t4034/dts/pre new file +32 -0
new file mode 100644
index 000000000000..ce95e993ec93
@@ -0,0 +1,32 @@
+/ {
+	this_handle: node@f00 {
+		compatible = "mydev";
+		string-prop = start: "hello world!" end: ;
+		#size-cells = <0+0>;
+		reg = <0xf00>;
+		prop = <1>;
+		prop = <-1e10>;
+		prop = <(!3)>;
+		prop = <(~3)>;
+		prop = <(3*4)>;
+		prop = <(3&4)>;
+		prop = <(3*4)>;
+		prop = <(3/4)>;
+		prop = <(3%4)>;
+		prop = <(3+4)>;
+		prop = <(3-4)>;
+		prop = /bits/ 64 <(3<<4)>;
+		prop = <(3>>4)>;
+		prop = <(3&4)>;
+		prop = <(3^4)>;
+		prop = <(3|4)>;
+		prop = <(3&&4)>;
+		prop = <(3||4)>;
+		prop = <(4?5:6)>;
+		list = <&this_handle>, <0 0 0 0>;
+	};
+
+	&phandle {
+		pre-phandle = <&this_handle>;
+	};
+};
userdiff.c +9 -0
index 97007abe5b16..2bc964e11089 100644
@@ -23,6 +23,15 @@ IPATTERN("ada",
 	 "[a-zA-Z][a-zA-Z0-9_]*"
 	 "|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?"
 	 "|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"),
+PATTERNS("dts",
+	 /* Node name (with optional label and unit address) */
+	 "^[ \t]*((([a-zA-Z_][a-zA-Z0-9_]*: )?[a-zA-Z][a-zA-Z0-9,._+-]*(@[a-zA-Z0-9,._+-]+)?"
+	 /* Reference */
+	 "|&[a-zA-Z_][a-zA-Z0-9_]*[ \t]*)[ \t]*\\{)[ \t]*$",
+	 /* -- */
+	 /* Property names and math operators */
+	 "[a-zA-Z0-9,._+?#-]+"
+	 "|[-+*/%&^|!~]"),
 IPATTERN("fortran",
 	 "!^([C*]|[ \t]*!)\n"
 	 "!^[ \t]*MODULE[ \t]+PROCEDURE[ \t]\n"
Signature · 1 line
Sent by a computer through tubes
#1 lore raw

Hi Stephen,

thank you for your patch. I left a few comments below.

Le 11/01/2019 à 22:51, Stephen Boyd a écrit :

Quoted 47 lines

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]

[1] https://github.com/devicetree-org/devicetree-specification/releases/latest

---
 Documentation/gitattributes.txt |  2 ++
 t/t4018-diff-funcname.sh        |  1 +
 t/t4018/dts-labels              |  8 +++++++
 t/t4018/dts-node-unitless       |  8 +++++++
 t/t4018/dts-nodes               |  8 +++++++
 t/t4018/dts-reference           |  8 +++++++
 t/t4034-diff-words.sh           |  1 +
 t/t4034/dts/expect              | 37 +++++++++++++++++++++++++++++++++
 t/t4034/dts/post                | 32 ++++++++++++++++++++++++++++
 t/t4034/dts/pre                 | 32 ++++++++++++++++++++++++++++
 userdiff.c                      |  9 ++++++++
 11 files changed, 146 insertions(+)
 create mode 100644 t/t4018/dts-labels
 create mode 100644 t/t4018/dts-node-unitless
 create mode 100644 t/t4018/dts-nodes
 create mode 100644 t/t4018/dts-reference
 create mode 100644 t/t4034/dts/expect
 create mode 100644 t/t4034/dts/post
 create mode 100644 t/t4034/dts/pre

-%<-

userdiff.c +3 -0
index 97007abe5b16..2bc964e11089 100644
@@ -23,6 +23,15 @@ IPATTERN("ada",
 	 "[a-zA-Z][a-zA-Z0-9_]*"
 	 "|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?"
 	 "|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"),
+PATTERNS("dts",
+	 /* Node name (with optional label and unit address) */
+	 "^[ \t]*((([a-zA-Z_][a-zA-Z0-9_]*: )?[a-zA-Z][a-zA-Z0-9,._+-]*(@[a-zA-Z0-9,._+-]+)?"
 
Quoted 1 line

From the spec, label and node names “shall be [between] 1 to 31

characters in length”. It’s not enforced here, and I guess it’s not really git’s job to check for this kind of rule. Others may disagree with me, though.

Should labels end with exactly one space after the colon, or can there be more, or none at all?

userdiff.c IPATTERN("ada", · line 30

Quoted 2 lines
userdiff.c +2 -0
+	 /* Reference */
+	 "|&[a-zA-Z_][a-zA-Z0-9_]*[ \t]*)[ \t]*\\{)[ \t]*$",

It’s not specified in the spec, but these lines must end with a curly brace? What if there is a comment after the curly brace?

This pattern does not match the root node, but I guess it’s not important as most of the interesting stuff in a dts is not directly in it.

userdiff.c IPATTERN("ada", · line 34

Quoted 4 lines
userdiff.c +4 -0
+	 /* -- */
+	 /* Property names and math operators */
+	 "[a-zA-Z0-9,._+?#-]+"
+	 "|[-+*/%&^|!~]"),

There is a `%' operator here and in your tests, but it’s not mentioned in the spec if I’m not mistaken. Does it actually exists?

userdiff.c IPATTERN("ada", · line 37

Quoted 4 lines

IPATTERN("fortran",

userdiff.c +0 -0
 	 "!^([C*]|[ \t]*!)\n"
 	 "!^[ \t]*MODULE[ \t]+PROCEDURE[ \t]\n"

Cheers,
Alban

#2 lore raw
Quoted 9 lines · Alban Gruin

thank you for your patch. I left a few comments below.

Quoted 6 lines · Stephen Boyd

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.

A sort of meta-question.

What is missing in the current git that prevents the folks involved in device-tree project from achieving what this patch tries to accomplish without having to wait the Git project to act on it? To put it another way, is it a symptom of a bad design that from time to time the Git project has to add built-in patterns?

Ability to ship arbitrary piece of text that you would normally place in .git/config is not exactly an answer to the above question, and will not happen as that has grave security implications.

But perhaps we can start accepting an in-tree config-like file whose contents are limited to verified-safe settings
(e.g. "diff.*.xfuncname" and nothing else), so that projects can ship two files in-tree:

- ".gitattributes" that says "*.dts diff=dts"

- ".gitpreferences" that says "[diff "dts"] xfuncname=..." to define the pattern the patch under review adds.

without waiting for the next release of Git to add one more built-in pattern?

Anything that defines executable (e.g. "diff.*.command") should never be accepted as part of the in-tree config-like file (for two
reasons: security and portability), but there should be some "obviously safe" subset of config settings that we can allow project to impose on its users, I hope.

#4 lore raw
In reply to Alban Gruin

Quoting Alban Gruin (2019-01-13 13:26:21)

Quoted 5 lines

Hi Stephen,
=20
thank you for your patch. I left a few comments below. =20
Le 11/01/2019 =C3=A0 22:51, Stephen Boyd a =C3=A9crit=C2=A0:

Quoted 11 lines

userdiff.c IPATTERN("ada", · line 28

Quoted 11 lines
userdiff.c +3 -0
index 97007abe5b16..2bc964e11089 100644
@@ -23,6 +23,15 @@ IPATTERN("ada",
       "[a-zA-Z][a-zA-Z0-9_]*"
       "|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?"
       "|=3D>|\\.\\.|\\*\\*|:=3D|/=3D|>=3D|<=3D|<<|>>|<>"),
+PATTERNS("dts",
+      /* Node name (with optional label and unit address) */
+      "^[ \t]*((([a-zA-Z_][a-zA-Z0-9_]*: )?[a-zA-Z][a-zA-Z0-9,._+-]*(@=

[a-zA-Z0-9,._+-]+)?"

Quoted 3 lines

=20
From the spec, label and node names =E2=80=9Cshall be [between] 1 to 31 characters in length=E2=80=9D. It=E2=80=99s not enforced here, and I gue=

ss it=E2=80=99s not

Quoted 1 line

really git=E2=80=99s job to check for this kind of rule. Others may disa=

gree

Quoted 4 lines

with me, though.
=20
Should labels end with exactly one space after the colon, or can there be more, or none at all?

There can be any number of spaces after the colon. I can fix the regex here to accept any amount of whitespace after the colon.

Quoted 5 lines

=20

userdiff.c IPATTERN("ada", · line 30

Quoted 2 lines
userdiff.c +2 -0
+      /* Reference */
+      "|&[a-zA-Z_][a-zA-Z0-9_]*[ \t]*)[ \t]*\\{)[ \t]*$",

=20
It=E2=80=99s not specified in the spec, but these lines must end with a c=

urly

Quoted 1 line

brace? =20

That isn't common but it is supported. I can change the regex to look for a line that ends in '{' or something that isn't ';' with anything after the node name?

Quoted 1 line

What if there is a comment after the curly brace?

There can be a comment after the curly brace or before the curly brace. The spec allows C style /* */ type comments, in addition to C++ style // comments. I've never really seen that happen in practice though so it's not very common. Grepping the linux sources shows two hits:

arch/arm/boot/dts/lpc3250-ea3250.dts:&ohci /* &usbd */ { arch/arm/boot/dts/lpc3250-phy3250.dts:&ohci /* &usbd */ {

Quoted 3 lines

=20
This pattern does not match the root node, but I guess it=E2=80=99s not important as most of the interesting stuff in a dts is not directly in it.

Agreed.

Quoted 7 lines

=20

userdiff.c IPATTERN("ada", · line 34

Quoted 4 lines
userdiff.c +4 -0
+      /* -- */
+      /* Property names and math operators */
+      "[a-zA-Z0-9,._+?#-]+"
+      "|[-+*/%&^|!~]"),

=20
There is a `%' operator here and in your tests, but it=E2=80=99s not ment=

ioned

Quoted 1 line

in the spec if I=E2=80=99m not mistaken. Does it actually exists?

The compiler doesn't seem to complain when it's used. I can send a patch to update the spec for this rather esoteric feature. I can also include more tests and support for the boolean relational operators which also seem to be supported but probably never used.

#3 lore raw
In reply to Junio C Hamano

Hi Junio,

Le 14/01/2019 à 19:34, Junio C Hamano a écrit :

Quoted 34 lines
Quoted 9 lines · Alban Gruin

thank you for your patch. I left a few comments below.

Quoted 6 lines · Stephen Boyd

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.

A sort of meta-question.

What is missing in the current git that prevents the folks involved in device-tree project from achieving what this patch tries to accomplish without having to wait the Git project to act on it? To put it another way, is it a symptom of a bad design that from time to time the Git project has to add built-in patterns?

Ability to ship arbitrary piece of text that you would normally place in .git/config is not exactly an answer to the above question, and will not happen as that has grave security implications.

But perhaps we can start accepting an in-tree config-like file whose contents are limited to verified-safe settings
(e.g. "diff.*.xfuncname" and nothing else), so that projects can ship two files in-tree:

- ".gitattributes" that says "*.dts diff=dts"

- ".gitpreferences" that says "[diff "dts"] xfuncname=..." to define the pattern the patch under review adds.

Quoted 9 lines

without waiting for the next release of Git to add one more built-in pattern?

Anything that defines executable (e.g. "diff.*.command") should never be accepted as part of the in-tree config-like file (for two
reasons: security and portability), but there should be some "obviously safe" subset of config settings that we can allow project to impose on its users, I hope.

I really don’t know what to think about this. I like your proposal, but it will take some time to write such a feature, while there is a patch almost ready to support the dts syntax. But I guess that if it is merged, it will be nearly-impossible to remove from the source if a feature like you proposed is eventually implemented.

#5 lore raw
In reply to Stephen Boyd

Hi, sorry for the late answer.

Le 14/01/2019 à 19:34, Stephen Boyd a écrit :

Quoted 42 lines

Quoting Alban Gruin (2019-01-13 13:26:21)

Quoted 22 lines

Hi Stephen,

thank you for your patch. I left a few comments below.

Le 11/01/2019 à 22:51, Stephen Boyd a écrit :

userdiff.c IPATTERN("ada", · line 28

Quoted 11 lines
userdiff.c +3 -0
index 97007abe5b16..2bc964e11089 100644
@@ -23,6 +23,15 @@ IPATTERN("ada",
       "[a-zA-Z][a-zA-Z0-9_]*"
       "|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?"
       "|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"),
+PATTERNS("dts",
+      /* Node name (with optional label and unit address) */
+      "^[ \t]*((([a-zA-Z_][a-zA-Z0-9_]*: )?[a-zA-Z][a-zA-Z0-9,._+-]*(@[a-zA-Z0-9,._+-]+)?"

From the spec, label and node names “shall be [between] 1 to 31 characters in length”. It’s not enforced here, and I guess it’s not really git’s job to check for this kind of rule. Others may disagree with me, though.

Quoted 2 lines

Should labels end with exactly one space after the colon, or can there be more, or none at all?

There can be any number of spaces after the colon. I can fix the regex here to accept any amount of whitespace after the colon.

Quoted 6 lines

userdiff.c IPATTERN("ada", · line 30

Quoted 3 lines
userdiff.c +2 -0
+      /* Reference */
+      "|&[a-zA-Z_][a-zA-Z0-9_]*[ \t]*)[ \t]*\\{)[ \t]*$",

It’s not specified in the spec, but these lines must end with a curly brace?

That isn't common but it is supported. I can change the regex to look for a line that ends in '{' or something that isn't ';' with anything after the node name?

Quoted 1 line

What if there is a comment after the curly brace?

Quoted 8 lines

There can be a comment after the curly brace or before the curly brace. The spec allows C style /* */ type comments, in addition to C++ style // comments. I've never really seen that happen in practice though so it's not very common. Grepping the linux sources shows two hits:

arch/arm/boot/dts/lpc3250-ea3250.dts:&ohci /* &usbd */ { arch/arm/boot/dts/lpc3250-phy3250.dts:&ohci /* &usbd */ {

I grepped through Linux and uboot’s sources and it seems that “it is not common” is actually “it does not exists in the wild”. Perhaps it’s not worth to support them.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
userdiff.c +4 -0
+      /* -- */
+      /* Property names and math operators */
+      "[a-zA-Z0-9,._+?#-]+"
+      "|[-+*/%&^|!~]"),
Quoted 8 lines
Quoted 2 lines

There is a `%' operator here and in your tests, but it’s not mentioned in the spec if I’m not mistaken. Does it actually exists?

The compiler doesn't seem to complain when it's used. I can send a patch to update the spec for this rather esoteric feature. I can also include more tests and support for the boolean relational operators which also seem to be supported but probably never used.

I’d like you to do this, yes.

To be fair, I don’t know what to think about this patch after Junio’s message.

#6 lore raw
In reply to Alban Gruin
Quoted 49 lines · Alban Gruin

Hi Stephen,

thank you for your patch. I left a few comments below.

Quoted 43 lines · Stephen Boyd

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]

[1] https://github.com/devicetree-org/devicetree-specification/releases/latest

---
 Documentation/gitattributes.txt |  2 ++
 t/t4018-diff-funcname.sh        |  1 +
 t/t4018/dts-labels              |  8 +++++++
 t/t4018/dts-node-unitless       |  8 +++++++
 t/t4018/dts-nodes               |  8 +++++++
 t/t4018/dts-reference           |  8 +++++++
 t/t4034-diff-words.sh           |  1 +
 t/t4034/dts/expect              | 37 +++++++++++++++++++++++++++++++++
 t/t4034/dts/post                | 32 ++++++++++++++++++++++++++++
 t/t4034/dts/pre                 | 32 ++++++++++++++++++++++++++++
 userdiff.c                      |  9 ++++++++
 11 files changed, 146 insertions(+)
 create mode 100644 t/t4018/dts-labels
 create mode 100644 t/t4018/dts-node-unitless
 create mode 100644 t/t4018/dts-nodes
 create mode 100644 t/t4018/dts-reference
 create mode 100644 t/t4034/dts/expect
 create mode 100644 t/t4034/dts/post
 create mode 100644 t/t4034/dts/pre

-%<-

userdiff.c +0 -0
index 97007abe5b16..2bc964e11089 100644
@@ -23,6 +23,15 @@ IPATTERN("ada",
       "[a-zA-Z][a-zA-Z0-9_]*"
       "|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?"
       "|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"),
Quoted 8 lines

userdiff.c IPATTERN("ada", · line 28

Quoted 3 lines
userdiff.c +3 -0
+PATTERNS("dts",
+      /* Node name (with optional label and unit address) */
+      "^[ \t]*((([a-zA-Z_][a-zA-Z0-9_]*: )?[a-zA-Z][a-zA-Z0-9,._+-]*(@[a-zA-Z0-9,._+-]+)?"

From the spec, label and node names “shall be [between] 1 to 31 characters in length”. It’s not enforced here, and I guess it’s not really git’s job to check for this kind of rule. Others may disagree with me, though.

The spec does say 31 characters, but that's never been enforced. So, of course, there are occurrences in the wild (though maybe they were just property names, not node names). In any case, we plan to change the spec to increase the size. To what, I don't know.

Rob