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

Re: [PATCH RFC 03/24] cat-file: split expand_atom into 2 functions

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 26, 2018, 21:46 UTC
Message-ID
<xmqqvafo5m5h.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<0102016133ff3afb-6bab2c11-e0f3-4bef-9626-fbcc826bcb15-000000@eu-west-1.amazonses.com>
Olga Telezhnaya <olyatelezhnaya@gmail.com> writes:
Show 11 quoted lines
> Split expand_atom function into 2 different functions,
> expand_atom_into_fields prepares variable for further filling,
> (new) expand_atom creates resulting string.
> 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 | 73 +++++++++++++++++++++++++++++-------------------------
>  1 file changed, 39 insertions(+), 34 deletions(-)

As expand_atom() is file-scope static and its callers are well isolated, it is OK to change its meaning while restructuring the code like this patch does (as opposed to a public function to which new callers may be added on other topics in flight).

The split itself looks sensible, but expand_atom_into_fields() is a questionable name. expand_atom() does fill the data in sb, but calling expand_atom_into_fields() does not fill any data into separated fields---it merely prepares somebody else to do so.

Helped by this comment:
	/*
	 * If mark_query is true, we do not expand anything, but rather
	 * just mark the object_info with items we wish to query.
	 */
	int mark_query;

we can guess that a better name would mention or hint "object_info", "query" and probably "prepare" (because we would do so before actually querying).

I am not sure if separating the logic into these two functions is a good way to organize things. When a new %(atom) is introduced, it is more likely that a programmer adds it to one but forgets to make a matching change to the other, no? (here, "I am not sure" is just that. It is very different from "I am sure this is wrong").

Thanks.
Previous: Olga TelezhnayaNext: Оля Тележная
Message 9 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.