aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucas Seiki Oshiro <lucasseikioshiro@gmail.com>2025-03-31 00:13:09 -0300
committerJunio C Hamano <gitster@pobox.com>2025-04-01 03:02:09 -0700
commit43380056df44aed6e074689dc8bc940f9dc6e2c8 (patch)
treeba5279cfaa2f82baceadb3b65d7c20d002952ca0
parentGit 2.49 (diff)
downloadgit-43380056df44aed6e074689dc8bc940f9dc6e2c8.tar.gz
git-43380056df44aed6e074689dc8bc940f9dc6e2c8.zip
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. 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>
-rw-r--r--t/t4018/ini-section5
-rw-r--r--t/t4018/ini-section-noindent5
-rw-r--r--t/t4018/ini-section-same-line4
-rw-r--r--t/t4018/ini-subsection12
-rw-r--r--t/t4018/ini-subsection-noindent12
-rw-r--r--userdiff.c4
6 files changed, 42 insertions, 0 deletions
diff --git a/t/t4018/ini-section b/t/t4018/ini-section
new file mode 100644
index 0000000000..c895ad9b4f
--- /dev/null
+++ b/t/t4018/ini-section
@@ -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
index 0000000000..733d23c801
--- /dev/null
+++ b/t/t4018/ini-section-noindent
@@ -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
index 0000000000..522a1fa4a1
--- /dev/null
+++ b/t/t4018/ini-section-same-line
@@ -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
index 0000000000..3d47349e60
--- /dev/null
+++ b/t/t4018/ini-subsection
@@ -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
index 0000000000..698ea00ea3
--- /dev/null
+++ b/t/t4018/ini-subsection-noindent
@@ -0,0 +1,12 @@
+[LEFT]
+
+[LEFT "CENTER"]
+# comment
+; comment
+name = value
+
+[LEFT "RIGHT"]
+# comment
+; comment
+name = value
+ChangeMe
diff --git a/userdiff.c b/userdiff.c
index 340c4eb4f7..da75625020 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -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 */