Thread (25 messages) flat view 25 messages, 7 authors, 2d ago

Re: [PATCH v3] var: support broken-down idents, default key, multiple args, and -z

From: Phillip Wood <hidden>
Date: 2026-09-08 09:07:55

Hi Junio

On 04/09/2026 16:57, Junio C Hamano wrote:
Phillip Wood [off-list ref] writes:
quoted
quoted
   	if (value)
-		printf("%s=%s\n", var, value);
+		printf("%s=%s%c", var, value, eol);
A key can contain "=" so this format is ambiguous. When the user passes
"-z" we should use the same format as "git config list -z" which avoids
that ambiguity

	printf("%s%c%s%c", var, eol == '\n' ? '=' : '\n', value, eol);
quoted
   	else
-		printf("%s\n", var);
+		printf("%s%c", var, eol);
It would be worth checking what "git config list -z" does when there is
no value and matching that. Does it print "key\n\0", or "key\0"?
By "key" do you mean "var"? 
I meant the config key which is in variable var
The namespace of "var" for "git var"
proper (like GIT_COMMITTER_IDENT) are very much under our control,
but it also gives all the configuration variables, whose names can
indeed have '=' in a three-level varlable name.  This is an
excellent suggestion.
quoted
quoted
[...]
-	printf("%s\n", val);
-	free(val);
+		printf("%s%c", val, null_term ? '\0' : '\n');
Multi-valued variables are a bit of a problem here, they're built on the
assumption that the individual values do not contain a newline, but as
they are paths I'm not sure that is necessarily true. With -z it would
be better to print '\0' after each value as we do in list_vars().
Ideally we wouldn't use a single string to pass multiple values around,
but a simple fix would be to use '\0' to separate the individual values
instead of '\n' so that we can split them unambiguously when we print them.
Hmph, what does "git config -l" do for multi-valued keys?  We should
mimick it, I would think.
With -z it nul terminates each value. I wonder if we should be printing 
the variable names here when the user passes more than one var name. 
That would make it easier to parse multivalued vars which can have a 
variable number of values, or we could print an extra delimiter after 
the last value of multivalued vars like "git merge-tree" does to 
separate the different sections of its output.
Another thing that might be worth doing is to see if we can separate
out "git config -l" handling out of "git var" with a breaking change
at big version boundary.
Yes, it would be nice to be able to print just the GIT_* vars without 
having to print the config as well.
quoted
Thanks for working on this, being able to specify multiple variables
that are printed unambiguously is a really useful improvement.
Indeed.  Thanks, both.
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help