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

Re: [PATCH 2/8] [GSOC] ref-filter: add %(raw) atom

From
ZheNing Hu <adlternative@gmail.com>
Date
Jun 17, 2021, 16:14 UTC
Message-ID
<CAOLTT8SGkObKWMZax-k4KXgsN+7ezvOMkRU-zt+c2zon2Ta3pA@mail.gmail.com>
In-Reply-To
<87r1h0wnwg.fsf@evledraar.gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> 于2021年6月17日周四 下午10:45写道:
Show 13 quoted lines
>
>
> On Thu, Jun 17 2021, ZheNing Hu wrote:
>
> >
> > Yes, strbuf is a suitable choice when using <str,len> pair.
> > But if replace v->s with strbuf, the possible changes will be larger.
>
> I for one would like to see it done that way, those changes are usually
> easy to read. Also it seems a large part of 2/8 is extra new code
> because we didn't do that, e.g. getting length differently if something
> is a strbuf or not, passing char*/size_t pairs to new functions etc.
>
After some refactoring, I found that there are two problems:
1. There are a lot of codes like this in ref-filter to fill v->s:

v->s = show_ref(...) v->s = copy_email(...)

It is very difficult to modify here: We know that show_ref() or copy_email() will allocate a block of memory to v->s, but if v->s is a strbuf, what should we do? In copy_email(), we can pass the v->s to copy_email() and use strbuf_add()/strbuf_addstr() instead of xstrdup() and xmemdupz(). But show_ref() will call external functions like shorten_unambiguous_ref(), we don’t know whether it will return us NULL or a dynamically allocated memory. If continue to pass v->s to the inner function, it is not a feasible method. Or we can use strbuf_attach() + strlen(), I'm not sure this is a good method.

2. See:
-       for (i = 0; i < used_atom_cnt; i++) {
+       for (i = 0; i < used_atom_cnt; i++) {
                struct atom_value *v = &ref->value[i];
-               if (v->s == NULL && used_atom[i].source == SOURCE_NONE)
+               if (v->s.len == 0 && used_atom[i].source == SOURCE_NONE)
                        return strbuf_addf_ret(err, -1, _("missing
object %s for %s"),
oid_to_hex(&ref->objectname), ref->refname);
        }

In the case of using strbuf, I don’t know how to distinguish between an empty strbuf and NULL. It can be easily distinguished by using c-style "const char*".

Show 8 quoted lines
> >
> > Not python safe. See [1].
> > Regarding the perl language, I support Junio's point of view: it can be
> > re-supported in the future.
>
> Ah, I'd missed that. Anyway, if it's easy it seems you discovered that
> Perl deals with it correctly, so we could just have it support this.
>
Well, it's ok, support for perl will be put in a separate commit.
Show 37 quoted lines
> >>
> >> > +test_expect_success 'basic atom: refs/tags/testtag *raw' '
> >> > +     git cat-file commit refs/tags/testtag^{} >expected &&
> >> > +     git for-each-ref --format="%(*raw)" refs/tags/testtag >actual &&
> >> > +     sanitize_pgp <expected >expected.clean &&
> >> > +     sanitize_pgp <actual >actual.clean &&
> >> > +     echo "" >>expected.clean &&
> >>
> >> Just "echo" will do, ditto for the rest. Also odd to go back and forth
> >> between populating expected.clean & actual.clean.
> >>
> >
> > Are you saying that sanitize_pgp is not needed?
>
> No that instead of:
>
>     echo "" >x
>
> You can do:
>
>     echo >x
>
> And also that going back and forth between populating different files is
> confusing, i.e. this:
>
>
>     echo a >x
>     echo c >y
>     echo b >>x
>
> is better as:
>
>     echo a >x
>     echo b >>x
>     echo c >y
>
>
Thanks, I get what you meant now.
Show 28 quoted lines
> >>
> >> > +test_expect_success 'set up refs pointing to binary blob' '
> >> > +     printf "a\0b\0c" >blob1 &&
> >> > +     printf "a\0c\0b" >blob2 &&
> >> > +     printf "\0a\0b\0c" >blob3 &&
> >> > +     printf "abc" >blob4 &&
> >> > +     printf "\0 \0 \0 " >blob5 &&
> >> > +     printf "\0 \0a\0 " >blob6 &&
> >> > +     printf "  " >blob7 &&
> >> > +     >blob8 &&
> >> > +     git hash-object blob1 -w | xargs git update-ref refs/myblobs/blob1 &&
> >> > +     git hash-object blob2 -w | xargs git update-ref refs/myblobs/blob2 &&
> >> > +     git hash-object blob3 -w | xargs git update-ref refs/myblobs/blob3 &&
> >> > +     git hash-object blob4 -w | xargs git update-ref refs/myblobs/blob4 &&
> >> > +     git hash-object blob5 -w | xargs git update-ref refs/myblobs/blob5 &&
> >> > +     git hash-object blob6 -w | xargs git update-ref refs/myblobs/blob6 &&
> >> > +     git hash-object blob7 -w | xargs git update-ref refs/myblobs/blob7 &&
> >> > +     git hash-object blob8 -w | xargs git update-ref refs/myblobs/blob8
> >>
> >> Hrm, xargs just to avoid:
> >>
> >>     git update-ref ... $(git hash-object) ?
> >>
> >
> > I didn’t think about it, just for convenience.
>
> *nod*, Junio had a good suggestion.
>
ok.

Thanks. -- ZheNing Hu

Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 13 of 121 in “[GSOC][RFC] cat-file: reuse ref-filter logic”
  1. 0/8 [GSOC][RFC] cat-file: reuse ref-filter logicZheNing Hu via GitGitGadget, Jun 12, 2021
  2. 3/8 [GSOC] ref-filter: use non-const ref_format in *_atom_parser()ZheNing Hu via GitGitGadget, Jun 12, 2021
  3. 6/8 [GSOC] cat-file: reuse ref-filter logicZheNing Hu via GitGitGadget, Jun 12, 2021
  4. 8/8 [GSOC] cat-file: re-implement --textconv, --filters optionsZheNing Hu via GitGitGadget, Jun 12, 2021
  5. Ævar Arnfjörð BjarmasonJun 17, 2021
  6. ZheNing HuJun 17, 2021
  7. 4/8 [GSOC] ref-filter: add %(rest) atomZheNing Hu via GitGitGadget, Jun 12, 2021
  8. 2/8 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jun 12, 2021
  9. Ævar Arnfjörð BjarmasonJun 17, 2021
  10. Junio C HamanoJun 17, 2021
  11. ZheNing HuJun 17, 2021
  12. Ævar Arnfjörð BjarmasonJun 17, 2021
  13. ZheNing HuJun 17, 2021
  14. Ævar Arnfjörð BjarmasonJun 18, 2021
  15. Christian CouderJun 18, 2021
  16. 1/8 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, Jun 12, 2021
  17. Ævar Arnfjörð BjarmasonJun 17, 2021
  18. Junio C HamanoJun 17, 2021
  19. 5/8 [GSOC] ref-filter: teach get_object() return useful valueZheNing Hu via GitGitGadget, Jun 12, 2021
  20. Christian CouderJun 12, 2021
  21. ZheNing HuJun 13, 2021
  22. Ævar Arnfjörð BjarmasonJun 17, 2021
  23. ZheNing HuJun 17, 2021
  24. 7/8 [GSOC] cat-file: reuse err buf in batch_objet_write()ZheNing Hu via GitGitGadget, Jun 12, 2021
  25. Ævar Arnfjörð BjarmasonJun 17, 2021
  26. ZheNing HuJun 17, 2021
  27. 0/9 [GSOC][RFC] cat-file: reuse ref-filter logicZheNing Hu via GitGitGadget, Jun 15, 2021
  28. 1/9 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, Jun 15, 2021
  29. 2/9 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jun 15, 2021
  30. 4/9 [GSOC] ref-filter: add %(rest) atomZheNing Hu via GitGitGadget, Jun 15, 2021
  31. 3/9 [GSOC] ref-filter: use non-const ref_format in *_atom_parser()ZheNing Hu via GitGitGadget, Jun 15, 2021
  32. 6/9 [GSOC] ref-filter: introduce free_array_item_internal() functionZheNing Hu via GitGitGadget, Jun 15, 2021
  33. Junio C HamanoJun 16, 2021
  34. ZheNing HuJun 17, 2021
  35. 5/9 [GSOC] ref-filter: teach get_object() return useful valueZheNing Hu via GitGitGadget, Jun 15, 2021
  36. Junio C HamanoJun 16, 2021
  37. ZheNing HuJun 17, 2021
  38. 7/9 [GSOC] cat-file: reuse ref-filter logicZheNing Hu via GitGitGadget, Jun 15, 2021
  39. 8/9 [GSOC] cat-file: reuse err buf in batch_objet_write()ZheNing Hu via GitGitGadget, Jun 15, 2021
  40. 9/9 [GSOC] cat-file: re-implement --textconv, --filters optionsZheNing Hu via GitGitGadget, Jun 15, 2021
  41. Junio C HamanoJun 16, 2021
  42. ZheNing HuJun 17, 2021
  43. Ævar Arnfjörð BjarmasonJun 17, 2021
  44. ZheNing HuJun 17, 2021
  45. 00/10 [GSOC][RFC] cat-file: reuse ref-filter logicZheNing Hu via GitGitGadget, Jun 19, 2021
  46. 01/10 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, Jun 19, 2021
  47. 04/10 [GSOC] ref-filter: use non-const ref_format in *_atom_parser()ZheNing Hu via GitGitGadget, Jun 19, 2021
  48. 02/10 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jun 19, 2021
  49. 07/10 [GSOC] ref-filter: introduce free_ref_array_item_value() functionZheNing Hu via GitGitGadget, Jun 19, 2021
  50. 05/10 [GSOC] ref-filter: add %(rest) atomZheNing Hu via GitGitGadget, Jun 19, 2021
  51. 06/10 [GSOC] ref-filter: pass get_object() return value to their callersZheNing Hu via GitGitGadget, Jun 19, 2021
  52. 09/10 [GSOC] cat-file: reuse err buf in batch_object_write()ZheNing Hu via GitGitGadget, Jun 19, 2021
  53. 08/10 [GSOC] cat-file: reuse ref-filter logicZheNing Hu via GitGitGadget, Jun 19, 2021
  54. Christian CouderJun 21, 2021
  55. ZheNing HuJun 21, 2021
  56. 03/10 [GSOC] ref-filter: --format=%(raw) re-support --perlZheNing Hu via GitGitGadget, Jun 19, 2021
  57. 10/10 [GSOC] cat-file: re-implement --textconv, --filters optionsZheNing Hu via GitGitGadget, Jun 19, 2021
  58. 00/14 [GSOC][RFC] cat-file: reuse ref-filter logicZheNing Hu via GitGitGadget, Jun 22, 2021
  59. 01/14 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, Jun 22, 2021
  60. 03/14 [GSOC] ref-filter: --format=%(raw) re-support --perlZheNing Hu via GitGitGadget, Jun 22, 2021
  61. 02/14 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jun 22, 2021
  62. Bagas SanjayaJun 24, 2021
  63. ZheNing HuJun 24, 2021
  64. 04/14 [GSOC] ref-filter: use non-const ref_format in *_atom_parser()ZheNing Hu via GitGitGadget, Jun 22, 2021
  65. 06/14 [GSOC] ref-filter: pass get_object() return value to their callersZheNing Hu via GitGitGadget, Jun 22, 2021
  66. Bagas SanjayaJun 24, 2021
  67. 05/14 [GSOC] ref-filter: add %(rest) atomZheNing Hu via GitGitGadget, Jun 22, 2021
  68. 08/14 [GSOC] ref-filter: add cat_file_mode in struct ref_formatZheNing Hu via GitGitGadget, Jun 22, 2021
  69. 07/14 [GSOC] ref-filter: introduce free_ref_array_item_value() functionZheNing Hu via GitGitGadget, Jun 22, 2021
  70. 09/14 [GSOC] ref-filter: modify the error message and value in get_objectZheNing Hu via GitGitGadget, Jun 22, 2021
  71. 10/14 [GSOC] cat-file: add has_object_file() checkZheNing Hu via GitGitGadget, Jun 22, 2021
  72. 11/14 [GSOC] cat-file: change batch_objects parameter nameZheNing Hu via GitGitGadget, Jun 22, 2021
  73. Bagas SanjayaJun 24, 2021
  74. 12/14 [GSOC] cat-file: reuse ref-filter logicZheNing Hu via GitGitGadget, Jun 22, 2021
  75. 13/14 [GSOC] cat-file: reuse err buf in batch_object_write()ZheNing Hu via GitGitGadget, Jun 22, 2021
  76. 14/14 [GSOC] cat-file: re-implement --textconv, --filters optionsZheNing Hu via GitGitGadget, Jun 22, 2021
  77. 00/15 [GSOC][RFC] cat-file: reuse ref-filter logicZheNing Hu via GitGitGadget, Jun 25, 2021
  78. 02/15 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jun 25, 2021
  79. Bagas SanjayaJun 26, 2021
  80. ZheNing HuJun 27, 2021
  81. 01/15 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, Jun 25, 2021
  82. 03/15 [GSOC] ref-filter: --format=%(raw) re-support --perlZheNing Hu via GitGitGadget, Jun 25, 2021
  83. 05/15 [GSOC] ref-filter: add %(rest) atomZheNing Hu via GitGitGadget, Jun 25, 2021
  84. 04/15 [GSOC] ref-filter: use non-const ref_format in *_atom_parser()ZheNing Hu via GitGitGadget, Jun 25, 2021
  85. 06/15 [GSOC] ref-filter: pass get_object() return value to their callersZheNing Hu via GitGitGadget, Jun 25, 2021
  86. 08/15 [GSOC] ref-filter: add cat_file_mode in struct ref_formatZheNing Hu via GitGitGadget, Jun 25, 2021
  87. 07/15 [GSOC] ref-filter: introduce free_ref_array_item_value() functionZheNing Hu via GitGitGadget, Jun 25, 2021
  88. 10/15 [GSOC] cat-file: add has_object_file() checkZheNing Hu via GitGitGadget, Jun 25, 2021
  89. 09/15 [GSOC] ref-filter: modify the error message and value in get_objectZheNing Hu via GitGitGadget, Jun 25, 2021
  90. 11/15 [GSOC] cat-file: change batch_objects parameter nameZheNing Hu via GitGitGadget, Jun 25, 2021
  91. 12/15 [GSOC] cat-file: reuse ref-filter logicZheNing Hu via GitGitGadget, Jun 25, 2021
  92. Hariom vermaJun 26, 2021
  93. ZheNing HuJun 27, 2021
  94. Hariom vermaJun 26, 2021
  95. ZheNing HuJun 27, 2021
  96. 13/15 [GSOC] cat-file: reuse err buf in batch_object_write()ZheNing Hu via GitGitGadget, Jun 25, 2021
  97. 14/15 [GSOC] cat-file: re-implement --textconv, --filters optionsZheNing Hu via GitGitGadget, Jun 25, 2021
  98. 15/15 [GSOC] ref-filter: remove grab_oid() functionZheNing Hu via GitGitGadget, Jun 25, 2021
  99. 00/15 [GSOC][RFC] cat-file: reuse ref-filter logicZheNing Hu via GitGitGadget, Jun 27, 2021
  100. 02/15 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jun 27, 2021
  101. Bagas SanjayaJun 28, 2021
  102. 01/15 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, Jun 27, 2021
  103. 03/15 [GSOC] ref-filter: --format=%(raw) re-support --perlZheNing Hu via GitGitGadget, Jun 27, 2021
  104. 07/15 [GSOC] ref-filter: introduce free_ref_array_item_value() functionZheNing Hu via GitGitGadget, Jun 27, 2021
  105. 04/15 [GSOC] ref-filter: use non-const ref_format in *_atom_parser()ZheNing Hu via GitGitGadget, Jun 27, 2021
  106. 08/15 [GSOC] ref-filter: add cat_file_mode in struct ref_formatZheNing Hu via GitGitGadget, Jun 27, 2021
  107. 05/15 [GSOC] ref-filter: add %(rest) atomZheNing Hu via GitGitGadget, Jun 27, 2021
  108. 06/15 [GSOC] ref-filter: pass get_object() return value to their callersZheNing Hu via GitGitGadget, Jun 27, 2021
  109. 09/15 [GSOC] ref-filter: modify the error message and value in get_objectZheNing Hu via GitGitGadget, Jun 27, 2021
  110. 12/15 [GSOC] cat-file: reuse ref-filter logicZheNing Hu via GitGitGadget, Jun 27, 2021
  111. Hariom vermaJun 28, 2021
  112. ZheNing HuJun 28, 2021
  113. 11/15 [GSOC] cat-file: change batch_objects parameter nameZheNing Hu via GitGitGadget, Jun 27, 2021
  114. 13/15 [GSOC] cat-file: reuse err buf in batch_object_write()ZheNing Hu via GitGitGadget, Jun 27, 2021
  115. 10/15 [GSOC] cat-file: add has_object_file() checkZheNing Hu via GitGitGadget, Jun 27, 2021
  116. 15/15 [GSOC] ref-filter: remove grab_oid() functionZheNing Hu via GitGitGadget, Jun 27, 2021
  117. 14/15 [GSOC] cat-file: re-implement --textconv, --filters optionsZheNing Hu via GitGitGadget, Jun 27, 2021
  118. Junio C HamanoJun 30, 2021
  119. ZheNing HuJul 1, 2021
  120. Junio C HamanoJul 1, 2021
  121. ZheNing HuJul 9, 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.