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

[PATCH v2 10/16] ref-filter: introduce symref_atom_parser()

From
Karthik Nayak <karthik.188@gmail.com>
Date
Mar 15, 2016, 16:47 UTC
Message-ID
<1458060436-1215-11-git-send-email-Karthik.188@gmail.com>
In-Reply-To
<1458060436-1215-1-git-send-email-Karthik.188@gmail.com>

Introduce symref_atom_parser() which will parse the '%(symref)' atom and store information into the 'used_atom' structure based on the modifiers used along with the atom.

Signed-off-by: Karthik Nayak <Karthik.188@gmail.com>
---
 ref-filter.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/ref-filter.c b/ref-filter.c
index 5c59b17..7b35e4f 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -62,6 +62,7 @@ static struct used_atom {
 			enum { O_FULL, O_LENGTH, O_SHORT } option;
 			unsigned int length;
 		} objectname;
+		enum { S_FULL, S_SHORT } symref;
 	} u;
 } *used_atom;
 static int used_atom_cnt, need_tagged, need_symref;
@@ -217,6 +218,15 @@ static void if_atom_parser(struct used_atom *atom, const char *arg)
 		die(_("unrecognized %%(if) argument: %s"), arg);
 }
 
+static void symref_atom_parser(struct used_atom *atom, const char *arg)
+{
+	if (!arg)
+		atom->u.symref = S_FULL;
+	else if (!strcmp(arg, "short"))
+		atom->u.symref = S_SHORT;
+	else
+		die(_("unrecognized %%(symref) argument: %s"), arg);
+}
 
 static struct {
 	const char *name;
@@ -252,7 +262,7 @@ static struct {
 	{ "contents", FIELD_STR, contents_atom_parser },
 	{ "upstream", FIELD_STR, remote_ref_atom_parser },
 	{ "push", FIELD_STR, remote_ref_atom_parser },
-	{ "symref" },
+	{ "symref", FIELD_STR, symref_atom_parser },
 	{ "flag" },
 	{ "HEAD" },
 	{ "color", FIELD_STR, color_atom_parser },
@@ -1132,6 +1142,17 @@ char *get_head_description(void)
 	return strbuf_detach(&desc, NULL);
 }
 
+static const char *get_symref(struct used_atom *atom, struct ref_array_item *ref)
+{
+	if (!ref->symref)
+		return "";
+	else if (atom->u.symref == S_SHORT)
+		return shorten_unambiguous_ref(ref->symref,
+					       warn_ambiguous_refs);
+	else
+		return ref->symref;
+}
+
 /*
  * Parse the object referred by ref, and grab needed value.
  */
@@ -1176,7 +1197,7 @@ static void populate_value(struct ref_array_item *ref)
 			if (ref->kind & FILTER_REFS_DETACHED_HEAD)
 				refname = get_head_description();
 		} else if (starts_with(name, "symref"))
-			refname = ref->symref ? ref->symref : "";
+			refname = get_symref(atom, ref);
 		else if (starts_with(name, "upstream")) {
 			const char *branch_name;
 			/* only local branches may have an upstream */
-- 
2.7.3
Previous: Karthik NayakNext: Karthik Nayak
Message 13 of 21 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, Mar 15, 2016
  2. 01/16 ref-filter: implement %(if), %(then), and %(else) atomsKarthik Nayak, Mar 15, 2016
  3. 02/16 ref-filter: include reference to 'used_atom' within 'atom_value'Karthik Nayak, Mar 15, 2016
  4. 03/16 ref-filter: implement %(if:equals=<string>) and %(if:notequals=<string>)Karthik Nayak, Mar 15, 2016
  5. 04/16 ref-filter: modify "%(objectname:short)" to take lengthKarthik Nayak, Mar 15, 2016
  6. Jacob KellerMar 15, 2016
  7. Karthik NayakMar 18, 2016
  8. 05/16 ref-filter: move get_head_description() from branch.cKarthik Nayak, Mar 15, 2016
  9. 06/16 ref-filter: introduce format_ref_array_item()Karthik Nayak, Mar 15, 2016
  10. 07/16 ref-filter: make %(upstream:track) prints "[gone]" for invalid upstreamsKarthik Nayak, Mar 15, 2016
  11. 08/16 ref-filter: add support for %(upstream:track,nobracket)Karthik Nayak, Mar 15, 2016
  12. 09/16 ref-filter: make "%(symref)" atom work with the ':short' modifierKarthik Nayak, Mar 15, 2016
  13. 10/16 ref-filter: introduce symref_atom_parser()Karthik Nayak, Mar 15, 2016
  14. 11/16 ref-filter: introduce refname_atom_parser()Karthik Nayak, Mar 15, 2016
  15. 12/16 ref-filter: add support for %(refname:dir) and %(refname:base)Karthik Nayak, Mar 15, 2016
  16. 13/16 ref-filter: allow porcelain to translate messages in the outputKarthik Nayak, Mar 15, 2016
  17. 14/16 branch, tag: use porcelain outputKarthik Nayak, Mar 15, 2016
  18. 15/16 branch: use ref-filter printing APIsKarthik Nayak, Mar 15, 2016
  19. 16/16 branch: implement '--format' optionKarthik Nayak, Mar 15, 2016
  20. Jacob KellerMar 15, 2016
  21. Karthik NayakMar 18, 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.