{"thread":{"id":"51683","subject":"[PATCH v3] userdiff: Add a builtin pattern for dts files","startedAt":"2019-08-19T21:22:46Z","lastAt":"2019-08-19T21:22:46Z","messageCount":1,"participants":["Stephen Boyd"],"isPatch":true,"patchVersion":3,"patchTotal":null},"messages":[{"id":"380736","messageId":"20190819212243.84492-1-sboyd@kernel.org","threadId":"51683","inReplyTo":null,"subject":"[PATCH v3] userdiff: Add a builtin pattern for dts files","fromName":"Stephen Boyd","fromEmail":"sboyd@kernel.org","sentAt":"2019-08-19T21:22:43Z","receivedAt":"2019-08-19T21:22:46Z","isPatch":true,"sender":{"key":"sboyd@kernel.org","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"The Linux kernel receives many patches to the devicetree files each\nrelease. The hunk header for those patches typically show nothing,\nmaking it difficult to figure out what node is being modified without\napplying the patch or opening the file and seeking to the context. Let's\nadd a builtin 'dts' pattern to git so that users can get better diff\noutput on dts files when they use the diff=dts driver.\n\nThe regex has been constructed based on the spec at devicetree.org[1]\nand with some help from Johannes Sixt.\n\n[1] https://github.com/devicetree-org/devicetree-specification/releases/latest\n\nCc: Rob Herring <robh+dt@kernel.org>\nCc: Frank Rowand <frowand.list@gmail.com>\nSigned-off-by: Stephen Boyd <sboyd@kernel.org>\n---\n\nChanges from v2:\n * Added a few more tests for comments after and before {\n * Added a root node test\n * Support for root node (/) in the regex\n * Simplified regex per Johannes' feedback\n * Sprinkled some newlines into the tests for variety\n\nChanges from v1:                                                                                                                                                                    \n * Updated regex to handle anything after node names instead of                                                                                                                     \n   requiring a '{'                                                                                                                                                                  \n * Updated test for boolean relation operators                                                                                                                                      \n * Sent out a patch to devicetree spec to document % operator                                                                                                                       \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t     \n Documentation/gitattributes.txt |  2 ++\n t/t4018-diff-funcname.sh        |  1 +\n t/t4018/dts-labels              |  9 ++++++++\n t/t4018/dts-node-unitless       |  8 +++++++\n t/t4018/dts-nodes               |  8 +++++++\n t/t4018/dts-nodes-comment1      |  8 +++++++\n t/t4018/dts-nodes-comment2      |  8 +++++++\n t/t4018/dts-reference           |  9 ++++++++\n t/t4018/dts-root                |  5 +++++\n t/t4034-diff-words.sh           |  1 +\n t/t4034/dts/expect              | 37 +++++++++++++++++++++++++++++++++\n t/t4034/dts/post                | 32 ++++++++++++++++++++++++++++\n t/t4034/dts/pre                 | 32 ++++++++++++++++++++++++++++\n userdiff.c                      |  8 +++++++\n 14 files changed, 168 insertions(+)\n create mode 100644 t/t4018/dts-labels\n create mode 100644 t/t4018/dts-node-unitless\n create mode 100644 t/t4018/dts-nodes\n create mode 100644 t/t4018/dts-nodes-comment1\n create mode 100644 t/t4018/dts-nodes-comment2\n create mode 100644 t/t4018/dts-reference\n create mode 100644 t/t4018/dts-root\n create mode 100644 t/t4034/dts/expect\n create mode 100644 t/t4034/dts/post\n create mode 100644 t/t4034/dts/pre\n\ndiff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt\nindex fb1d188d440c..c5a528c667b6 100644\n--- a/Documentation/gitattributes.txt\n+++ b/Documentation/gitattributes.txt\n@@ -810,6 +810,8 @@ patterns are available:\n \n - `css` suitable for cascading style sheets.\n \n+- `dts` suitable for devicetree (DTS) files.\n+\n - `fortran` suitable for source code in the Fortran language.\n \n - `fountain` suitable for Fountain documents.\ndiff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh\nindex 9261d6d3a000..6f5ef0035e92 100755\n--- a/t/t4018-diff-funcname.sh\n+++ b/t/t4018-diff-funcname.sh\n@@ -31,6 +31,7 @@ diffpatterns=\"\n \tcpp\n \tcsharp\n \tcss\n+\tdts\n \tfortran\n \tfountain\n \tgolang\ndiff --git a/t/t4018/dts-labels b/t/t4018/dts-labels\nnew file mode 100644\nindex 000000000000..b21ef8737bb8\n--- /dev/null\n+++ b/t/t4018/dts-labels\n@@ -0,0 +1,9 @@\n+/ {\n+\tlabel_1: node1@ff00 {\n+\t\tlabel2: RIGHT {\n+\t\t\tvendor,some-property;\n+\n+\t\t\tChangeMe = <0x45-30>;\n+\t\t};\n+\t};\n+};\ndiff --git a/t/t4018/dts-node-unitless b/t/t4018/dts-node-unitless\nnew file mode 100644\nindex 000000000000..c5287d91416e\n--- /dev/null\n+++ b/t/t4018/dts-node-unitless\n@@ -0,0 +1,8 @@\n+/ {\n+\tlabel_1: node1 {\n+\t\tRIGHT {\n+\t\t\tprop-array = <1>, <4>;\n+\t\t\tChangeMe = <0xffeedd00>;\n+\t\t};\n+\t};\n+};\ndiff --git a/t/t4018/dts-nodes b/t/t4018/dts-nodes\nnew file mode 100644\nindex 000000000000..5a4334bb1645\n--- /dev/null\n+++ b/t/t4018/dts-nodes\n@@ -0,0 +1,8 @@\n+/ {\n+\tlabel_1: node1@ff00 {\n+\t\tRIGHT@deadf00,4000 {\n+\t\t\t#size-cells = <1>;\n+\t\t\tChangeMe = <0xffeedd00>;\n+\t\t};\n+\t};\n+};\ndiff --git a/t/t4018/dts-nodes-comment1 b/t/t4018/dts-nodes-comment1\nnew file mode 100644\nindex 000000000000..559dfce9b308\n--- /dev/null\n+++ b/t/t4018/dts-nodes-comment1\n@@ -0,0 +1,8 @@\n+/ {\n+\tlabel_1: node1@ff00 {\n+\t\tRIGHT@deadf00,4000 /* &a comment */ {\n+\t\t\t#size-cells = <1>;\n+\t\t\tChangeMe = <0xffeedd00>;\n+\t\t};\n+\t};\n+};\ndiff --git a/t/t4018/dts-nodes-comment2 b/t/t4018/dts-nodes-comment2\nnew file mode 100644\nindex 000000000000..27e9718b31cf\n--- /dev/null\n+++ b/t/t4018/dts-nodes-comment2\n@@ -0,0 +1,8 @@\n+/ {\n+\tlabel_1: node1@ff00 {\n+\t\tRIGHT@deadf00,4000 { /* a trailing comment */ \n+\t\t\t#size-cells = <1>;\n+\t\t\tChangeMe = <0xffeedd00>;\n+\t\t};\n+\t};\n+};\ndiff --git a/t/t4018/dts-reference b/t/t4018/dts-reference\nnew file mode 100644\nindex 000000000000..8f0c87d8637f\n--- /dev/null\n+++ b/t/t4018/dts-reference\n@@ -0,0 +1,9 @@\n+&label_1 {\n+\tTEST = <455>;\n+};\n+\n+&RIGHT {\n+\tvendor,some-property;\n+\n+\tChangeMe = <0x45-30>;\n+};\ndiff --git a/t/t4018/dts-root b/t/t4018/dts-root\nnew file mode 100644\nindex 000000000000..2ef9e6ffaa2c\n--- /dev/null\n+++ b/t/t4018/dts-root\n@@ -0,0 +1,5 @@\n+/RIGHT { /* Technically just supposed to be a slash */\n+\t#size-cells = <1>;\n+\n+\tChangeMe = <0xffeedd00>;\n+};\ndiff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh\nindex 912df91226f2..9a93c2a3e0dd 100755\n--- a/t/t4034-diff-words.sh\n+++ b/t/t4034-diff-words.sh\n@@ -303,6 +303,7 @@ test_language_driver bibtex\n test_language_driver cpp\n test_language_driver csharp\n test_language_driver css\n+test_language_driver dts\n test_language_driver fortran\n test_language_driver html\n test_language_driver java\ndiff --git a/t/t4034/dts/expect b/t/t4034/dts/expect\nnew file mode 100644\nindex 000000000000..560fc9918476\n--- /dev/null\n+++ b/t/t4034/dts/expect\n@@ -0,0 +1,37 @@\n+<BOLD>diff --git a/pre b/post<RESET>\n+<BOLD>index b6a9051..7803aee 100644<RESET>\n+<BOLD>--- a/pre<RESET>\n+<BOLD>+++ b/post<RESET>\n+<CYAN>@@ -1,32 +1,32 @@<RESET>\n+/ {<RESET>\n+\t<RED>this_handle<RESET><GREEN>HANDLE_2<RESET>: <RED>node<RESET><GREEN>new-node<RESET>@<RED>f00<RESET><GREEN>eeda<RESET> {\n+\t\tcompatible = \"<RED>mydev<RESET><GREEN>vendor,compat<RESET>\";\n+\t\tstring-prop = <RED>start<RESET><GREEN>end<RESET>: \"hello <RED>world!<RESET><GREEN>world?<RESET>\" <RED>end<RESET><GREEN>start<RESET>: ;\n+\t\t<RED>#size-cells<RESET><GREEN>#address-cells<RESET> = <<RED>0+0<RESET><GREEN>0+40<RESET>>;\n+\t\treg = <<RED>0xf00<RESET><GREEN>0xeeda<RESET>>;\n+\t\tprop = <<GREEN>(<RESET>1<GREEN>)<RESET>>;\n+\t\tprop = <<GREEN>(<RESET>-1e10<GREEN>)<RESET>>;\n+\t\tprop = <(!<RED>3<RESET><GREEN>1<RESET>)>;\n+\t\tprop = <(~<RED>3<RESET><GREEN>1<RESET>)>;\n+\t\tprop = <(<RED>3<RESET><GREEN>1<RESET>*<RED>4<RESET><GREEN>2<RESET>)>;\n+\t\tprop = <(<RED>3<RESET><GREEN>1<RESET>&<RED>4<RESET><GREEN>2<RESET>)>;\n+\t\tprop = <(<RED>3<RESET><GREEN>1<RESET>*<RED>4<RESET><GREEN>2<RESET>)>;\n+\t\tprop = <(<RED>3<RESET><GREEN>1<RESET>/<RED>4<RESET><GREEN>2<RESET>)>;\n+\t\tprop = <(<RED>3<RESET><GREEN>1<RESET>%<RED>4<RESET><GREEN>2<RESET>)>;\n+\t\tprop = <(<RED>3+4<RESET><GREEN>1+2<RESET>)>;\n+\t\tprop = <(<RED>3-4<RESET><GREEN>1-2<RESET>)>;\n+\t\tprop = /bits/ <RED>64<RESET><GREEN>32<RESET> <(<RED>3<RESET><GREEN>1<RESET><<<RED>4<RESET><GREEN>2<RESET>)>;\n+\t\tprop = <(<RED>3<RESET><GREEN>1<RESET>>><RED>4<RESET><GREEN>2<RESET>)>;\n+\t\tprop = <(<RED>3<RESET><GREEN>1<RESET>&<RED>4<RESET><GREEN>2<RESET>)>;\n+\t\tprop = <(<RED>3<RESET><GREEN>1<RESET>^<RED>4<RESET><GREEN>2<RESET>)>;\n+\t\tprop = <(<RED>3<RESET><GREEN>1<RESET>|<RED>4<RESET><GREEN>2<RESET>)>;\n+\t\tprop = <(<RED>3<RESET><GREEN>1<RESET>&&<RED>4<RESET><GREEN>2<RESET>)>;\n+\t\tprop = <(<RED>3<RESET><GREEN>1<RESET>||<RED>4<RESET><GREEN>2<RESET>)>;\n+\t\tprop = <(<RED>4?5<RESET><GREEN>1?2<RESET>:3)>;\n+\t\tlist = <&<RED>this_handle<RESET><GREEN>HANDLE_2<RESET>>, <0 0 0 <RED>0<RESET><GREEN>1<RESET>>;\n+\t};<RESET>\n+\n+\t&<RED>phandle<RESET><GREEN>phandle2<RESET> {\n+\t\t<RED>pre-phandle<RESET><GREEN>prop_handle<RESET> = <&<RED>this_handle<RESET><GREEN>HANDLE_2<RESET>>;\n+\t};<RESET>\n+};<RESET>\ndiff --git a/t/t4034/dts/post b/t/t4034/dts/post\nnew file mode 100644\nindex 000000000000..7803aee28093\n--- /dev/null\n+++ b/t/t4034/dts/post\n@@ -0,0 +1,32 @@\n+/ {\n+\tHANDLE_2: new-node@eeda {\n+\t\tcompatible = \"vendor,compat\";\n+\t\tstring-prop = end: \"hello world?\" start: ;\n+\t\t#address-cells = <0+40>;\n+\t\treg = <0xeeda>;\n+\t\tprop = <(1)>;\n+\t\tprop = <(-1e10)>;\n+\t\tprop = <(!1)>;\n+\t\tprop = <(~1)>;\n+\t\tprop = <(1*2)>;\n+\t\tprop = <(1&2)>;\n+\t\tprop = <(1*2)>;\n+\t\tprop = <(1/2)>;\n+\t\tprop = <(1%2)>;\n+\t\tprop = <(1+2)>;\n+\t\tprop = <(1-2)>;\n+\t\tprop = /bits/ 32 <(1<<2)>;\n+\t\tprop = <(1>>2)>;\n+\t\tprop = <(1&2)>;\n+\t\tprop = <(1^2)>;\n+\t\tprop = <(1|2)>;\n+\t\tprop = <(1&&2)>;\n+\t\tprop = <(1||2)>;\n+\t\tprop = <(1?2:3)>;\n+\t\tlist = <&HANDLE_2>, <0 0 0 1>;\n+\t};\n+\n+\t&phandle2 {\n+\t\tprop_handle = <&HANDLE_2>;\n+\t};\n+};\ndiff --git a/t/t4034/dts/pre b/t/t4034/dts/pre\nnew file mode 100644\nindex 000000000000..b6a905113c22\n--- /dev/null\n+++ b/t/t4034/dts/pre\n@@ -0,0 +1,32 @@\n+/ {\n+\tthis_handle: node@f00 {\n+\t\tcompatible = \"mydev\";\n+\t\tstring-prop = start: \"hello world!\" end: ;\n+\t\t#size-cells = <0+0>;\n+\t\treg = <0xf00>;\n+\t\tprop = <1>;\n+\t\tprop = <-1e10>;\n+\t\tprop = <(!3)>;\n+\t\tprop = <(~3)>;\n+\t\tprop = <(3*4)>;\n+\t\tprop = <(3&4)>;\n+\t\tprop = <(3*4)>;\n+\t\tprop = <(3/4)>;\n+\t\tprop = <(3%4)>;\n+\t\tprop = <(3+4)>;\n+\t\tprop = <(3-4)>;\n+\t\tprop = /bits/ 64 <(3<<4)>;\n+\t\tprop = <(3>>4)>;\n+\t\tprop = <(3&4)>;\n+\t\tprop = <(3^4)>;\n+\t\tprop = <(3|4)>;\n+\t\tprop = <(3&&4)>;\n+\t\tprop = <(3||4)>;\n+\t\tprop = <(4?5:3)>;\n+\t\tlist = <&this_handle>, <0 0 0 0>;\n+\t};\n+\n+\t&phandle {\n+\t\tpre-phandle = <&this_handle>;\n+\t};\n+};\ndiff --git a/userdiff.c b/userdiff.c\nindex e74a6d402255..86e3244e15dd 100644\n--- a/userdiff.c\n+++ b/userdiff.c\n@@ -23,6 +23,14 @@ IPATTERN(\"ada\",\n \t \"[a-zA-Z][a-zA-Z0-9_]*\"\n \t \"|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?\"\n \t \"|=>|\\\\.\\\\.|\\\\*\\\\*|:=|/=|>=|<=|<<|>>|<>\"),\n+PATTERNS(\"dts\",\n+\t \"!;\\n\"\n+\t /* lines beginning with a word optionally preceded by '&' or the root */\n+\t \"^[ \\t]*((/|&?[a-zA-Z_]).*)\",\n+\t /* -- */\n+\t /* Property names and math operators */\n+\t \"[a-zA-Z0-9,._+?#-]+\"\n+\t \"|[-+*/%&^|!~]|>>|<<|&&|\\\\|\\\\|\"),\n IPATTERN(\"fortran\",\n \t \"!^([C*]|[ \\t]*!)\\n\"\n \t \"!^[ \\t]*MODULE[ \\t]+PROCEDURE[ \\t]\\n\"\n-- \nSent by a computer through tubes\n\n"}]}