Re: [GSoC PATCH v5 5/5] repo: add the --format flag

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

 



Lucas Seiki Oshiro <lucasseikioshiro@xxxxxxxxx> writes:

> Add the --format flag to git-repo-info. By using this flag, the users
> can choose the format for obtaining the data they requested.
>
> Given that this command can be used for generating input for another

Nit: s/another/other

> applications and for being read by end users, it requires at least two
> formats: one for being read by humans and other for being read by
> machines. Some other Git commands also have two output formats, notably
> git-config which was the inspiration for the two formats that were
> chosen here:
>
> - keyvalue, where the retrieved data is printed one per line, using =
>   for delimiting the key and the value. This is the default format,
>   targeted for end users.
> - null, where the retrieved data is separated by null characters, using
>   the newline character for delimiting the key and the value. This
>   format is targeted for being read by machines.
>
> Helped-by: Phillip Wood <phillip.wood@xxxxxxxxxxxxx>
> Helped-by: Junio C Hamano <gitster@xxxxxxxxx>
> Helped-by: Justin Tobler <jltobler@xxxxxxxxx>
> Mentored-by: Karthik Nayak <karthik.188@xxxxxxxxx>
> Mentored-by: Patrick Steinhardt <ps@xxxxxx>
> Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@xxxxxxxxx>
> ---
>  Documentation/git-repo.adoc | 13 +++++++++-
>  builtin/repo.c              | 49 ++++++++++++++++++++++++++++++++++---
>  t/t1900-repo.sh             | 13 ++++++++--
>  3 files changed, 68 insertions(+), 7 deletions(-)
>
> diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
> index 375b956d3f..5bdc3831a7 100644
> --- a/Documentation/git-repo.adoc
> +++ b/Documentation/git-repo.adoc
> @@ -18,10 +18,21 @@ THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
>
>  COMMANDS
>  --------
> -info [<key>...]::
> +info [--format=<format>] [<key>...]::
>  	Retrieve metadata-related information about the current repository. Only
>  	the requested data will be returned based on their keys (see "INFO KEYS"
>  	section below).
> ++
> +The output format can be chosen through the flag `--format`. Two formats are
> +supported:
> ++

It's hard to know where the documentation for '--format' starts from,
perhaps we can take a note from how 'Documentation/git-refs.adoc' does
this?

[snip]

>  int cmd_repo(int argc, const char **argv, const char *prefix,
> diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
> index c46ace1fd3..fdd3491429 100755
> --- a/t/t1900-repo.sh
> +++ b/t/t1900-repo.sh
> @@ -20,11 +20,20 @@ test_repo_info () {
>  	key=$3
>  	expected_value=$4
>
> -	test_expect_success "$label" '
> +	test_expect_success "null-terminated: $label" '
> +		test_when_finished "rm -rf repo" &&
> +		eval "$init_command" &&
> +		echo "$expected_value" | lf_to_nul >expected &&
> +		git -C repo repo info --format=null "$key" >output &&
> +		tail -n 1 output >actual &&
> +		test_cmp expected actual
> +	'
> +
> +	test_expect_success "key-value: $label" '
>  		test_when_finished "rm -rf repo" &&
>  		eval "$init_command" &&
>  		echo "$expected_value" >expected &&
> -		git -C repo repo info "$key" >output &&
> +		git -C repo repo info --format=keyvalue "$key" >output &&
>  		cut -d "=" -f 2 <output >actual &&
>  		test_cmp expected actual
>  	'

Shouldn't we also test for invalid format? Also perhaps invalid key in
the first commit too.

Attachment: signature.asc
Description: PGP signature


[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