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

[PATCH RFC v2 03/25] cat-file: reuse struct ref_format

From
Olga Telezhnaya <olyatelezhnaya@gmail.com>
Date
Feb 5, 2018, 11:27 UTC
Message-ID
<0102016165b8b444-99fcbf50-ab35-4781-821a-a0dc90ed813b-000000@eu-west-1.amazonses.com>
In-Reply-To
<0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com>

Start using ref_format struct instead of simple char*. Need that for further reusing of formatting logic from ref-filter.

Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored by: Jeff King <peff@peff.net>
---
 builtin/cat-file.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index f5fa4fd75af26..98fc5ec069a49 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -13,15 +13,16 @@
 #include "tree-walk.h"
 #include "sha1-array.h"
 #include "packfile.h"
+#include "ref-filter.h"
 
 struct batch_options {
+	struct ref_format format;
 	int enabled;
 	int follow_symlinks;
 	int print_contents;
 	int buffer_output;
 	int all_objects;
 	int cmdmode; /* may be 'w' or 'c' for --filters or --textconv */
-	const char *format;
 };
 
 static const char *force_path;
@@ -348,7 +349,7 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,
 		return;
 	}
 
-	strbuf_expand(&buf, opt->format, expand_format, data);
+	strbuf_expand(&buf, opt->format.format, expand_format, data);
 	strbuf_addch(&buf, '\n');
 	batch_write(opt, buf.buf, buf.len);
 	strbuf_release(&buf);
@@ -441,8 +442,8 @@ static int batch_objects(struct batch_options *opt)
 	int save_warning;
 	int retval = 0;
 
-	if (!opt->format)
-		opt->format = "%(objectname) %(objecttype) %(objectsize)";
+	if (!opt->format.format)
+		opt->format.format = "%(objectname) %(objecttype) %(objectsize)";
 
 	/*
 	 * Expand once with our special mark_query flag, which will prime the
@@ -451,7 +452,7 @@ static int batch_objects(struct batch_options *opt)
 	 */
 	memset(&data, 0, sizeof(data));
 	data.mark_query = 1;
-	strbuf_expand(&buf, opt->format, expand_format, &data);
+	strbuf_expand(&buf, opt->format.format, expand_format, &data);
 	data.mark_query = 0;
 	if (opt->cmdmode)
 		data.split_on_whitespace = 1;
@@ -543,7 +544,7 @@ static int batch_option_callback(const struct option *opt,
 
 	bo->enabled = 1;
 	bo->print_contents = !strcmp(opt->long_name, "batch");
-	bo->format = arg;
+	bo->format.format = arg;
 
 	return 0;
 }
@@ -552,7 +553,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
 {
 	int opt = 0;
 	const char *exp_type = NULL, *obj_name = NULL;
-	struct batch_options batch = {0};
+	struct batch_options batch = { REF_FORMAT_INIT };
 	int unknown_type = 0;
 
 	const struct option options[] = {

--
https://github.com/git/git/pull/452
Previous: Olga TelezhnayaNext: Olga Telezhnaya
Message 10 of 26 in “ref-filter: get rid of goto”
  1. 01/25 ref-filter: get rid of gotoOlga Telezhnaya, Feb 5, 2018
  2. 08/25 ref-filter: reuse parse_ref_filter_atom()Olga Telezhnaya, Feb 5, 2018
  3. 05/25 cat-file: move struct expand_data into ref-filterOlga Telezhnaya, Feb 5, 2018
  4. 22/25 ref-filter: work with objectsize:diskOlga Telezhnaya, Feb 5, 2018
  5. 13/25 ref-filter: get rid of mark_atom_in_object_info()Olga Telezhnaya, Feb 5, 2018
  6. 06/25 cat-file: split expand_atom() into 2 functionsOlga Telezhnaya, Feb 5, 2018
  7. 16/25 cat-file: move skip_object_info into ref-filterOlga Telezhnaya, Feb 5, 2018
  8. 11/25 ref-filter: rename field in ref_array_item stuctOlga Telezhnaya, Feb 5, 2018
  9. 04/25 ref-filter: make valid_atom as function parameterOlga Telezhnaya, Feb 5, 2018
  10. 03/25 cat-file: reuse struct ref_formatOlga Telezhnaya, Feb 5, 2018
  11. 25/25 cat-file: update of docsOlga Telezhnaya, Feb 5, 2018
  12. 24/25 cat-file: tests for new atoms addedOlga Telezhnaya, Feb 5, 2018
  13. 15/25 ref_filter: add is_atom_used functionOlga Telezhnaya, Feb 5, 2018
  14. 10/25 ref-filter: make populate_value() globalOlga Telezhnaya, Feb 5, 2018
  15. 18/25 ref-filter: make valid_atom general againOlga Telezhnaya, Feb 5, 2018
  16. 02/25 ref-filter: add return value to some functionsOlga Telezhnaya, Feb 5, 2018
  17. 20/25 ref-filter: make populate_value() internal againOlga Telezhnaya, Feb 5, 2018
  18. 19/25 cat-file: reuse printing logic from ref-filterOlga Telezhnaya, Feb 5, 2018
  19. 12/25 cat-file: start reusing populate_value()Olga Telezhnaya, Feb 5, 2018
  20. 14/25 ref-filter: add is_cat flagOlga Telezhnaya, Feb 5, 2018
  21. Junio C HamanoFeb 5, 2018
  22. 21/25 ref-filter: unifying formatting of cat-file optsOlga Telezhnaya, Feb 5, 2018
  23. 09/25 cat-file: start use ref_array_item structOlga Telezhnaya, Feb 5, 2018
  24. 17/25 ref-filter: make cat_file_info independentOlga Telezhnaya, Feb 5, 2018
  25. 23/25 for-each-ref: tests for new atoms addedOlga Telezhnaya, Feb 5, 2018
  26. 07/25 cat-file: start migrating formatting to ref-filterOlga Telezhnaya, Feb 5, 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.