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

Re: [PATCH v2 01/20] pack-revindex: introduce a new API

From
Taylor Blau <me@ttaylorr.com>
Date
Jan 14, 2021, 17:06 UTC
Message-ID
<YAB6DNk4wPBVbGtU@nand.local>
In-Reply-To
<xmqq1reoypzy.fsf@gitster.c.googlers.com>
On Wed, Jan 13, 2021 at 10:46:57PM -0800, Junio C Hamano wrote:
Show 16 quoted lines
> Taylor Blau <me@ttaylorr.com> writes:
>
> > +/*
> > + * offset_to_pack_pos converts an object offset to a pack position. This
> > + * function returns zero on success, and a negative number otherwise. The
> > + * parameter 'pos' is usable only on success.
> > + *
> > + * If the reverse index has not yet been loaded, this function loads it lazily,
> > + * and returns an negative number if an error was encountered.
>
> It is somewhat strange to see a function that yields a non-negative
> "position" on success and a negative value to signal a failure to
> have a separate pointer to the location to receive the true return
> value.  Do we truly care the upper half of "uint32_t" (in other
> words, do we seriously want to support more than 2G positions in a
> pack)?

I don't think that we care about that as much as we do about potential misuse of a signed return value. There are indeed a couple of spots where a potential negative return value is ignored, and then used to lookup an object in a pack, or some such.

And that's part of the goal of this API: we have strict guidelines about when the output parameter is and isn't usable. That makes it more difficult to accidentally use an uninitialized value / negative number.

> What I'm trying to get at is that [...] is more natural than [...] but
> now I wrote it down and laid it out in front of my eyes, the latter
> does not look too bad.
OK, good :-).
Show 9 quoted lines
> 	... later comes back after reading through the series ...
>
> 	The new callers all looked quite nice to eyes.  Because we
> 	discourage assignment inside if() condition, the converted
> 	result does not make the code more verbose than the
> 	original.  In fact, it makes it even clearer that we are
> 	checking for an error return from a function call.
>
> 	Quite nice.
Thank you :-D.
Show 9 quoted lines
> > + * This function runs in time O(log N) with the number of objects in the pack.
>
> Is it a good idea to commit to such performance characteristics as a
> promise to callers like this (the comment applies to all three
> functions)?
>
> It depends on how a developer is helped by this comment when
> deciding whether to use this function, or find other ways, to
> implement what s/he wants to do.

I don't mind it. If they all had the same performance characteristics, I wouldn't be for it, but since they don't, I think that it's good to know. Peff suggested this back in [1].

Thanks, Taylor

[1]: https://lore.kernel.org/git/X%2F1guCOGWybOzIS7@coredump.intra.peff.net/
Previous: Derrick StoleeNext: Jeff King
Message 83 of 121 in “pack-revindex: prepare for on-disk reverse index”
  1. 00/20 pack-revindex: prepare for on-disk reverse indexTaylor Blau, Jan 8, 2021
  2. 01/20 pack-revindex: introduce a new APITaylor Blau, Jan 8, 2021
  3. Jeff KingJan 12, 2021
  4. Jeff KingJan 12, 2021
  5. Taylor BlauJan 12, 2021
  6. Junio C HamanoJan 13, 2021
  7. Junio C HamanoJan 13, 2021
  8. Jeff KingJan 13, 2021
  9. Taylor BlauJan 13, 2021
  10. 02/20 write_reuse_object(): convert to new revindex APITaylor Blau, Jan 8, 2021
  11. Jeff KingJan 12, 2021
  12. Taylor BlauJan 12, 2021
  13. Jeff KingJan 13, 2021
  14. 03/20 write_reused_pack_one(): convert to new revindex APITaylor Blau, Jan 8, 2021
  15. Jeff KingJan 12, 2021
  16. Taylor BlauJan 12, 2021
  17. 04/20 write_reused_pack_verbatim(): convert to new revindex APITaylor Blau, Jan 8, 2021
  18. Jeff KingJan 12, 2021
  19. 06/20 bitmap_position_packfile(): convert to new revindex APITaylor Blau, Jan 8, 2021
  20. 08/20 get_size_by_pos(): convert to new revindex APITaylor Blau, Jan 8, 2021
  21. 07/20 show_objects_for_type(): convert to new revindex APITaylor Blau, Jan 8, 2021
  22. Jeff KingJan 12, 2021
  23. Taylor BlauJan 12, 2021
  24. 05/20 check_object(): convert to new revindex APITaylor Blau, Jan 8, 2021
  25. Derrick StoleeJan 11, 2021
  26. Taylor BlauJan 11, 2021
  27. Jeff KingJan 12, 2021
  28. Jeff KingJan 12, 2021
  29. 11/20 get_delta_base_oid(): convert to new revindex APITaylor Blau, Jan 8, 2021
  30. 12/20 retry_bad_packed_offset(): convert to new revindex APITaylor Blau, Jan 8, 2021
  31. 16/20 builtin/gc.c: guess the size of the revindexTaylor Blau, Jan 8, 2021
  32. Derrick StoleeJan 11, 2021
  33. Taylor BlauJan 11, 2021
  34. Derrick StoleeJan 11, 2021
  35. Jeff KingJan 12, 2021
  36. 15/20 for_each_object_in_pack(): convert to new revindex APITaylor Blau, Jan 8, 2021
  37. 10/20 rebuild_existing_bitmaps(): convert to new revindex APITaylor Blau, Jan 8, 2021
  38. 09/20 try_partial_reuse(): convert to new revindex APITaylor Blau, Jan 8, 2021
  39. Jeff KingJan 12, 2021
  40. Taylor BlauJan 12, 2021
  41. 13/20 packed_object_info(): convert to new revindex APITaylor Blau, Jan 8, 2021
  42. Jeff KingJan 12, 2021
  43. Taylor BlauJan 12, 2021
  44. 14/20 unpack_entry(): convert to new revindex APITaylor Blau, Jan 8, 2021
  45. Jeff KingJan 12, 2021
  46. Taylor BlauJan 12, 2021
  47. 18/20 pack-revindex: remove unused 'find_revindex_position()'Taylor Blau, Jan 8, 2021
  48. Derrick StoleeJan 11, 2021
  49. Taylor BlauJan 11, 2021
  50. Derrick StoleeJan 11, 2021
  51. Jeff KingJan 12, 2021
  52. Taylor BlauJan 12, 2021
  53. Jeff KingJan 13, 2021
  54. 19/20 pack-revindex: hide the definition of 'revindex_entry'Taylor Blau, Jan 8, 2021
  55. Derrick StoleeJan 11, 2021
  56. Jeff KingJan 12, 2021
  57. 17/20 pack-revindex: remove unused 'find_pack_revindex()'Taylor Blau, Jan 8, 2021
  58. 20/20 pack-revindex.c: avoid direct revindex access in 'offset_to_pack_pos()'Taylor Blau, Jan 8, 2021
  59. Jeff KingJan 12, 2021
  60. Taylor BlauJan 12, 2021
  61. Derrick StoleeJan 11, 2021
  62. Taylor BlauJan 11, 2021
  63. Derrick StoleeJan 11, 2021
  64. Taylor BlauJan 11, 2021
  65. Junio C HamanoJan 11, 2021
  66. Jeff KingJan 12, 2021
  67. Taylor BlauJan 12, 2021
  68. Junio C HamanoJan 13, 2021
  69. Taylor BlauJan 13, 2021
  70. Junio C HamanoJan 13, 2021
  71. Taylor BlauJan 13, 2021
  72. Junio C HamanoJan 13, 2021
  73. Jeff KingJan 13, 2021
  74. Taylor BlauJan 13, 2021
  75. Junio C HamanoJan 13, 2021
  76. Taylor BlauJan 13, 2021
  77. Jeff KingJan 13, 2021
  78. 00/20 pack-revindex: prepare for on-disk reverse indexTaylor Blau, Jan 13, 2021
  79. 03/20 write_reused_pack_one(): convert to new revindex APITaylor Blau, Jan 13, 2021
  80. 01/20 pack-revindex: introduce a new APITaylor Blau, Jan 13, 2021
  81. Junio C HamanoJan 14, 2021
  82. Derrick StoleeJan 14, 2021
  83. Taylor BlauJan 14, 2021
  84. Jeff KingJan 14, 2021
  85. Junio C HamanoJan 14, 2021
  86. 20/20 pack-revindex.c: avoid direct revindex access in 'offset_to_pack_pos()'Taylor Blau, Jan 13, 2021
  87. Junio C HamanoJan 14, 2021
  88. Taylor BlauJan 14, 2021
  89. 09/20 try_partial_reuse(): convert to new revindex APITaylor Blau, Jan 13, 2021
  90. 15/20 for_each_object_in_pack(): convert to new revindex APITaylor Blau, Jan 13, 2021
  91. Junio C HamanoJan 14, 2021
  92. Taylor BlauJan 14, 2021
  93. Jeff KingJan 14, 2021
  94. Jeff KingJan 14, 2021
  95. Taylor BlauJan 14, 2021
  96. Junio C HamanoJan 15, 2021
  97. Taylor BlauJan 15, 2021
  98. Junio C HamanoJan 14, 2021
  99. 13/20 packed_object_info(): convert to new revindex APITaylor Blau, Jan 13, 2021
  100. 16/20 builtin/gc.c: guess the size of the revindexTaylor Blau, Jan 13, 2021
  101. Junio C HamanoJan 14, 2021
  102. Taylor BlauJan 14, 2021
  103. Jeff KingJan 14, 2021
  104. 19/20 pack-revindex: hide the definition of 'revindex_entry'Taylor Blau, Jan 13, 2021
  105. 17/20 pack-revindex: remove unused 'find_pack_revindex()'Taylor Blau, Jan 13, 2021
  106. 10/20 rebuild_existing_bitmaps(): convert to new revindex APITaylor Blau, Jan 13, 2021
  107. 07/20 show_objects_for_type(): convert to new revindex APITaylor Blau, Jan 13, 2021
  108. 11/20 get_delta_base_oid(): convert to new revindex APITaylor Blau, Jan 13, 2021
  109. 12/20 retry_bad_packed_offset(): convert to new revindex APITaylor Blau, Jan 13, 2021
  110. 14/20 unpack_entry(): convert to new revindex APITaylor Blau, Jan 13, 2021
  111. 18/20 pack-revindex: remove unused 'find_revindex_position()'Taylor Blau, Jan 13, 2021
  112. Junio C HamanoJan 14, 2021
  113. 08/20 get_size_by_pos(): convert to new revindex APITaylor Blau, Jan 13, 2021
  114. 04/20 write_reused_pack_verbatim(): convert to new revindex APITaylor Blau, Jan 13, 2021
  115. 06/20 bitmap_position_packfile(): convert to new revindex APITaylor Blau, Jan 13, 2021
  116. 02/20 write_reuse_object(): convert to new revindex APITaylor Blau, Jan 13, 2021
  117. 05/20 check_object(): convert to new revindex APITaylor Blau, Jan 13, 2021
  118. Jeff KingJan 14, 2021
  119. Junio C HamanoJan 14, 2021
  120. Jeff KingJan 15, 2021
  121. Jeff KingJan 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.