Re: [GSoC PATCH 1/2] repo: add the flag -z as an alias for --format=nul

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Aug 20, 2025 at 11:42:46AM -0300, Lucas Seiki Oshiro wrote:
> Other Git commands that have nul-terminated output (e.g. git-config,
> git-status, git-ls-files) have a flag `-z` for using the null character
> as the record separator.
> 
> Add the `-z` flag to git-repo-info as an alias for `--format=nul`,
> making it consistent with the behavior of the other commands.

Yeah, it's common indeed to have `-z` for nul-terminated output.

> diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
> index 2870828d93..f2dc71193c 100644
> --- a/Documentation/git-repo.adoc
> +++ b/Documentation/git-repo.adoc
> @@ -8,7 +8,7 @@ git-repo - Retrieve information about the repository
>  SYNOPSIS
>  --------
>  [synopsis]
> -git repo info [--format=(keyvalue|nul)] [<key>...]
> +git repo info [--format=(keyvalue|nul)|-z] [<key>...]

Not a 100% sure, but I think this would actually need to be formatted as

    [(--format=(keyvalue|nul)|-z)]

Looks a bit ugly though, so maybe the existent version is good enough?
Others may have a more informed opinion.

> diff --git a/builtin/repo.c b/builtin/repo.c
> index 8c6e7f42ab..b2ec66e454 100644
> --- a/builtin/repo.c
> +++ b/builtin/repo.c
> @@ -115,20 +115,27 @@ static int print_fields(int argc, const char **argv,
>  static int repo_info(int argc, const char **argv, const char *prefix,
>  		     struct repository *repo)
>  {
> -	const char *format_str = "keyvalue";
> +	const char *format_str = NULL;
>  	enum output_format format;
> +	int format_nul = 0;
>  	struct option options[] = {
>  		OPT_STRING(0, "format", &format_str, N_("format"),
>  			   N_("output format")),
> +		OPT_BOOL('z', NULL, &format_nul, N_("alias for --format=nul")),
>  		OPT_END()
>  	};
>  
>  	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
>  
> -	if (!strcmp(format_str, "keyvalue"))
> -		format = FORMAT_KEYVALUE;
> -	else if (!strcmp(format_str, "nul"))
> +	die_for_incompatible_opt2(!!format_nul, "-z",
> +				  !!format_str, "--format");

Makes sense, we only want one of "--format=" or "-z".

> +	format_str = format_str ? format_str : "keyvalue";
> +
> +	if (format_nul || !strcmp(format_str, "nul"))
>  		format = FORMAT_NUL_TERMINATED;
> +	else if (!strcmp(format_str, "keyvalue"))
> +		format = FORMAT_KEYVALUE;
>  	else
>  		die(_("invalid format '%s'"), format_str);
>  

And here we then determine which format was picked. Looks reasonable.

Patrick




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux