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

[PATCH v10 09/20] ref-filter: make "%(symref)" atom work with the ':short' modifier

From
Karthik Nayak <karthik.188@gmail.com>
Date
Jan 10, 2017, 08:49 UTC
Message-ID
<20170110084953.15890-10-Karthik.188@gmail.com>
In-Reply-To
<20170110084953.15890-1-Karthik.188@gmail.com>
From: Karthik Nayak <karthik.188@gmail.com>

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 comparing with the valid_atom rather than the used_atom.

Add tests for %(symref) and %(symref:short) while we're here.
Helped-by: Junio C Hamano <gitster@pobox.com>
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 6de0927d1..e98ef4bb6 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -352,7 +352,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 (!strcmp(valid_atom[i].name, "symref"))
 		need_symref = 1;
 	return at;
 }
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index af76dc530..7663a3661 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
@@ -566,6 +567,7 @@ test_expect_success 'Verify sort with multiple keys' '
 	test_cmp expected actual
 '
 
+
 test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
 	test_when_finished "git checkout master" &&
 	git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
@@ -600,4 +602,26 @@ test_expect_success 'basic atom: head contents:trailers' '
 	test_cmp expect actual.clean
 '
 
+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
-- 
2.11.0
Previous: Karthik NayakNext: Karthik Nayak
Message 14 of 28 in “port branch.c to use ref-filter's printing options”
  1. 00/20 port branch.c to use ref-filter's printing optionsKarthik Nayak, Jan 10, 2017
  2. 01/20 ref-filter: implement %(if), %(then), and %(else) atomsKarthik Nayak, Jan 10, 2017
  3. 03/20 ref-filter: implement %(if:equals=<string>) and %(if:notequals=<string>)Karthik Nayak, Jan 10, 2017
  4. Junio C HamanoJan 10, 2017
  5. Karthik NayakJan 14, 2017
  6. 04/20 ref-filter: modify "%(objectname:short)" to take lengthKarthik Nayak, Jan 10, 2017
  7. 02/20 ref-filter: include reference to 'used_atom' within 'atom_value'Karthik Nayak, Jan 10, 2017
  8. 07/20 ref-filter: make %(upstream:track) prints "[gone]" for invalid upstreamsKarthik Nayak, Jan 10, 2017
  9. 06/20 ref-filter: introduce format_ref_array_item()Karthik Nayak, Jan 10, 2017
  10. 05/20 ref-filter: move get_head_description() from branch.cKarthik Nayak, Jan 10, 2017
  11. 08/20 ref-filter: add support for %(upstream:track,nobracket)Karthik Nayak, Jan 10, 2017
  12. 10/20 ref-filter: introduce refname_atom_parser_internal()Karthik Nayak, Jan 10, 2017
  13. 11/20 ref-filter: introduce refname_atom_parser()Karthik Nayak, Jan 10, 2017
  14. 09/20 ref-filter: make "%(symref)" atom work with the ':short' modifierKarthik Nayak, Jan 10, 2017
  15. 15/20 ref-filter: modify the 'lstrip=<N>' option to work with negative '<N>'Karthik Nayak, Jan 10, 2017
  16. 20/20 branch: implement '--format' optionKarthik Nayak, Jan 10, 2017
  17. 17/20 ref-filter: allow porcelain to translate messages in the outputKarthik Nayak, Jan 10, 2017
  18. 16/20 ref-filter: add an 'rstrip=<N>' option to atoms which deal with refnamesKarthik Nayak, Jan 10, 2017
  19. 19/20 branch: use ref-filter printing APIsKarthik Nayak, Jan 10, 2017
  20. Jacob KellerJan 11, 2017
  21. Karthik NayakJan 14, 2017
  22. Jacob KellerJan 15, 2017
  23. 18/20 branch, tag: use porcelain outputKarthik Nayak, Jan 10, 2017
  24. 14/20 ref-filter: Do not abruptly die when using the 'lstrip=<N>' optionKarthik Nayak, Jan 10, 2017
  25. 12/20 ref-filter: make remote_ref_atom_parser() use refname_atom_parser_internal()Karthik Nayak, Jan 10, 2017
  26. 13/20 ref-filter: rename the 'strip' option to 'lstrip'Karthik Nayak, Jan 10, 2017
  27. Junio C HamanoJan 10, 2017
  28. Karthik NayakJan 14, 2017

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.