git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[GSoC PATCH v2] userdiff: add builtin driver for gitconfig syntax

From
Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Date
Mar 24, 2025, 02:11 UTC
Message-ID
<20250324021101.7483-1-lucasseikioshiro@gmail.com>
From Documentation/config.adoc:
Add a new builtin driver for gitconfig files, where:
- the funcname regular expression matches sections and subsections,
  i. e. the pattern [SECTION] or [SECTION "SUBSECTION"], where the
  section is composed by alphanumeric numbers, `-` and `.`, and
  subsection names may be composed by any characters;
- word_regex is more permissive than the syntax specification, matching
  any word with one or more non-whitespace characters without checking
  if it is a valid variable name or value.

A more detailed description on the format of gitconfig syntax can be seen by running `git show cfd409:Documentation/config.txt`.

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

This v2 removes the quoted text from the commit message, using a reference to the documentation file and the commit that last changed the lines where it was copied before.

I'm also adding the missing newlines at the end of the test files.
 t/t4018/gitconfig-section             | 6 ++++++
 t/t4018/gitconfig-section-noindent    | 6 ++++++
 t/t4018/gitconfig-subsection          | 8 ++++++++
 t/t4018/gitconfig-subsection-noindent | 8 ++++++++
 userdiff.c                            | 4 ++++
 5 files changed, 32 insertions(+)
 create mode 100644 t/t4018/gitconfig-section
 create mode 100644 t/t4018/gitconfig-section-noindent
 create mode 100644 t/t4018/gitconfig-subsection
 create mode 100644 t/t4018/gitconfig-subsection-noindent
diff --git a/t/t4018/gitconfig-section b/t/t4018/gitconfig-section
new file mode 100644
index 0000000000..18c85eb613
--- /dev/null
+++ b/t/t4018/gitconfig-section
@@ -0,0 +1,6 @@
+[RIGHT]
+        # comment
+        ; comment
+        name = value
+        ChangeMe
+
diff --git a/t/t4018/gitconfig-section-noindent b/t/t4018/gitconfig-section-noindent
new file mode 100644
index 0000000000..5c58a7ac92
--- /dev/null
+++ b/t/t4018/gitconfig-section-noindent
@@ -0,0 +1,6 @@
+[RIGHT]
+# comment
+; comment
+name = value
+ChangeMe
+
diff --git a/t/t4018/gitconfig-subsection b/t/t4018/gitconfig-subsection
new file mode 100644
index 0000000000..569be04a32
--- /dev/null
+++ b/t/t4018/gitconfig-subsection
@@ -0,0 +1,8 @@
+[LEFT]
+
+[LEFT "RIGHT"]
+      # comment
+      ; comment
+      name = value
+      ChangeMe
+
diff --git a/t/t4018/gitconfig-subsection-noindent b/t/t4018/gitconfig-subsection-noindent
new file mode 100644
index 0000000000..85c5074f47
--- /dev/null
+++ b/t/t4018/gitconfig-subsection-noindent
@@ -0,0 +1,8 @@
+[LEFT]
+
+[LEFT "RIGHT"]
+# comment
+; comment
+name = value
+ChangeMe
+
diff --git a/userdiff.c b/userdiff.c
index 340c4eb4f7..5bbcc2b690 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -198,6 +198,10 @@ IPATTERN("fountain",
 	 "^((\\.[^.]|(int|ext|est|int\\.?/ext|i/e)[. ]).*)$",
 	 /* -- */
 	 "[^ \t-]+"),
+PATTERNS("gitconfig",
+         "^\\[[a-zA-Z0-9]+\\]|\\[[a-zA-Z0-9]+[ \t]+\".+\"\\]$",
+         /* -- */
+         "[^ \t]+"),
 PATTERNS("golang",
 	 /* Functions */
 	 "^[ \t]*(func[ \t]*.*(\\{[ \t]*)?)\n"
-- 
2.39.5 (Apple Git-154)
Next: Johannes Sixt
Message 1 of 5 in “userdiff: add builtin driver for gitconfig syntax”
  1. userdiff: add builtin driver for gitconfig syntaxLucas Seiki Oshiro, Mar 24, 2025
  2. Johannes SixtMar 24, 2025
  3. D. Ben KnobleMar 24, 2025
  4. Lucas Seiki OshiroMar 25, 2025
  5. Junio C HamanoMar 24, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.