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

Re: [PATCH 4/6] [GSOC] ref-filter: add %(rest) atom and --rest option

From
ZheNing Hu <adlternative@gmail.com>
Date
Jun 9, 2021, 12:47 UTC
Message-ID
<CAOLTT8QQPfYdE3GzNt9BEPvLvPdJg8zS6-Dn3L26BdQ6M7Tk6g@mail.gmail.com>
In-Reply-To
<xmqq4ke7jzee.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> 于2021年6月9日周三 下午3:00写道:
Show 13 quoted lines
>
> I think I kind-of see what is going on here.  There is
>
>     git cat-file blob --textconv --path="$path" "$blob_object_name"
>
> that allows a blob to be fed to the command, pretend as if it
> appears at $path in a tree object and grab attribute for it, and
> show the blob contents converted using the textconv filter.  If we
> were to mimic it by extending the format based substitutions, a
> design consistent with the behaviour is to teach --format=%(raw)
> to show the contents after applying the textconv filter instead of
> the raw blob contents.
>
Yes, this is exactly what cat-file --textconv does.
Show 9 quoted lines
> And there is a corresponding
>
>     git cat-file --batch --textconv
>
> The "--path=$path" parameter is omitted when using --batch, as each
> object would sit at different path in the tree (so the input stream
> would be given as a run of "<blob> <path>" to give each item its own
> path).
>
Just like let --batch omitted --path, --rest is meaningless for "for-ech-ref".
Show 11 quoted lines
> So to answer my question in the previous message, yes, this is an
> attempt to support the "cat-file --textconv".  So in the context of
> that command, something may need to be added.  But I do not think it
> makes any sense to expose that to for-each-ref and friends, even if
> we were to share the internal machinery (after all, sharing of the
> internal machinery is a mere means to an end that is to make it
> easier to give the same syntax and same behaviour to end users and
> is not a goal itself; "because we use the same machinery, the users
> have to tolerate that irrelevant %(atoms) are accepted by the parser"
> is not making a good excuse for a sloppy implementation).
>

Because "git cat-file --batch" will only print the contents of the object once, so when implements the function of textconv/filters in ref-filter, we should really consider whether we should let something like "%(raw) %(raw) %(raw) %(raw:size)" all pass the conversion of textconv/filters. If it is my previous %(raw:textconv) or %(raw:filter), they can only print the converted content separately, and we need:

$ git for-ecah-ref --format="%(raw:filters) %(raw:filters) %(raw:filters) %(raw:filters:size)"

As you said it might be too complicated for the user....
Show 14 quoted lines
> Having said all that, I somehow doubt that the "--batch=<format>"
> was designed to interact sensibly with the "--textconv" option.
> builtin/cat-file.c::expand_atom() does not know anything at all that
> the data could be modified from the raw contents of the blob, so
> --batch="%(contents) %(size)" --textconv, if existed, may show the
> conveted contents with size of blob before conversion, or something
> incoherent like that.  And if your rewrite using the shared internal
> machinery results in a more coherent behaviour, that would be
> excellent.  For example, we could imagine that the machinery, when
> textconv (or filter) is in use, would first grab the blob contents
> and run the requested conversion, and then work solely on that
> conveted contents when computing what to fill with %(raw:size) and
> other blob-related atoms.
>
And with your --textconv/--filters, we only need:
$ git for-ecah-ref --format="%(raw) %(raw) %(raw) %(raw:size)" --filters

This will be more concise for users. I will try to build --filters, --textconv for ref-filter . But as stated in the previous reply, it needs to be placed after the transplant of cat-file --batch (Because --path is useless for for-each-ref, and at the same time we need proper testing for --filter/--textconv.)

Thanks, your reply is very reasonable, -- ZheNing Hu

Previous: Junio C HamanoNext: Junio C Hamano
Message 18 of 27 in “[GSOC][RFC] ref-filter: add %(raw:textconv) and %(raw:filters)”
  1. 0/6 [GSOC][RFC] ref-filter: add %(raw:textconv) and %(raw:filters)ZheNing Hu via GitGitGadget, Jun 5, 2021
  2. 2/6 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jun 5, 2021
  3. Junio C HamanoJun 8, 2021
  4. ZheNing HuJun 8, 2021
  5. 1/6 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, Jun 5, 2021
  6. 3/6 [GSOC] ref-filter: use non-const ref_format in *_atom_parser()ZheNing Hu via GitGitGadget, Jun 5, 2021
  7. 5/6 [GSOC] ref-filter: teach grab_sub_body_contents() return value and errZheNing Hu via GitGitGadget, Jun 5, 2021
  8. 4/6 [GSOC] ref-filter: add %(rest) atom and --rest optionZheNing Hu via GitGitGadget, Jun 5, 2021
  9. Hariom vermaJun 5, 2021
  10. ZheNing HuJun 6, 2021
  11. Junio C HamanoJun 7, 2021
  12. ZheNing HuJun 7, 2021
  13. ZheNing HuJun 7, 2021
  14. ZheNing HuJun 8, 2021
  15. Junio C HamanoJun 8, 2021
  16. ZheNing HuJun 8, 2021
  17. Junio C HamanoJun 9, 2021
  18. ZheNing HuJun 9, 2021
  19. Junio C HamanoJun 8, 2021
  20. ZheNing HuJun 8, 2021
  21. 6/6 [GSOC] ref-filter: add %(raw:textconv) and %(raw:filters)ZheNing Hu via GitGitGadget, Jun 5, 2021
  22. Bagas SanjayaJun 5, 2021
  23. ZheNing HuJun 5, 2021
  24. Junio C HamanoJun 7, 2021
  25. ZheNing HuJun 7, 2021
  26. Junio C HamanoJun 8, 2021
  27. ZheNing HuJun 8, 2021

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.