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

[PATCH v3 08/23] ref-filter: reuse parse_ref_filter_atom()

From
Olga Telezhnaya <olyatelezhnaya@gmail.com>
Date
Feb 12, 2018, 08:08 UTC
Message-ID
<01020161890f434b-3f93f5b7-0fad-4777-ab9b-79c48b2b41d2-000000@eu-west-1.amazonses.com>
In-Reply-To
<01020161890f4236-47989eb4-c19f-4282-9084-9d4f90c2ebeb-000000@eu-west-1.amazonses.com>

Continue migrating formatting logic from cat-file to ref-filter. Reuse parse_ref_filter_atom() for unifying all processes in ref-filter and further removing of mark_atom_in_object_info().

Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored by: Jeff King <peff@peff.net>
---
 ref-filter.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)
diff --git a/ref-filter.c b/ref-filter.c
index ff87e632f463c..5c75259b1ab8c 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -100,6 +100,7 @@ static struct used_atom {
 	} u;
 } *used_atom;
 static int used_atom_cnt, need_tagged, need_symref;
+struct expand_data *cat_file_info;
 
 static void color_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *color_value)
 {
@@ -251,6 +252,16 @@ static void objectname_atom_parser(const struct ref_format *format, struct used_
 		die(_("unrecognized %%(objectname) argument: %s"), arg);
 }
 
+static void objectsize_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg)
+{
+	if (!arg)
+		; /* default to normal object size */
+	else if (!strcmp(arg, "disk"))
+		cat_file_info->info.disk_sizep = &cat_file_info->disk_size;
+	else
+		die(_("urecognized %%(objectsize) argument: %s"), arg);
+}
+
 static void refname_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg)
 {
 	refname_atom_parser_internal(&atom->u.refname, arg, atom->name);
@@ -371,6 +382,14 @@ static struct valid_atom {
 	{ "else" },
 };
 
+static struct valid_atom valid_cat_file_atom[] = {
+	{ "objectname" },
+	{ "objecttype" },
+	{ "objectsize", FIELD_ULONG, objectsize_atom_parser },
+	{ "rest" },
+	{ "deltabase" },
+};
+
 #define REF_FORMATTING_STATE_INIT  { 0, NULL }
 
 struct ref_formatting_stack {
@@ -401,20 +420,14 @@ static int is_atom(const char *atom, const char *s, int slen)
 static void mark_atom_in_object_info(const char *atom, int len,
 				    struct expand_data *data)
 {
-	if (is_atom("objectname", atom, len))
-		; /* do nothing */
-	else if (is_atom("objecttype", atom, len))
+	if (is_atom("objecttype", atom, len))
 		data->info.typep = &data->type;
 	else if (is_atom("objectsize", atom, len))
 		data->info.sizep = &data->size;
-	else if (is_atom("objectsize:disk", atom, len))
-		data->info.disk_sizep = &data->disk_size;
 	else if (is_atom("rest", atom, len))
 		data->split_on_whitespace = 1;
 	else if (is_atom("deltabase", atom, len))
 		data->info.delta_base_sha1 = data->delta_base_oid.hash;
-	else
-		die("unknown format element: %.*s", len, atom);
 }
 
 /*
@@ -483,6 +496,8 @@ static int parse_ref_filter_atom(const struct ref_format *format,
 		need_tagged = 1;
 	if (!strcmp(valid_atom[i].name, "symref"))
 		need_symref = 1;
+	if (cat_file_info)
+		mark_atom_in_object_info(atom, atom_len, cat_file_info);
 	return at;
 }
 
@@ -726,6 +741,7 @@ int verify_ref_format(struct ref_format *format)
 {
 	const char *cp, *sp;
 
+	cat_file_info = format->cat_file_data;
 	format->need_color_reset_at_eol = 0;
 	for (cp = format->format; *cp && (sp = find_next(cp)); ) {
 		const char *color, *ep = strchr(sp, ')');
@@ -736,8 +752,8 @@ int verify_ref_format(struct ref_format *format)
 		/* sp points at "%(" and ep points at the closing ")" */
 
 		if (format->cat_file_data)
-			mark_atom_in_object_info(sp + 2, ep - sp - 2,
-						format->cat_file_data);
+			at = parse_ref_filter_atom(format, valid_cat_file_atom,
+						   ARRAY_SIZE(valid_cat_file_atom), sp + 2, ep);
 		else {
 			at = parse_ref_filter_atom(format, valid_atom,
 						   ARRAY_SIZE(valid_atom), sp + 2, ep);

--
https://github.com/git/git/pull/452
Previous: Jeff KingNext: Jeff King
Message 4 of 56 in “ref-filter: get rid of goto”
  1. 01/23 ref-filter: get rid of gotoOlga Telezhnaya, Feb 12, 2018
  2. 03/23 cat-file: reuse struct ref_formatOlga Telezhnaya, Feb 12, 2018
  3. Jeff KingFeb 15, 2018
  4. 08/23 ref-filter: reuse parse_ref_filter_atom()Olga Telezhnaya, Feb 12, 2018
  5. Jeff KingFeb 15, 2018
  6. Оля ТележнаяFeb 15, 2018
  7. 04/23 ref-filter: make valid_atom as function parameterOlga Telezhnaya, Feb 12, 2018
  8. Jeff KingFeb 15, 2018
  9. Оля ТележнаяFeb 15, 2018
  10. 11/23 ref-filter: rename field in ref_array_item stuctOlga Telezhnaya, Feb 12, 2018
  11. 07/23 cat-file: start migrating formatting to ref-filterOlga Telezhnaya, Feb 12, 2018
  12. Jeff KingFeb 15, 2018
  13. 19/23 ref-filter: make populate_value() internal againOlga Telezhnaya, Feb 12, 2018
  14. 16/23 ref-filter: make cat_file_info independentOlga Telezhnaya, Feb 12, 2018
  15. Jeff KingFeb 15, 2018
  16. Оля ТележнаяFeb 15, 2018
  17. Jeff KingFeb 16, 2018
  18. 20/23 ref-filter: unifying formatting of cat-file optsOlga Telezhnaya, Feb 12, 2018
  19. Jeff KingFeb 15, 2018
  20. Оля ТележнаяFeb 15, 2018
  21. Junio C HamanoFeb 15, 2018
  22. 10/23 ref-filter: make populate_value() globalOlga Telezhnaya, Feb 12, 2018
  23. 15/23 cat-file: move skip_object_info into ref-filterOlga Telezhnaya, Feb 12, 2018
  24. Jeff KingFeb 15, 2018
  25. Оля ТележнаяFeb 15, 2018
  26. 21/23 for-each-ref: tests for new atoms addedOlga Telezhnaya, Feb 12, 2018
  27. Jeff KingFeb 15, 2018
  28. Оля ТележнаяFeb 15, 2018
  29. 02/23 ref-filter: add return value to some functionsOlga Telezhnaya, Feb 12, 2018
  30. Jeff KingFeb 15, 2018
  31. Оля ТележнаяFeb 15, 2018
  32. 09/23 cat-file: start use ref_array_item structOlga Telezhnaya, Feb 12, 2018
  33. Jeff KingFeb 15, 2018
  34. Оля ТележнаяFeb 15, 2018
  35. 18/23 cat-file: reuse printing logic from ref-filterOlga Telezhnaya, Feb 12, 2018
  36. 05/23 cat-file: move struct expand_data into ref-filterOlga Telezhnaya, Feb 12, 2018
  37. Jeff KingFeb 15, 2018
  38. 23/23 cat-file: update of docsOlga Telezhnaya, Feb 12, 2018
  39. Jeff KingFeb 15, 2018
  40. 12/23 cat-file: start reusing populate_value()Olga Telezhnaya, Feb 12, 2018
  41. Jeff KingFeb 15, 2018
  42. 14/23 ref_filter: add is_atom_used functionOlga Telezhnaya, Feb 12, 2018
  43. Jeff KingFeb 15, 2018
  44. Оля ТележнаяFeb 15, 2018
  45. 17/23 ref-filter: make valid_atom general againOlga Telezhnaya, Feb 12, 2018
  46. Jeff KingFeb 15, 2018
  47. 13/23 ref-filter: get rid of mark_atom_in_object_info()Olga Telezhnaya, Feb 12, 2018
  48. Jeff KingFeb 15, 2018
  49. Оля ТележнаяFeb 15, 2018
  50. 22/23 cat-file: tests for new atoms addedOlga Telezhnaya, Feb 12, 2018
  51. Adam DinwoodieFeb 16, 2018
  52. Ramsay JonesFeb 18, 2018
  53. Ramsay JonesFeb 19, 2018
  54. 06/23 cat-file: split expand_atom() into 2 functionsOlga Telezhnaya, Feb 12, 2018
  55. Jeff KingFeb 15, 2018
  56. Jeff KingFeb 15, 2018

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.