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

Re: [PATCH 08/15] ref-filter: make "%(symref)" atom work with the ':short' modifier

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 7, 2016, 23:08 UTC
Message-ID
<xmqqtwkhnaxg.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1457265902-7949-9-git-send-email-Karthik.188@gmail.com>
Karthik Nayak <karthik.188@gmail.com> writes:
> The "%(symref)" atom doesn't work when used with the ':short' modifier
> because we strictly match only 'symref' for setting the 'need_symref'
> indicator. Fix this by using 'starts_with()' rather than 'strcmp()'.
Does that mean you also accept %(symrefgarbage) without complaining?
Show 62 quoted lines
>
> Add tests for %(symref) and %(symref:short) while we're here.
>
> Signed-off-by: Karthik Nayak <Karthik.188@gmail.com>
> ---
>  ref-filter.c            |  2 +-
>  t/t6300-for-each-ref.sh | 24 ++++++++++++++++++++++++
>  2 files changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/ref-filter.c b/ref-filter.c
> index 0e6ab75..ab860a3 100644
> --- a/ref-filter.c
> +++ b/ref-filter.c
> @@ -323,7 +323,7 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
>  		valid_atom[i].parser(&used_atom[at], arg);
>  	if (*atom == '*')
>  		need_tagged = 1;
> -	if (!strcmp(used_atom[at].name, "symref"))
> +	if (starts_with(used_atom[at].name, "symref"))
>  		need_symref = 1;
>  	return at;
>  }
> diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
> index 2c5f177..b06ea1c 100755
> --- a/t/t6300-for-each-ref.sh
> +++ b/t/t6300-for-each-ref.sh
> @@ -38,6 +38,7 @@ test_atom() {
>  	case "$1" in
>  		head) ref=refs/heads/master ;;
>  		 tag) ref=refs/tags/testtag ;;
> +		 sym) ref=refs/heads/sym ;;
>  		   *) ref=$1 ;;
>  	esac
>  	printf '%s\n' "$3" >expected
> @@ -565,4 +566,27 @@ test_expect_success 'Verify sort with multiple keys' '
>  		refs/tags/bogo refs/tags/master > actual &&
>  	test_cmp expected actual
>  '
> +
> +test_expect_success 'Add symbolic ref for the following tests' '
> +	git symbolic-ref refs/heads/sym refs/heads/master
> +'
> +
> +cat >expected <<EOF
> +refs/heads/master
> +EOF
> +
> +test_expect_success 'Verify usage of %(symref) atom' '
> +	git for-each-ref --format="%(symref)" refs/heads/sym > actual &&
> +	test_cmp expected actual
> +'
> +
> +cat >expected <<EOF
> +heads/master
> +EOF
> +
> +test_expect_success 'Verify usage of %(symref:short) atom' '
> +	git for-each-ref --format="%(symref:short)" refs/heads/sym > actual &&
> +	test_cmp expected actual
> +'
> +
>  test_done
Previous: Karthik NayakNext: Jacob Keller
Message 16 of 30 in “port branch.c to use ref-filter's printing options”
  1. 00/15 port branch.c to use ref-filter's printing optionsKarthik Nayak, Mar 6, 2016
  2. 01/15 ref-filter: implement %(if), %(then), and %(else) atomsKarthik Nayak, Mar 6, 2016
  3. 02/15 ref-filter: implement %(if:equals=<string>) and %(if:notequals=<string>)Karthik Nayak, Mar 6, 2016
  4. Junio C HamanoMar 7, 2016
  5. Karthik NayakMar 8, 2016
  6. Junio C HamanoMar 8, 2016
  7. Karthik NayakMar 8, 2016
  8. 03/15 ref-filter: modify "%(objectname:short)" to take lengthKarthik Nayak, Mar 6, 2016
  9. 04/15 ref-filter: move get_head_description() from branch.cKarthik Nayak, Mar 6, 2016
  10. 05/15 ref-filter: introduce format_ref_array_item()Karthik Nayak, Mar 6, 2016
  11. 06/15 ref-filter: make %(upstream:track) prints "[gone]" for invalid upstreamsKarthik Nayak, Mar 6, 2016
  12. Jacob KellerMar 8, 2016
  13. Karthik NayakMar 8, 2016
  14. 07/15 ref-filter: add support for %(upstream:track,nobracket)Karthik Nayak, Mar 6, 2016
  15. 08/15 ref-filter: make "%(symref)" atom work with the ':short' modifierKarthik Nayak, Mar 6, 2016
  16. Junio C HamanoMar 7, 2016
  17. Jacob KellerMar 8, 2016
  18. Karthik NayakMar 8, 2016
  19. Junio C HamanoMar 8, 2016
  20. Karthik NayakMar 9, 2016
  21. 09/15 ref-filter: introduce symref_atom_parser()Karthik Nayak, Mar 6, 2016
  22. 10/15 ref-filter: introduce refname_atom_parser()Karthik Nayak, Mar 6, 2016
  23. 11/15 ref-filter: add support for %(refname:dir) and %(refname:base)Karthik Nayak, Mar 6, 2016
  24. 12/15 ref-filter: allow porcelain to translate messages in the outputKarthik Nayak, Mar 6, 2016
  25. 13/15 branch, tag: use porcelain outputKarthik Nayak, Mar 6, 2016
  26. 14/15 branch: use ref-filter printing APIsKarthik Nayak, Mar 6, 2016
  27. Junio C HamanoMar 7, 2016
  28. 15/15 branch: implement '--format' optionKarthik Nayak, Mar 6, 2016
  29. Jacob KellerMar 8, 2016
  30. Karthik NayakMar 15, 2016

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.