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

Re: [PATCH v3 16/23] ref-filter: make cat_file_info independent

From
Jeff King <peff@peff.net>
Date
Feb 16, 2018, 21:54 UTC
Message-ID
<20180216215442.GA22270@sigill.intra.peff.net>
In-Reply-To
<CAL21BmmFaDstAT3Jm6AWh95mfWLJqN1MQF+pBTa3erX5w9MWRQ@mail.gmail.com>
On Thu, Feb 15, 2018 at 01:33:25PM +0300, Оля Тележная wrote:
Show 20 quoted lines
> 2018-02-15 8:53 GMT+03:00 Jeff King <peff@peff.net>:
> > On Mon, Feb 12, 2018 at 08:08:54AM +0000, Olga Telezhnaya wrote:
> >
> >> Remove connection between expand_data variable
> >> in cat-file and in ref-filter.
> >> It will help further to get rid of using expand_data in cat-file.
> >
> > I have to admit I'm confused at this point about what is_cat_file is
> > for, or even why we need cat_file_data. Shouldn't these items be handled
> > by their matching ref-filter atoms at this point?
> 
> We discussed that earlier outside of mailing list, and I even tried to
> implement that idea and spent a couple of days to prove that it's not
> possible.
> The problem is that the list of atoms is made dynamically, and we
> can't store pointers to any values in each atom. That's why we need
> separate cat_file_info variable that is outside of main atom list.
> We also need is_cat_file because we still have some part of logic that
> is different for cat-file and for all other commands, and sometimes we
> need to know that information.

OK, right, I forgot about the pointers thing. This is definitely the sort of design decision that should go into the commit message.

I went over our off-list discussion again to refresh my memory. Let me try to summarize a bit (for myself, or for other readerss). Naively, one would hope that you could do something like:

  1. While parsing the %(objectsize) atom, add a pointer like:
       the_object_info->sizep = &atom.size;
  2. Later when fulfilling the request for a specific object, if
     the_object_info is not empty, then call sha1_object_info() with it
     to hold the results.
  3. Read the value out of atom.size when assembling the formatted
     string.
But that has two problems:
  a. During parsing, we're resizing the atom array, so the &atom.size
     pointer is subject to change.  This is the issue you mentioned
     above. I think we could solve it by taking a pass over the atoms
     after parsing and filling in the pointers then. But...
  b. Another problem is that the same atom may appear multiple times. So
     parsing "%(objectsize) %(objectsize)", we can't point
     the_object_info at _both_ of them. We need our call to
     sha1_object_info() to store the result in a single location, and
     then as we format each atom they can both use that (which works
     even if they might format it differently, say if you had
     "%(deltabase) %(deltabase:abbrev)".

So we do need some kind of global storage to hold these results. This is sort of the same problem we have with parsing the objects at all. There we get by without a global because all of the logic is crammed into populate_value(). In theory we could do the same thing here, but there are just a lot of different items we might be asking for. So instead of "need_tagged", you'd have a multitude of need_objectsize_disk, need_deltabase, etc, which gets unwieldy. We may as well fill in a "struct object_info".

So OK, I agree that something like "struct expand_data" is needed.

But what seems non-ideal to me is the way that ref-filter depends on it in this cat-file-specific way. If it needs those values it should be calling sha1_object_info(). And if it doesn't, then it can skip the call. It shouldn't need to know about cat-file at all.

And likewise cat-file should not know about expand_data. And I think that's true by the end of the series, though the steps in the middle left me a little confused.

-Peff
Previous: Оля ТележнаяNext: Olga Telezhnaya
Message 17 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.