git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [GSoC PATCH v3] userdiff: add builtin driver for INI files
@ 2025-03-31  3:13 Lucas Seiki Oshiro
  2025-03-31  7:38 ` Patrick Steinhardt
  0 siblings, 1 reply; 2+ messages in thread
From: Lucas Seiki Oshiro @ 2025-03-31  3:13 UTC (permalink / raw)
  To: git; +Cc: Lucas Seiki Oshiro, Patrick Steinhardt, D . Ben Knoble

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>
---

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

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 */
-- 
2.39.5 (Apple Git-154)


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [GSoC PATCH v3] userdiff: add builtin driver for INI files
  2025-03-31  3:13 [GSoC PATCH v3] userdiff: add builtin driver for INI files Lucas Seiki Oshiro
@ 2025-03-31  7:38 ` Patrick Steinhardt
  0 siblings, 0 replies; 2+ messages in thread
From: Patrick Steinhardt @ 2025-03-31  7:38 UTC (permalink / raw)
  To: Lucas Seiki Oshiro; +Cc: git, D . Ben Knoble

On Mon, Mar 31, 2025 at 12:13:09AM -0300, Lucas Seiki Oshiro wrote:
> 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>

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

Patrick

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-03-31  7:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-31  3:13 [GSoC PATCH v3] userdiff: add builtin driver for INI files Lucas Seiki Oshiro
2025-03-31  7:38 ` Patrick Steinhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).