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

Re: [PATCH 14/19] [GSOC] cat-file: reuse ref-filter logic

From
ZheNing Hu <adlternative@gmail.com>
Date
Jul 12, 2021, 13:49 UTC
Message-ID
<CAOLTT8SKp2Zfd+R31+vJbW_QJG5vJArB2yPn-O_34y1ezaDBcw@mail.gmail.com>
In-Reply-To
<CAP8UFD0vHw8cK90RbOUcrAcxNKiHVTMX0VEiK8+MNyHH0CNm4A@mail.gmail.com>
Christian Couder <christian.couder@gmail.com> 于2021年7月12日周一 下午9:17写道:
Show 46 quoted lines
>
> On Mon, Jul 12, 2021 at 1:47 PM ZheNing Hu via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
> >
> > From: ZheNing Hu <adlternative@gmail.com>
> >
> > In order to let cat-file use ref-filter logic, let's do the
> > following:
> >
> > 1. Change the type of member `format` in struct `batch_options`
> > to `ref_format`, we will pass it to ref-filter later.
> > 2. Let `batch_objects()` add atoms to format, and use
> > `verify_ref_format()` to check atoms.
> > 3. Use `format_ref_array_item()` in `batch_object_write()` to
> > get the formatted data corresponding to the object. If the
> > return value of `format_ref_array_item()` is equals to zero,
> > use `batch_write()` to print object data; else if the return
> > value is less than zero, use `die()` to print the error message
> > and exit; else if return value is greater than zero, only print
> > the error message, but don't exit.
> > 4. Use free_ref_array_item_value() to free ref_array_item's
> > value.
> >
> > Most of the atoms in `for-each-ref --format` are now supported,
> > such as `%(tree)`, `%(parent)`, `%(author)`, `%(tagger)`, `%(if)`,
> > `%(then)`, `%(else)`, `%(end)`. But these atoms will be rejected:
> > `%(refname)`, `%(symref)`, `%(upstream)`, `%(push)`, `%(worktreepath)`,
> > `%(flag)`, `%(HEAD)`, because these atoms are unique to those objects
> > that pointed to by a ref, "for-each-ref"'s family can naturally use
> > these atoms, but not all objects are pointed to be a ref, so "cat-file"
> > will not be able to use them.
> >
> > The performance for `git cat-file --batch-all-objects
> > --batch-check` on the Git repository itself with performance
> > testing tool `hyperfine` changes from 669.4 ms ±  31.1 ms to
> > 1.134 s ±  0.063 s.
> >
> > The performance for `git cat-file --batch-all-objects --batch
> > >/dev/null` on the Git repository itself with performance testing
> > tool `time` change from "27.37s user 0.29s system 98% cpu 28.089
> > total" to "33.69s user 1.54s system 87% cpu 40.258 total".
>
> Saying that a later patch will add a fast path which will mitigate the
> performance regression introduced by this patch might help reassure
> reviewers.
>
OK.
> By the way it is not clear if adding the fast path fully mitigates
> this performance regression or not. You might want to discuss that in
> the cover letter, or maybe in the patch adding the fast path.
>

I mentioned it: "By using this fast path, we can reduce some of the extra overhead when cat-file --batch using ref-filter. The running time of git cat-file --batch-check will be similar to before, and the running time of git cat-file --batch will be 9.1% less than before." which is using the result of t/perf/p1006-cat-file.sh.

Show 8 quoted lines
>
> I wonder if the above function and some of the tests below could be
> introduced in a preparatory patch before this one. It could help check
> that reusing ref-filter doesn't change the behavior with some atoms
> that were previously supported or rejected. Of course if some atoms
> are now failing or are now supported, then it's ok to add new tests
> for these atoms in this patch.
>
Yes, it might be worth splitting into two commits.
Show 25 quoted lines
> > +batch_test_atom refs/heads/main '%(refname)' fail
> > +batch_test_atom refs/heads/main '%(refname:)' fail
>
> [...]
>
> > +batch_test_atom refs/heads/main 'VALID'
> > +batch_test_atom refs/heads/main '%(INVALID)' fail
> > +batch_test_atom refs/heads/main '%(authordate:INVALID)' fail
> > +
> > +test_expect_success '%(rest) works with both a branch and a tag' '
> > +       cat >expected <<-EOF &&
> > +       123 commit 123
> > +       456 tag 456
> > +       EOF
> > +       git cat-file --batch-check="%(rest) %(objecttype) %(rest)" >actual <<-EOF &&
> > +       refs/heads/main 123
> > +       refs/tags/testtag 456
> > +       EOF
> > +       test_cmp expected actual
> > +'
>
> It's a bit strange that this test is added in this patch while the
> commit message doesn't talk about %(rest). So I wonder if this new
> test could move to another previous commit.
>

It's just used for checking the uncommonly atoms "%(rest)". But as you said, we can move it to a split commit.

Show 28 quoted lines
> > +batch_test_atom refs/heads/main '%(objectname) %(objecttype) %(objectsize)
> > +%(raw)'
> > +batch_test_atom refs/tags/testtag '%(objectname) %(objecttype) %(objectsize)
> > +%(raw)'
> > +batch_test_atom refs/myblobs/blob1 '%(objectname) %(objecttype) %(objectsize)
> > +%(raw)'
> > +batch_test_atom refs/myblobs/blob2 '%(objectname) %(objecttype) %(objectsize)
> > +%(raw)'
> > +
> > +
>
> It looks like there are two empty lines instead of one above.
>
> > +test_expect_success 'cat-file --batch equals to --batch-check with atoms' '
> > +       git cat-file --batch-check="%(objectname) %(objecttype) %(objectsize)
> > +%(raw)" >expected <<-EOF &&
> > +       refs/heads/main
> > +       refs/tags/testtag
> > +       EOF
> > +       git cat-file --batch >actual <<-EOF &&
> > +       refs/heads/main
> > +       refs/tags/testtag
> > +       EOF
> > +       cmp expected actual
> > +'
>
> I also wonder if the above new test belong to this commit or if it
> could be moved to a previous commit.
It's same.

Thanks. -- ZheNing Hu

Previous: ZheNing HuNext: Junio C Hamano
Message 21 of 52 in “[GSOC] cat-file: reuse ref-filter logic”
  1. 00/19 [GSOC] cat-file: reuse ref-filter logicZheNing Hu via GitGitGadget, Jul 12, 2021
  2. 02/19 cat-file: merge two block into oneZheNing Hu via GitGitGadget, Jul 12, 2021
  3. 01/19 cat-file: handle trivial --batch format with --batch-all-objectsZheNing Hu via GitGitGadget, Jul 12, 2021
  4. 03/19 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, Jul 12, 2021
  5. 07/19 [GSOC] ref-filter: add %(rest) atomZheNing Hu via GitGitGadget, Jul 12, 2021
  6. 08/19 [GSOC] ref-filter: pass get_object() return value to their callersZheNing Hu via GitGitGadget, Jul 12, 2021
  7. 06/19 [GSOC] ref-filter: use non-const ref_format in *_atom_parser()ZheNing Hu via GitGitGadget, Jul 12, 2021
  8. 04/19 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jul 12, 2021
  9. 05/19 [GSOC] ref-filter: --format=%(raw) re-support --perlZheNing Hu via GitGitGadget, Jul 12, 2021
  10. 09/19 [GSOC] ref-filter: introduce free_ref_array_item_value() functionZheNing Hu via GitGitGadget, Jul 12, 2021
  11. 11/19 [GSOC] ref-filter: modify the error message and value in get_objectZheNing Hu via GitGitGadget, Jul 12, 2021
  12. 10/19 [GSOC] ref-filter: introduce reject_atom()ZheNing Hu via GitGitGadget, Jul 12, 2021
  13. 12/19 [GSOC] cat-file: add has_object_file() checkZheNing Hu via GitGitGadget, Jul 12, 2021
  14. 13/19 [GSOC] cat-file: change batch_objects parameter nameZheNing Hu via GitGitGadget, Jul 12, 2021
  15. 15/19 [GSOC] cat-file: reuse err buf in batch_object_write()ZheNing Hu via GitGitGadget, Jul 12, 2021
  16. 16/19 [GSOC] cat-file: re-implement --textconv, --filters optionsZheNing Hu via GitGitGadget, Jul 12, 2021
  17. 14/19 [GSOC] cat-file: reuse ref-filter logicZheNing Hu via GitGitGadget, Jul 12, 2021
  18. Christian CouderJul 12, 2021
  19. Christian CouderJul 12, 2021
  20. ZheNing HuJul 12, 2021
  21. ZheNing HuJul 12, 2021
  22. Junio C HamanoJul 12, 2021
  23. ZheNing HuJul 14, 2021
  24. ZheNing HuJul 15, 2021
  25. Christian CouderJul 15, 2021
  26. ZheNing HuJul 15, 2021
  27. ZheNing HuJul 15, 2021
  28. 17/19 [GSOC] ref-filter: remove grab_oid() functionZheNing Hu via GitGitGadget, Jul 12, 2021
  29. 18/19 [GSOC] cat-file: create p1006-cat-file.shZheNing Hu via GitGitGadget, Jul 12, 2021
  30. 19/19 [GSOC] cat-file: use fast path when using default_formatZheNing Hu via GitGitGadget, Jul 12, 2021
  31. Christian CouderJul 12, 2021
  32. ZheNing HuJul 12, 2021
  33. Philip OakleyJul 12, 2021
  34. ZheNing HuJul 12, 2021
  35. 00/17 [GSOC] cat-file: reuse ref-filter logicZheNing Hu via GitGitGadget, Jul 15, 2021
  36. 01/17 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, Jul 15, 2021
  37. 02/17 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jul 15, 2021
  38. 03/17 [GSOC] ref-filter: --format=%(raw) re-support --perlZheNing Hu via GitGitGadget, Jul 15, 2021
  39. 04/17 [GSOC] ref-filter: use non-const ref_format in *_atom_parser()ZheNing Hu via GitGitGadget, Jul 15, 2021
  40. 06/17 [GSOC] ref-filter: pass get_object() return value to their callersZheNing Hu via GitGitGadget, Jul 15, 2021
  41. 07/17 [GSOC] ref-filter: introduce free_ref_array_item_value() functionZheNing Hu via GitGitGadget, Jul 15, 2021
  42. 05/17 [GSOC] ref-filter: add %(rest) atomZheNing Hu via GitGitGadget, Jul 15, 2021
  43. 09/17 [GSOC] ref-filter: modify the error message and value in get_objectZheNing Hu via GitGitGadget, Jul 15, 2021
  44. 10/17 [GSOC] cat-file: add has_object_file() checkZheNing Hu via GitGitGadget, Jul 15, 2021
  45. 11/17 [GSOC] cat-file: change batch_objects parameter nameZheNing Hu via GitGitGadget, Jul 15, 2021
  46. 12/17 [GSOC] cat-file: create p1006-cat-file.shZheNing Hu via GitGitGadget, Jul 15, 2021
  47. 08/17 [GSOC] ref-filter: add cat_file_mode to ref_formatZheNing Hu via GitGitGadget, Jul 15, 2021
  48. 15/17 [GSOC] cat-file: re-implement --textconv, --filters optionsZheNing Hu via GitGitGadget, Jul 15, 2021
  49. 14/17 [GSOC] cat-file: reuse err buf in batch_object_write()ZheNing Hu via GitGitGadget, Jul 15, 2021
  50. 13/17 [GSOC] cat-file: reuse ref-filter logicZheNing Hu via GitGitGadget, Jul 15, 2021
  51. 16/17 [GSOC] ref-filter: remove grab_oid() functionZheNing Hu via GitGitGadget, Jul 15, 2021
  52. 17/17 [GSOC] cat-file: use fast path when using default_formatZheNing Hu via GitGitGadget, Jul 15, 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.