diff mbox series

Support "valueless truth" in configuration parsing

Message ID xmqq34o6zrmj.fsf@gitster.g (mailing list archive)
State Accepted
Headers show
Series Support "valueless truth" in configuration parsing | expand

Commit Message

Junio C Hamano July 18, 2024, 2:44 p.m. UTC
With a configuration item somewhere (like ~/.gitconfig) like this:

    [sendemail]
        suppressfrom

"b4" barfs while parsing the configuration file.

The code assumes that "git config -z" output, after splitting at
NUL, would always be a LF separated variable and value, but that
does not hold for such a variable defined with only its name without
"= <value>", which means that variable is given the value "true".

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 * It seems that this part of the parser hasn't changed at all since
   ae57d6ea (Initial commit after porting from korg-helpers,
   2020-03-14).  The patch was made against the current tip 47743a82
   (Improve tests exclusion from the built packages, 2024-07-17),
   but presumably it would apply anywhere.

 src/b4/__init__.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Konstantin Ryabitsev July 18, 2024, 3:59 p.m. UTC | #1
On Thu, 18 Jul 2024 07:44:52 -0700, Junio C Hamano wrote:
> With a configuration item somewhere (like ~/.gitconfig) like this:
> 
>     [sendemail]
>         suppressfrom
> 
> "b4" barfs while parsing the configuration file.
> 
> [...]

Applied, thanks!

[1/1] Support "valueless truth" in configuration parsing
      commit: d04d7f4ec48b083b7d83886b1b7e743111cc16d4

Best regards,
Konstantin Ryabitsev July 18, 2024, 4:01 p.m. UTC | #2
On Thu, Jul 18, 2024 at 11:59:41AM GMT, Konstantin Ryabitsev wrote:
> 
> On Thu, 18 Jul 2024 07:44:52 -0700, Junio C Hamano wrote:
> > With a configuration item somewhere (like ~/.gitconfig) like this:
> > 
> >     [sendemail]
> >         suppressfrom
> > 
> > "b4" barfs while parsing the configuration file.
> > 
> > [...]
> 
> Applied, thanks!
> 
> [1/1] Support "valueless truth" in configuration parsing
>       commit: d04d7f4ec48b083b7d83886b1b7e743111cc16d4

Also backported to stable-0.14.y.

Thanks!

-K
diff mbox series

Patch

diff --git a/src/b4/__init__.py b/src/b4/__init__.py
index 7164d3f..ae15b83 100644
--- a/src/b4/__init__.py
+++ b/src/b4/__init__.py
@@ -2824,7 +2824,10 @@  def get_config_from_git(regexp: str, defaults: Opti
     for line in out.split('\x00'):
         if not line:
             continue
-        key, value = line.split('\n', 1)
+        if '\n' in line:
+            key, value = line.split('\n', 1)
+        else:
+            key, value = line, 'true'
         try:
             chunks = key.split('.')
             cfgkey = chunks[-1].lower()