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

[PATCH v4 00/16] port branch.c to use ref-filter's printing options

From
Karthik Nayak <karthik.188@gmail.com>
Date
Apr 9, 2016, 18:44 UTC
Message-ID
<1460227515-28437-1-git-send-email-Karthik.188@gmail.com>

This is part of unification of the commands 'git tag -l, git branch -l and git for-each-ref'. This ports over branch.c to use ref-filter's printing options.

Initially posted here: $(gmane/279226). It was decided that this series would follow up after refactoring ref-filter parsing mechanism, which is now merged into master (9606218b32344c5c756f7c29349d3845ef60b80c).

v1 can be found here: $(gmane/288342) v2 can be found here: $(gmane/288863) v3 can be found here: $(gmane/290299)

Changes in this version:
1. Rebased on top of Erics changes, this was breaking tests. Thanks
to Dennis Kaarsemaker and Ramsay Jones for reporting this in.
2. Show local branch symrefs if available, changed this in the format
for `git branch -l`.

Thanks to Junio, Matthieu, Dennis and Ramsay for all suggestions on the previous iteration.

Karthik Nayak (16):
  ref-filter: implement %(if), %(then), and %(else) atoms
  ref-filter: include reference to 'used_atom' within 'atom_value'
  ref-filter: implement %(if:equals=<string>) and
    %(if:notequals=<string>)
  ref-filter: modify "%(objectname:short)" to take length
  ref-filter: move get_head_description() from branch.c
  ref-filter: introduce format_ref_array_item()
  ref-filter: make %(upstream:track) prints "[gone]" for invalid
    upstreams
  ref-filter: add support for %(upstream:track,nobracket)
  ref-filter: make "%(symref)" atom work with the ':short' modifier
  ref-filter: introduce symref_atom_parser()
  ref-filter: introduce refname_atom_parser()
  ref-filter: add support for %(refname:dir) and %(refname:base)
  ref-filter: allow porcelain to translate messages in the output
  branch, tag: use porcelain output
  branch: use ref-filter printing APIs
  branch: implement '--format' option
 Documentation/git-branch.txt       |   7 +-
 Documentation/git-for-each-ref.txt |  63 +++++-
 builtin/branch.c                   | 268 ++++++----------------
 builtin/tag.c                      |   2 +
 ref-filter.c                       | 447 +++++++++++++++++++++++++++++++------
 ref-filter.h                       |   7 +
 t/t3203-branch-output.sh           |  12 +
 t/t6040-tracking-info.sh           |   2 +-
 t/t6300-for-each-ref.sh            |  40 +++-
 t/t6302-for-each-ref-filter.sh     |  94 ++++++++
 10 files changed, 664 insertions(+), 278 deletions(-)
Interdiff:
diff --git a/builtin/branch.c b/builtin/branch.c
index fb05b39..665ee57 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -320,7 +320,8 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
 			    branch_get_color(BRANCH_COLOR_REMOTE), maxwidth,
 			    remote_prefix, branch_get_color(BRANCH_COLOR_RESET));
 	} else {
-		strbuf_addf(&local, "%%(refname:strip=2)%s", branch_get_color(BRANCH_COLOR_RESET));
+		strbuf_addf(&local, "%%(refname:strip=2)%s%%(if)%%(symref)%%(then) -> %%(symref:short)%%(end)",
+			    branch_get_color(BRANCH_COLOR_RESET));
 		strbuf_addf(&remote, "%s%s%%(refname:strip=2)%s%%(if)%%(symref)%%(then) -> %%(symref:short)%%(end)",
 			    branch_get_color(BRANCH_COLOR_REMOTE), remote_prefix, branch_get_color(BRANCH_COLOR_RESET));
 	}
diff --git a/t/t6302-for-each-ref-filter.sh b/t/t6302-for-each-ref-filter.sh
index 841f0c1..206ad67 100755
--- a/t/t6302-for-each-ref-filter.sh
+++ b/t/t6302-for-each-ref-filter.sh
@@ -349,6 +349,8 @@ test_expect_success 'check %(if)...%(then)...%(end) atoms' '
 	A U Thor: refs/heads/side
 	A U Thor: refs/odd/spot
 	
+	
+	
 	A U Thor: refs/tags/foo1.10
 	A U Thor: refs/tags/foo1.3
 	A U Thor: refs/tags/foo1.6
@@ -367,7 +369,9 @@ test_expect_success 'check %(if)...%(then)...%(else)...%(end) atoms' '
 	A U Thor: refs/heads/master
 	A U Thor: refs/heads/side
 	A U Thor: refs/odd/spot
-	No author: refs/tags/double-tag
+	No author: refs/tags/annotated-tag
+	No author: refs/tags/doubly-annotated-tag
+	No author: refs/tags/doubly-signed-tag
 	A U Thor: refs/tags/foo1.10
 	A U Thor: refs/tags/foo1.3
 	A U Thor: refs/tags/foo1.6
@@ -385,7 +389,9 @@ test_expect_success 'ignore spaces in %(if) atom usage' '
 	master: Head ref
 	side: Not Head ref
 	odd/spot: Not Head ref
-	double-tag: Not Head ref
+	annotated-tag: Not Head ref
+	doubly-annotated-tag: Not Head ref
+	doubly-signed-tag: Not Head ref
 	foo1.10: Not Head ref
 	foo1.3: Not Head ref
 	foo1.6: Not Head ref
-- 
2.8.0
Next: Karthik Nayak
Message 1 of 31 in “port branch.c to use ref-filter's printing options”
  1. 00/16 port branch.c to use ref-filter's printing optionsKarthik Nayak, Apr 9, 2016
  2. 01/16 ref-filter: implement %(if), %(then), and %(else) atomsKarthik Nayak, Apr 9, 2016
  3. 02/16 ref-filter: include reference to 'used_atom' within 'atom_value'Karthik Nayak, Apr 9, 2016
  4. 03/16 ref-filter: implement %(if:equals=<string>) and %(if:notequals=<string>)Karthik Nayak, Apr 9, 2016
  5. 04/16 ref-filter: modify "%(objectname:short)" to take lengthKarthik Nayak, Apr 9, 2016
  6. 05/16 ref-filter: move get_head_description() from branch.cKarthik Nayak, Apr 9, 2016
  7. 06/16 ref-filter: introduce format_ref_array_item()Karthik Nayak, Apr 9, 2016
  8. 07/16 ref-filter: make %(upstream:track) prints "[gone]" for invalid upstreamsKarthik Nayak, Apr 9, 2016
  9. 08/16 ref-filter: add support for %(upstream:track,nobracket)Karthik Nayak, Apr 9, 2016
  10. 09/16 ref-filter: make "%(symref)" atom work with the ':short' modifierKarthik Nayak, Apr 9, 2016
  11. 10/16 ref-filter: introduce symref_atom_parser()Karthik Nayak, Apr 9, 2016
  12. 11/16 ref-filter: introduce refname_atom_parser()Karthik Nayak, Apr 9, 2016
  13. Jeff KingApr 14, 2016
  14. Karthik NayakApr 15, 2016
  15. 12/16 ref-filter: add support for %(refname:dir) and %(refname:base)Karthik Nayak, Apr 9, 2016
  16. 13/16 ref-filter: allow porcelain to translate messages in the outputKarthik Nayak, Apr 9, 2016
  17. 14/16 branch, tag: use porcelain outputKarthik Nayak, Apr 9, 2016
  18. 15/16 branch: use ref-filter printing APIsKarthik Nayak, Apr 9, 2016
  19. Junio C HamanoApr 12, 2016
  20. Junio C HamanoApr 12, 2016
  21. Karthik NayakApr 13, 2016
  22. Stefan BellerApr 16, 2016
  23. Karthik NayakApr 17, 2016
  24. 16/16 branch: implement '--format' optionKarthik Nayak, Apr 9, 2016
  25. Karthik NayakApr 13, 2016
  26. Jeff KingApr 13, 2016
  27. Karthik NayakApr 14, 2016
  28. Jeff KingApr 14, 2016
  29. Jeff KingApr 14, 2016
  30. Karthik NayakApr 15, 2016
  31. Jeff KingApr 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.