{"thread":{"id":"63183","subject":"[GSoC PATCH v2] userdiff: add builtin driver for gitconfig syntax","startedAt":"2025-03-24T02:11:10Z","lastAt":"2025-03-25T18:35:11Z","messageCount":5,"participants":["Lucas Seiki Oshiro","Johannes Sixt","Junio C Hamano","D. Ben Knoble"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"514893","messageId":"20250324021101.7483-1-lucasseikioshiro@gmail.com","threadId":"63183","inReplyTo":null,"subject":"[GSoC PATCH v2] userdiff: add builtin driver for gitconfig syntax","fromName":"Lucas Seiki Oshiro","fromEmail":"lucasseikioshiro@gmail.com","sentAt":"2025-03-24T02:11:01Z","receivedAt":"2025-03-24T02:11:10Z","isPatch":true,"sender":{"key":"lucasseikioshiro@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12701580?v=4"},"body":"From Documentation/config.adoc:\n\nAdd a new builtin driver for gitconfig files, where:\n\n- the funcname regular expression matches sections and subsections,\n  i. e. the pattern [SECTION] or [SECTION \"SUBSECTION\"], where the\n  section is composed by alphanumeric numbers, `-` and `.`, and\n  subsection names may be composed by any characters;\n\n- word_regex is more permissive than the syntax specification, matching\n  any word with one or more non-whitespace characters without checking\n  if it is a valid variable name or value.\n\nA more detailed description on the format of gitconfig syntax can be\nseen by running `git show cfd409:Documentation/config.txt`.\n\nAlso add tests for the new userdiff driver. These files define sections\nand subsections, with and without indentation.\n\nHelped-by: Patrick Steinhardt <ps@pks.im>\nHelped-by: D. Ben Knoble <ben.knoble@gmail.com>\nSigned-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>\n---\n\nHi!\n\nThis v2 removes the quoted text from the commit message, using a reference to\nthe documentation file and the commit that last changed the lines where it was\ncopied before.\n\nI'm also adding the missing newlines at the end of the test files.\n\n t/t4018/gitconfig-section             | 6 ++++++\n t/t4018/gitconfig-section-noindent    | 6 ++++++\n t/t4018/gitconfig-subsection          | 8 ++++++++\n t/t4018/gitconfig-subsection-noindent | 8 ++++++++\n userdiff.c                            | 4 ++++\n 5 files changed, 32 insertions(+)\n create mode 100644 t/t4018/gitconfig-section\n create mode 100644 t/t4018/gitconfig-section-noindent\n create mode 100644 t/t4018/gitconfig-subsection\n create mode 100644 t/t4018/gitconfig-subsection-noindent\n\ndiff --git a/t/t4018/gitconfig-section b/t/t4018/gitconfig-section\nnew file mode 100644\nindex 0000000000..18c85eb613\n--- /dev/null\n+++ b/t/t4018/gitconfig-section\n@@ -0,0 +1,6 @@\n+[RIGHT]\n+        # comment\n+        ; comment\n+        name = value\n+        ChangeMe\n+\ndiff --git a/t/t4018/gitconfig-section-noindent b/t/t4018/gitconfig-section-noindent\nnew file mode 100644\nindex 0000000000..5c58a7ac92\n--- /dev/null\n+++ b/t/t4018/gitconfig-section-noindent\n@@ -0,0 +1,6 @@\n+[RIGHT]\n+# comment\n+; comment\n+name = value\n+ChangeMe\n+\ndiff --git a/t/t4018/gitconfig-subsection b/t/t4018/gitconfig-subsection\nnew file mode 100644\nindex 0000000000..569be04a32\n--- /dev/null\n+++ b/t/t4018/gitconfig-subsection\n@@ -0,0 +1,8 @@\n+[LEFT]\n+\n+[LEFT \"RIGHT\"]\n+      # comment\n+      ; comment\n+      name = value\n+      ChangeMe\n+\ndiff --git a/t/t4018/gitconfig-subsection-noindent b/t/t4018/gitconfig-subsection-noindent\nnew file mode 100644\nindex 0000000000..85c5074f47\n--- /dev/null\n+++ b/t/t4018/gitconfig-subsection-noindent\n@@ -0,0 +1,8 @@\n+[LEFT]\n+\n+[LEFT \"RIGHT\"]\n+# comment\n+; comment\n+name = value\n+ChangeMe\n+\ndiff --git a/userdiff.c b/userdiff.c\nindex 340c4eb4f7..5bbcc2b690 100644\n--- a/userdiff.c\n+++ b/userdiff.c\n@@ -198,6 +198,10 @@ IPATTERN(\"fountain\",\n \t \"^((\\\\.[^.]|(int|ext|est|int\\\\.?/ext|i/e)[. ]).*)$\",\n \t /* -- */\n \t \"[^ \\t-]+\"),\n+PATTERNS(\"gitconfig\",\n+         \"^\\\\[[a-zA-Z0-9]+\\\\]|\\\\[[a-zA-Z0-9]+[ \\t]+\\\".+\\\"\\\\]$\",\n+         /* -- */\n+         \"[^ \\t]+\"),\n PATTERNS(\"golang\",\n \t /* Functions */\n \t \"^[ \\t]*(func[ \\t]*.*(\\\\{[ \\t]*)?)\\n\"\n-- \n2.39.5 (Apple Git-154)\n\n"},{"id":"514905","messageId":"d4c0c9a4-0402-4456-9fa0-3102b5bcc3dc@kdbg.org","threadId":"63183","inReplyTo":"20250324021101.7483-1-lucasseikioshiro@gmail.com","subject":"Re: [GSoC PATCH v2] userdiff: add builtin driver for gitconfig syntax","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2025-03-24T07:18:55Z","receivedAt":"2025-03-24T07:56:19Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 24.03.25 um 03:11 schrieb Lucas Seiki Oshiro:\n> From Documentation/config.adoc:\n> \n> Add a new builtin driver for gitconfig files, where:\n> \n> - the funcname regular expression matches sections and subsections,\n>   i. e. the pattern [SECTION] or [SECTION \"SUBSECTION\"], where the\n>   section is composed by alphanumeric numbers, `-` and `.`, and\n>   subsection names may be composed by any characters;\n> \n> - word_regex is more permissive than the syntax specification, matching\n>   any word with one or more non-whitespace characters without checking\n>   if it is a valid variable name or value.\n> \n> A more detailed description on the format of gitconfig syntax can be\n> seen by running `git show cfd409:Documentation/config.txt`.\n\nCan we please have a more recent reference? The difference of config.txt\nhere and config.adoc above is very surprising.\n\n> Also add tests for the new userdiff driver. These files define sections\n> and subsections, with and without indentation.\n> \n> Helped-by: Patrick Steinhardt <ps@pks.im>\n> Helped-by: D. Ben Knoble <ben.knoble@gmail.com>\n> Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>\n\nThank you for your contribution.\n\nThe file format of .git/config files isn't specific to .git/config; it's\ncalled \"ini-file\" and is already very old. Wouldn't it make sense to\ngeneralize the format? It would be just a matter of choosing a different\nname; the regular expressions would not have to change.\n\n> diff --git a/t/t4018/gitconfig-section b/t/t4018/gitconfig-section\n> new file mode 100644\n> index 0000000000..18c85eb613\n> --- /dev/null\n> +++ b/t/t4018/gitconfig-section\n> @@ -0,0 +1,6 @@\n> +[RIGHT]\n> +        # comment\n> +        ; comment\n> +        name = value\n> +        ChangeMe\n> +\n\nThis could test two sections in a row and ensure that the later one is\nchosen.\n\nYou have now managed to avoid the \"No newline at end of file\", but have\nadded a blank line instead. Not a big deal, but unconventional.\n\n> diff --git a/t/t4018/gitconfig-section-noindent b/t/t4018/gitconfig-section-noindent\n> new file mode 100644\n> index 0000000000..5c58a7ac92\n> --- /dev/null\n> +++ b/t/t4018/gitconfig-section-noindent\n> @@ -0,0 +1,6 @@\n> +[RIGHT]\n> +# comment\n> +; comment\n> +name = value\n> +ChangeMe\n> +\n> diff --git a/t/t4018/gitconfig-subsection b/t/t4018/gitconfig-subsection\n> new file mode 100644\n> index 0000000000..569be04a32\n> --- /dev/null\n> +++ b/t/t4018/gitconfig-subsection\n> @@ -0,0 +1,8 @@\n> +[LEFT]\n> +\n> +[LEFT \"RIGHT\"]\n> +      # comment\n> +      ; comment\n> +      name = value\n> +      ChangeMe\n> +\n\nThis could test two sub-sections in a row and ensure that the later one\nis chosen.\n\nWhat happens if there is an *indented* header after the \"RIGHT\" one?\nShould it be chosen or not? Can this happen in a valid file?\n\n> diff --git a/t/t4018/gitconfig-subsection-noindent b/t/t4018/gitconfig-subsection-noindent\n> new file mode 100644\n> index 0000000000..85c5074f47\n> --- /dev/null\n> +++ b/t/t4018/gitconfig-subsection-noindent\n> @@ -0,0 +1,8 @@\n> +[LEFT]\n> +\n> +[LEFT \"RIGHT\"]\n> +# comment\n> +; comment\n> +name = value\n> +ChangeMe\n> +\n> diff --git a/userdiff.c b/userdiff.c\n> index 340c4eb4f7..5bbcc2b690 100644\n> --- a/userdiff.c\n> +++ b/userdiff.c\n> @@ -198,6 +198,10 @@ IPATTERN(\"fountain\",\n>  \t \"^((\\\\.[^.]|(int|ext|est|int\\\\.?/ext|i/e)[. ]).*)$\",\n>  \t /* -- */\n>  \t \"[^ \\t-]+\"),\n> +PATTERNS(\"gitconfig\",\n> +         \"^\\\\[[a-zA-Z0-9]+\\\\]|\\\\[[a-zA-Z0-9]+[ \\t]+\\\".+\\\"\\\\]$\",\n\nThe regular expression can assume that the syntax of the processed file\nis correct. For example,\n\n   [!not a section!]\n\ncannot be a section header and will not occur in a valid file. Or can it?\n\nTherefore, it would be sufficient to just take everything after the '['\nat the beginning of the line without further inspection.\n\nFurthermore, a valid file can look like this:\n\n[section] key = value\n  another_key = more values\n\nbut your pattern would not pick up this header, because it insists in\nthat the closing bracket is at the end of the line. Having a test for\nthis case would be great.\n\n> +         /* -- */\n> +         \"[^ \\t]+\"),\n>  PATTERNS(\"golang\",\n>  \t /* Functions */\n>  \t \"^[ \\t]*(func[ \\t]*.*(\\\\{[ \\t]*)?)\\n\"\n\n-- Hannes\n\n"},{"id":"514909","messageId":"xmqqtt7iojaf.fsf@gitster.g","threadId":"63183","inReplyTo":"20250324021101.7483-1-lucasseikioshiro@gmail.com","subject":"Re: [GSoC PATCH v2] userdiff: add builtin driver for gitconfig syntax","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-03-24T09:43:52Z","receivedAt":"2025-03-24T09:43:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> writes:\n\n> This v2 removes the quoted text from the commit message, using a reference to\n> the documentation file and the commit that last changed the lines where it was\n> copied before.\n>\n> I'm also adding the missing newlines at the end of the test files.\n>\n>  t/t4018/gitconfig-section             | 6 ++++++\n>  t/t4018/gitconfig-section-noindent    | 6 ++++++\n>  t/t4018/gitconfig-subsection          | 8 ++++++++\n>  t/t4018/gitconfig-subsection-noindent | 8 ++++++++\n>  userdiff.c                            | 4 ++++\n>  5 files changed, 32 insertions(+)\n>  create mode 100644 t/t4018/gitconfig-section\n>  create mode 100644 t/t4018/gitconfig-section-noindent\n>  create mode 100644 t/t4018/gitconfig-subsection\n>  create mode 100644 t/t4018/gitconfig-subsection-noindent\n\n.git/rebase-apply/patch:83: indent with spaces.\n         \"^\\\\[[a-zA-Z0-9]+\\\\]|\\\\[[a-zA-Z0-9]+[ \\t]+\\\".+\\\"\\\\]$\",\n.git/rebase-apply/patch:84: indent with spaces.\n         /* -- */\n.git/rebase-apply/patch:85: indent with spaces.\n         \"[^ \\t]+\"),\nwarning: 3 lines applied after fixing whitespace errors.\nApplying: userdiff: add builtin driver for gitconfig syntax\n\n"},{"id":"514967","messageId":"CALnO6CAsF1J39MeO-KY80bQfFL1V3UHT08-Va2R6QNh0JqwZ9A@mail.gmail.com","threadId":"63183","inReplyTo":"d4c0c9a4-0402-4456-9fa0-3102b5bcc3dc@kdbg.org","subject":"Re: [GSoC PATCH v2] userdiff: add builtin driver for gitconfig syntax","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2025-03-24T20:23:02Z","receivedAt":"2025-03-24T20:23:15Z","isPatch":true,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"On Mon, Mar 24, 2025 at 3:18 AM Johannes Sixt <j6t@kdbg.org> wrote:\n>\n>\n> You have now managed to avoid the \"No newline at end of file\", but have\n> added a blank line instead. Not a big deal, but unconventional.\n>\n\nI missed the opportunity to reply to the original patch on this front,\nbut here's the information I usually give out:\n- VS Code's default settings do not respect POSIX end-of-file newline\nstandards, so you should probably change them [1]\n- There's a similar setting for Intellij IDEA [2] and Vim [3], but\nthey might have saner defaults (Vim certainly does)\n- If your editor or IDE picks up on editorconfig settings, you'll be\nable to avoid this\n- Git can warn you with diff or show saying \"No newline at end of\nfile,\" so a careful self-review also catches these.\n\n[1]: https://stackoverflow.com/q/44704968/4400820\n[2]: https://stackoverflow.com/q/16761227/4400820\n[3]: https://vimhelp.org/options.txt.html#%27endofline%27\n\n-- \nD. Ben Knoble\n"},{"id":"515034","messageId":"FE085EEC-0BCC-43D9-9F17-1A7060DC4D6E@gmail.com","threadId":"63183","inReplyTo":"d4c0c9a4-0402-4456-9fa0-3102b5bcc3dc@kdbg.org","subject":"Re: [GSoC PATCH v2] userdiff: add builtin driver for gitconfig syntax","fromName":"Lucas Seiki Oshiro","fromEmail":"lucasseikioshiro@gmail.com","sentAt":"2025-03-25T18:34:57Z","receivedAt":"2025-03-25T18:35:11Z","isPatch":true,"sender":{"key":"lucasseikioshiro@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12701580?v=4"},"body":"\n> Can we please have a more recent reference? The difference of config.txt\n> here and config.adoc above is very surprising.\n\nHmmmm... My idea was to reference the last change in the paragraphs\nof the documentation, but I'll change to the last change of this file.\n\n> The file format of .git/config files isn't specific to .git/config; it's\n> called \"ini-file\" and is already very old. Wouldn't it make sense to\n> generalize the format? It would be just a matter of choosing a different\n> name; the regular expressions would not have to change.\n\nIndeed. This is was written having the gitconfig in mind, but perhaps I\ncould use a different approach and make a little more flexible for other\nINI flavors and perhaps even TOML\n\n> This could test two sub-sections in a row and ensure that the later one\n> is chosen.\n\nNice! I'll do that.\n\n> What happens if there is an *indented* header after the \"RIGHT\" one?\n> Should it be chosen or not? Can this happen in a valid file?\n\nI just tested here, it is valid file. I'll take indentation into acoount\nin v3.\n\n> The regular expression can assume that the syntax of the processed file\n> is correct. For example,\n> \n>   [!not a section!]\n> cannot be a section header and will not occur in a valid file. Or can it?\n\nFollowing the gitconfig syntax specification it can't be in a valid file,\nand this regex won't match it.\n\n> Therefore, it would be sufficient to just take everything after the '['\n> at the beginning of the line without further inspection.\n\nI can't see any harm in just dropping the section name matching and using\na generic /\\[.+\\]/. It may be also useful for more generic INI files that\nyou mentioned before.\n\n> Furthermore, a valid file can look like this:\n> \n> [section] key = value\n>  another_key = more values\n\nTo be honest, I didn't know that it could was a valid file. I'll include\nthat in a v3.\n\nThanks for your extensive review!\n\n\n\n\n"}]}