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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 14, 2026, 19:34 UTC
Message-ID
<xmqq5x07630q.fsf@gitster.g>
In-Reply-To
<pull.2388.v7.git.git.1789009798902.gitgitgadget@gmail.com>
"Andrew Pleeter via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 7 quoted lines
>  DESCRIPTION
>  -----------
> +Prints Git logical variables. Exits with code 1 if any requested
> +variable has no value. When multiple variables are requested, an empty
> +record (a blank line, or an empty NUL-terminated record when `-z` is given)
> +is printed for any variable that has no value, and the command continues
> +processing the remaining variables.

Very clearly described. Although it makes it sound as if the command always notices a variable without any value and reports failure with its exit value, no matter in what mode, but I do not think that matches what the code does (below).

Show 40 quoted lines
>  int cmd_var(int argc,
> ...
> +	term = nul_term ? '\0' : '\n';
> +
> +	for (i = 0; i < argc; i++) {
> +		const struct git_var *git_var = get_git_var(argv[i]);
>  
> +		if (!git_var)
> +			usage_with_options(var_usage, options);
>  
> +		if (git_var->read) {
> +			char *val = git_var->read(IDENT_STRICT);
> +
> +			if (!val) {
> +				if (argc == 1)
> +					return 1;
> +				putc(term, stdout);
> +				continue;
> +			}
> +			printf("%s%c", val, term);
> +			free(val);
> +		} else {
> +			struct string_list list = STRING_LIST_INIT_DUP;
> +			size_t j;
> +
> +			git_var->multiread(&list);
> +			if (argc == 1 && !list.nr) {
> +				string_list_clear(&list, 0);
> +				return 1;
> +			}
> +			for (j = 0; j < list.nr; j++)
> +				printf("%s%c", list.items[j].string, term);
> +			if (argc > 1)
> +				putc(term, stdout);
> +			string_list_clear(&list, 0);
> +		}
> +	}
>  
>  	return 0;
>  }

When we ask for a single variable, 'argc' is 1 (and we never update 'argc' in the loop, which is good), and we return 1 upon seeing a missing value. We also do the same when we receive a 0-element list back for a multi-valued variable. Otherwise, nobody in the loop remembers that we had any such failure; the loop continues, and we return 0 unconditionally. A "missing value" anomaly noticed during the loop gets forgotten.

Either the documentation or the code needs to be updated, I think.

I am still not convinced this output format is easy for scripts to handle when multi-valued variables are involved. It is also a bit unclear what exactly "variable has no value" means. A variable whose value is an empty string is not such a variable, right? If a multi-valued variable has an empty string and the string "hello" as its value, would the output from the command confuse the reading script into thinking that the first blank line signals that the variable has no value, for example? Having to know which variables are multi-valued and which are not before parsing the output format does not help, either.

We could, of course, disambiguate by prefixing these lines with variable names followed by '=' (or NUL), which would likely eliminate the ambiguity. But I understand that you are trying to allow the parsers to proceed without having to strip prefixes from each input, which is why the format tries to rely solely on the correspondence between command-line arguments and output lines. I, however, doubt you succeeded in doing so without making the output ambiguous.

Thanks.
Previous: Andrew Pleeter via GitGitGadgetNext: Andrew Pleeter via GitGitGadget
Message 21 of 35 in “builtin/whoami: add new 'whoami' command”
  1. builtin/whoami: add new 'whoami' commandAndrew Pleeter via GitGitGadget, Aug 25, 2026
  2. brian m. carlsonAug 25, 2026
  3. Junio C HamanoAug 25, 2026
  4. builtin/ident: add new 'ident' commandAndrew Pleeter via GitGitGadget, Aug 31, 2026
  5. Jeff KingSep 1, 2026
  6. Junio C HamanoSep 1, 2026
  7. var: support broken-down idents, default key, multiple args, and -zAndrew Pleeter via GitGitGadget, Sep 3, 2026
  8. Junio C HamanoSep 3, 2026
  9. Ben KnobleSep 3, 2026
  10. Phillip WoodSep 4, 2026
  11. Junio C HamanoSep 4, 2026
  12. Phillip WoodSep 8, 2026
  13. var: support broken-down idents, signing key, multiple args, and -zAndrew Pleeter via GitGitGadget, Sep 8, 2026
  14. Phillip WoodSep 8, 2026
  15. var: support broken-down idents, signing key, multiple args, and -zAndrew Pleeter via GitGitGadget, Sep 8, 2026
  16. Junio C HamanoSep 8, 2026
  17. var: support broken-down idents, signing key, multiple args, and -zAndrew Pleeter via GitGitGadget, Sep 9, 2026
  18. Phillip WoodSep 9, 2026
  19. Junio C HamanoSep 9, 2026
  20. var: support broken-down idents, signing key, multiple args, and -zAndrew Pleeter via GitGitGadget, Sep 10, 2026
  21. Junio C HamanoSep 14, 2026
  22. var: support broken-down idents, signing key, multiple args, and -zAndrew Pleeter via GitGitGadget, Sep 14, 2026
  23. Junio C HamanoSep 15, 2026
  24. Andrew PleeterSep 15, 2026
  25. Phillip WoodSep 22, 2026
  26. Andrew PleeterSep 26, 2026
  27. 0/4 var: -z output, multiple variables, and broken-out identsAndrew Pleeter, Sep 26, 2026
  28. Phillip WoodOct 2, 2026
  29. Andrew PleeterOct 2, 2026
  30. 1/4 var: represent multi-valued variables with a string_listAndrew Pleeter, Sep 26, 2026
  31. 2/4 var: add "-z" output modeAndrew Pleeter, Sep 26, 2026
  32. 3/4 var: accept more than one variableAndrew Pleeter, Sep 26, 2026
  33. Phillip WoodOct 2, 2026
  34. 4/4 var: add broken-out identity variablesAndrew Pleeter, Sep 26, 2026
  35. Phillip WoodOct 2, 2026

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.