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

Re: [PATCH v3 8/9] tag.c: implement '--format' option

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Jul 22, 2015, 19:38 UTC
Message-ID
<vpq7fpsnft1.fsf@anie.imag.fr>
In-Reply-To
<1437256837-13378-2-git-send-email-Karthik.188@gmail.com>
Karthik Nayak <karthik.188@gmail.com> writes:
Show 23 quoted lines
> --- a/Documentation/git-tag.txt
> +++ b/Documentation/git-tag.txt
> @@ -13,7 +13,8 @@ SYNOPSIS
>  	<tagname> [<commit> | <object>]
>  'git tag' -d <tagname>...
>  'git tag' [-n[<num>]] -l [--contains <commit>] [--points-at <object>]
> -	[--column[=<options>] | --no-column] [--sort=<key>] [<pattern>...]
> +	[--column[=<options>] | --no-column] [--sort=<key>] [--format=<format>]
> +	[<pattern>...]
>  'git tag' -v <tagname>...
>  
>  DESCRIPTION
> @@ -155,6 +156,19 @@ This option is only applicable when listing tags without annotation lines.
>  	The object that the new tag will refer to, usually a commit.
>  	Defaults to HEAD.
>  
> +<format>::
> +	A string that interpolates `%(fieldname)` from the
> +	object pointed at by a ref being shown.  If `fieldname`
> +	is prefixed with an asterisk (`*`) and the ref points
> +	at a tag object, the value for the field in the object
> +	tag refers is used.  When unspecified, defaults to
> +	`%(objectname) SPC %(objecttype) TAB %(refname)`.

I think this last sentence is taken from for-each-ref where it is true, but for 'git tag', the default is just %(refname:short), as written here:

> -	else
> +	else if (!format)
>  		format = "%(refname:short)";
right?
Show 21 quoted lines
> --- a/t/t7004-tag.sh
> +++ b/t/t7004-tag.sh
> @@ -1507,4 +1507,20 @@ EOF"
>  	test_cmp expect actual
>  '
>  
> +test_expect_success '--format cannot be used with -n' '
> +	test_must_fail git tag -l -n4 --format="%(refname)"
> +'
> +
> +test_expect_success '--format should list tags as per format given' '
> +	cat >expect <<-\EOF &&
> +	foo1.10
> +	foo1.3
> +	foo1.6
> +	foo1.6-rc1
> +	foo1.6-rc2
> +	EOF
> +	git tag -l --format="%(refname)" "foo*" >actual &&
> +	test_cmp expect actual
> +'

This tests the pattern argument, but the the test still passes if I remove the --format option, so it does not test what it claims.

Also, why does "git tag"'s %(refname) behave like "git for-each-ref"'s %(refname:short)? I find it very confusing as I think --format's argument should be interpreted the same way for all ref-listing commands. Actually I didn't find a way to have "git tag" display the full refname other than with --format "refs/tags/%(refname)".

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Karthik NayakNext: Karthik Nayak
Message 32 of 37 in “Port tag.c to use ref-filter APIs”
  1. 0/9 Port tag.c to use ref-filter APIsKarthik Nayak, Jul 18, 2015
  2. 1/9 ref-filter: add option to align atoms to the leftKarthik Nayak, Jul 18, 2015
  3. Eric SunshineJul 19, 2015
  4. Karthik NayakJul 20, 2015
  5. Junio C HamanoJul 20, 2015
  6. Eric SunshineJul 20, 2015
  7. Junio C HamanoJul 20, 2015
  8. Karthik NayakJul 20, 2015
  9. 1/9 ref-filter: add option to align atoms to the leftKarthik Nayak, Jul 20, 2015
  10. Eric SunshineJul 20, 2015
  11. Karthik NayakJul 20, 2015
  12. Junio C HamanoJul 20, 2015
  13. Karthik NayakJul 21, 2015
  14. Matthieu MoyJul 22, 2015
  15. Karthik NayakJul 23, 2015
  16. 2/9 ref-filter: add option to filter only tagsKarthik Nayak, Jul 18, 2015
  17. 3/9 ref-filter: support printing N lines from tag annotationKarthik Nayak, Jul 18, 2015
  18. Eric SunshineJul 20, 2015
  19. Karthik NayakJul 20, 2015
  20. 4/9 ref-filter: add support to sort by versionKarthik Nayak, Jul 18, 2015
  21. Eric SunshineJul 20, 2015
  22. Karthik NayakJul 20, 2015
  23. 5/9 ref-filter: add option to match literal patternKarthik Nayak, Jul 18, 2015
  24. Eric SunshineJul 20, 2015
  25. Christian CouderJul 20, 2015
  26. Eric SunshineJul 20, 2015
  27. Karthik NayakJul 21, 2015
  28. Matthieu MoyJul 22, 2015
  29. 6/9 tag.c: use 'ref-filter' data structuresKarthik Nayak, Jul 18, 2015
  30. 7/9 tag.c: use 'ref-filter' APIsKarthik Nayak, Jul 18, 2015
  31. 8/9 tag.c: implement '--format' optionKarthik Nayak, Jul 18, 2015
  32. Matthieu MoyJul 22, 2015
  33. 9/9 tag.c: implement '--merged' and '--no-merged' optionsKarthik Nayak, Jul 18, 2015
  34. Christian CouderJul 19, 2015
  35. Karthik NayakJul 21, 2015
  36. Matthieu MoyJul 22, 2015
  37. Karthik NayakJul 23, 2015

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.