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

[PATCH RFC 02/24] ref-filter: add return value to some functions

From
Olga Telezhnaya <olyatelezhnaya@gmail.com>
Date
Jan 26, 2018, 19:43 UTC
Message-ID
<0102016133ff3ad8-abf99952-4df0-42a4-9ae9-06f602e84f3b-000000@eu-west-1.amazonses.com>
In-Reply-To
<0102016133ff3a86-44d354ec-13c6-4c38-bc75-1ba4422db5a7-000000@eu-west-1.amazonses.com>

Add return flag to format_ref_array_item, show_ref_array_item, get_ref_array_info and populate_value for further using. Need it to handle situations when item is broken but we can not invoke die() because we are in batch mode and all items need to be processed.

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 | 21 +++++++++++++--------
 ref-filter.h |  4 ++--
 2 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/ref-filter.c b/ref-filter.c
index 37337b57aacf4..7030d35c84a81 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1405,7 +1405,7 @@ static void need_object(struct ref_array_item *ref) {
 /*
  * Parse the object referred by ref, and grab needed value.
  */
-static void populate_value(struct ref_array_item *ref)
+static int populate_value(struct ref_array_item *ref)
 {
 	int i;
 
@@ -1526,20 +1526,22 @@ static void populate_value(struct ref_array_item *ref)
 			break;
 		}
 	}
-	return;
+	return 0;
 }
 
 /*
  * Given a ref, return the value for the atom.  This lazily gets value
  * out of the object by calling populate value.
  */
-static void get_ref_atom_value(struct ref_array_item *ref, int atom, struct atom_value **v)
+static int get_ref_atom_value(struct ref_array_item *ref, int atom, struct atom_value **v)
 {
+	int retval = 0;
 	if (!ref->value) {
-		populate_value(ref);
+		retval = populate_value(ref);
 		fill_missing_values(ref->value);
 	}
 	*v = &ref->value[atom];
+	return retval;
 }
 
 /*
@@ -2124,7 +2126,7 @@ static void append_literal(const char *cp, const char *ep, struct ref_formatting
 	}
 }
 
-void format_ref_array_item(struct ref_array_item *info,
+int format_ref_array_item(struct ref_array_item *info,
 			   const struct ref_format *format,
 			   struct strbuf *final_buf)
 {
@@ -2158,17 +2160,20 @@ void format_ref_array_item(struct ref_array_item *info,
 		die(_("format: %%(end) atom missing"));
 	strbuf_addbuf(final_buf, &state.stack->output);
 	pop_stack_element(&state.stack);
+	return 0;
 }
 
-void show_ref_array_item(struct ref_array_item *info,
+int show_ref_array_item(struct ref_array_item *info,
 			 const struct ref_format *format)
 {
 	struct strbuf final_buf = STRBUF_INIT;
+	int retval = format_ref_array_item(info, format, &final_buf);
 
-	format_ref_array_item(info, format, &final_buf);
 	fwrite(final_buf.buf, 1, final_buf.len, stdout);
 	strbuf_release(&final_buf);
-	putchar('\n');
+	if (!retval)
+		putchar('\n');
+	return retval;
 }
 
 void pretty_print_ref(const char *name, const unsigned char *sha1,
diff --git a/ref-filter.h b/ref-filter.h
index 0d98342b34319..ff416b733b4b1 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -110,11 +110,11 @@ int verify_ref_format(struct ref_format *format);
 /*  Sort the given ref_array as per the ref_sorting provided */
 void ref_array_sort(struct ref_sorting *sort, struct ref_array *array);
 /*  Based on the given format and quote_style, fill the strbuf */
-void format_ref_array_item(struct ref_array_item *info,
+int format_ref_array_item(struct ref_array_item *info,
 			   const struct ref_format *format,
 			   struct strbuf *final_buf);
 /*  Print the ref using the given format and quote_style */
-void show_ref_array_item(struct ref_array_item *info, const struct ref_format *format);
+int show_ref_array_item(struct ref_array_item *info, const struct ref_format *format);
 /*  Parse a single sort specifier and add it to the list */
 void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *atom);
 /*  Callback function for parsing the sort option */

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