Skip to contentSkip to conversation

userdiff: add builtin driver for INI files

PATCH In review Lucas Seiki Oshiro 2 participants 2 messages Mar 31, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 userdiff: add builtin driver for INI files

Add a new builtin driver for generic INI files (e. g. the gitconfig files), where:

- the funcname regular expression matches section names, i. e. any string between brackets at the beginning of the line, with or without indentation;

- word_regex matches any word with one or more non-whitespace characters without checking if it is a valid variable name or value.

Also add tests for the new userdiff driver. These files define sections and subsections, with and without indentation.

---

The previous versions were more focused on the gitconfig format. This patch generalizes for other INI files, such as the systemd .service files or the Desktop.ini files on Windows.

 t/t4018/ini-section             |  5 +++++
 t/t4018/ini-section-noindent    |  5 +++++
 t/t4018/ini-section-same-line   |  4 ++++
 t/t4018/ini-subsection          | 12 ++++++++++++
 t/t4018/ini-subsection-noindent | 12 ++++++++++++
 userdiff.c                      |  4 ++++
 6 files changed, 42 insertions(+)
 create mode 100644 t/t4018/ini-section
 create mode 100644 t/t4018/ini-section-noindent
 create mode 100644 t/t4018/ini-section-same-line
 create mode 100644 t/t4018/ini-subsection
 create mode 100644 t/t4018/ini-subsection-noindent
t/t4018/ini-section new file +5 -0
new file mode 100644
index 0000000000..c895ad9b4f
@@ -0,0 +1,5 @@
+[RIGHT]
+        # comment
+        ; comment
+        name = value
+        ChangeMe
t/t4018/ini-section-noindent new file +5 -0
new file mode 100644
index 0000000000..733d23c801
@@ -0,0 +1,5 @@
+[RIGHT]
+# comment
+; comment
+name = value
+ChangeMe
t/t4018/ini-section-same-line new file +4 -0
new file mode 100644
index 0000000000..522a1fa4a1
@@ -0,0 +1,4 @@
+[RIGHT] name = value
+        # comment
+        ; comment
+        ChangeMe
t/t4018/ini-subsection new file +12 -0
new file mode 100644
index 0000000000..3d47349e60
@@ -0,0 +1,12 @@
+[LEFT]
+
+      [LEFT "CENTER"]
+      # comment
+      ; comment
+      name = value
+
+      [LEFT "RIGHT"]
+      # comment
+      ; comment
+      name = value
+      ChangeMe
t/t4018/ini-subsection-noindent new file +12 -0
new file mode 100644
index 0000000000..698ea00ea3
@@ -0,0 +1,12 @@
+[LEFT]
+
+[LEFT "CENTER"]
+# comment
+; comment
+name = value
+
+[LEFT "RIGHT"]
+# comment
+; comment
+name = value
+ChangeMe
userdiff.c +4 -0
index 340c4eb4f7..da75625020 100644
@@ -211,6 +211,10 @@ PATTERNS("html",
 	 "^[ \t]*(<[Hh][1-6]([ \t].*)?>.*)$",
 	 /* -- */
 	 "[^<>= \t]+"),
+PATTERNS("ini",
+	 "^[ \t]*\\[[^]]+\\]",
+	 /* -- */
+	 "[^ \t]+"),
 PATTERNS("java",
 	 "!^[ \t]*(catch|do|for|if|instanceof|new|return|switch|throw|while)\n"
 	 /* Class, enum, interface, and record declarations */
Signature · 1 line
2.39.5 (Apple Git-154)
#1 lore raw
Quoted 10 lines · Lucas Seiki Oshiro

Add a new builtin driver for generic INI files (e. g. the gitconfig files), where:

- the funcname regular expression matches section names, i. e. any string between brackets at the beginning of the line, with or without indentation;

- word_regex matches any word with one or more non-whitespace characters without checking if it is a valid variable name or value.

Quoted 6 lines

Also add tests for the new userdiff driver. These files define sections and subsections, with and without indentation.

This commit message reads quite nicely now. The changes also look sensible to me. Thanks, I've got nothing else to add!

Patrick