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

Re: [PATCH v4 4/4] sha1_name: minimize OID comparisons during disambiguation

From
Derrick Stolee <stolee@gmail.com>
Date
Oct 10, 2017, 13:11 UTC
Message-ID
<f9add2c3-5499-085e-e433-799427dda6d8@gmail.com>
In-Reply-To
<xmqqbmlfp3eh.fsf@gitster.mtv.corp.google.com>
On 10/10/2017 8:56 AM, Junio C Hamano wrote:
Show 18 quoted lines
> Jeff King <peff@peff.net> writes:
>
>> OK, I think that makes more sense. But note the p->num_objects thing I
>> mentioned. If I do:
>>
>>    git pack-objects .git/objects/pack/pack </dev/null
>>
>> then I have a pack with zero objects, which I think we'd similarly want
>> to return early from. I.e., I think we need:
>>
>>    if (p->num_objects)
>> 	return;
>>
>> Technically that also covers open_pack_index() failure, too, but that's
>> a subtlety I don't think we should rely on.
> True.  I notice that the early part of the two functions look almost
> identical.  Do we need error condition handling for the other one,
> too?

I prefer to fix the problem in all code clones when they cause review friction, so I'll send a fifth commit showing just the diff for these packfile issues in sha1_name.c. See patch below.

Should open_pack_index() return a non-zero status if the packfile is empty? Or, is there a meaningful reason to have empty packfiles?

Thanks, -Stolee

diff --git a/sha1_name.c b/sha1_name.c
index 49ba67955..9f8a33e82 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -153,7 +153,9 @@ static void unique_in_pack(struct packed_git *p,
         uint32_t num, last, i, first = 0;
         const struct object_id *current = NULL;

-       open_pack_index(p);
+       if (open_pack_index(p) || !p->num_objects)
+               return;
+
         num = p->num_objects;
         last = num;
         while (first < last) {
@@ -513,7 +515,9 @@ static void find_abbrev_len_for_pack(struct 
packed_git *p,
         uint32_t num, last, first = 0;
         struct object_id oid;

-       open_pack_index(p);
+       if (open_pack_index(p) || !p->num_objects)
+               return;
+
         num = p->num_objects;
         last = num;
         while (first < last) {
Previous: Jeff KingNext: Jeff King
Message 11 of 22 in “Improve abbreviation disambiguation”
  1. 0/4 Improve abbreviation disambiguationDerrick Stolee, Oct 8, 2017
  2. 1/4 p4211-line-log.sh: add log --online --raw --parents perf testDerrick Stolee, Oct 8, 2017
  3. 3/4 sha1_name: parse less while finding common prefixDerrick Stolee, Oct 8, 2017
  4. Jeff KingOct 9, 2017
  5. 4/4 sha1_name: minimize OID comparisons during disambiguationDerrick Stolee, Oct 8, 2017
  6. Jeff KingOct 9, 2017
  7. Derrick StoleeOct 10, 2017
  8. Jeff KingOct 10, 2017
  9. Junio C HamanoOct 10, 2017
  10. Jeff KingOct 10, 2017
  11. Derrick StoleeOct 10, 2017
  12. Jeff KingOct 10, 2017
  13. Derrick StoleeOct 11, 2017
  14. 0/4 Improve abbreviation disambiguationDerrick Stolee, Oct 12, 2017
  15. Derrick StoleeOct 12, 2017
  16. Junio C HamanoOct 12, 2017
  17. Jeff KingOct 12, 2017
  18. 3/4 sha1_name: parse less while finding common prefixDerrick Stolee, Oct 12, 2017
  19. 2/4 sha1_name: unroll len loop in find_unique_abbrev_rDerrick Stolee, Oct 12, 2017
  20. 1/4 p4211-line-log.sh: add log --online --raw --parents perf testDerrick Stolee, Oct 12, 2017
  21. 4/4 sha1_name: minimize OID comparisons during disambiguationDerrick Stolee, Oct 12, 2017
  22. 2/4 sha1_name: unroll len loop in find_unique_abbrev_rDerrick Stolee, Oct 8, 2017

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.