]> git.ipfire.org Git - thirdparty/git.git/commitdiff
userdiff: add builtin driver for INI files
authorLucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Mon, 31 Mar 2025 03:13:09 +0000 (00:13 -0300)
committerJunio C Hamano <gitster@pobox.com>
Tue, 1 Apr 2025 10:02:09 +0000 (03:02 -0700)
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.

Helped-by: Patrick Steinhardt <ps@pks.im>
Helped-by: D. Ben Knoble <ben.knoble@gmail.com>
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t4018/ini-section [new file with mode: 0644]
t/t4018/ini-section-noindent [new file with mode: 0644]
t/t4018/ini-section-same-line [new file with mode: 0644]
t/t4018/ini-subsection [new file with mode: 0644]
t/t4018/ini-subsection-noindent [new file with mode: 0644]
userdiff.c

diff --git a/t/t4018/ini-section b/t/t4018/ini-section
new file mode 100644 (file)
index 0000000..c895ad9
--- /dev/null
@@ -0,0 +1,5 @@
+[RIGHT]
+        # comment
+        ; comment
+        name = value
+        ChangeMe
diff --git a/t/t4018/ini-section-noindent b/t/t4018/ini-section-noindent
new file mode 100644 (file)
index 0000000..733d23c
--- /dev/null
@@ -0,0 +1,5 @@
+[RIGHT]
+# comment
+; comment
+name = value
+ChangeMe
diff --git a/t/t4018/ini-section-same-line b/t/t4018/ini-section-same-line
new file mode 100644 (file)
index 0000000..522a1fa
--- /dev/null
@@ -0,0 +1,4 @@
+[RIGHT] name = value
+        # comment
+        ; comment
+        ChangeMe
diff --git a/t/t4018/ini-subsection b/t/t4018/ini-subsection
new file mode 100644 (file)
index 0000000..3d47349
--- /dev/null
@@ -0,0 +1,12 @@
+[LEFT]
+
+      [LEFT "CENTER"]
+      # comment
+      ; comment
+      name = value
+
+      [LEFT "RIGHT"]
+      # comment
+      ; comment
+      name = value
+      ChangeMe
diff --git a/t/t4018/ini-subsection-noindent b/t/t4018/ini-subsection-noindent
new file mode 100644 (file)
index 0000000..698ea00
--- /dev/null
@@ -0,0 +1,12 @@
+[LEFT]
+
+[LEFT "CENTER"]
+# comment
+; comment
+name = value
+
+[LEFT "RIGHT"]
+# comment
+; comment
+name = value
+ChangeMe
index 340c4eb4f77ab17798d25383fa4b6135c661b67a..da75625020e34c9016ec84c63aa5050d9172d750 100644 (file)
@@ -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 */