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

Re: [PATCH] cache-tree: do not cache empty trees

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Feb 7, 2011, 02:36 UTC
Message-ID
<AANLkTinCyOq4rmb-tf4B91bK97GWca-4DyC715tUv+zx@mail.gmail.com>
In-Reply-To
<7v62swwq7s.fsf@alter.siamese.dyndns.org>
2011/2/7 Junio C Hamano <gitster@pobox.com>:
Show 16 quoted lines
>> diff --git a/cache-tree.c b/cache-tree.c
>> index f755590..03732ad 100644
>> --- a/cache-tree.c
>> +++ b/cache-tree.c
>> @@ -621,9 +621,18 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
>>                       struct tree *subtree = lookup_tree(entry.sha1);
>>                       if (!subtree->object.parsed)
>>                               parse_tree(subtree);
>> +                     if (!hashcmp(entry.sha1, (unsigned char *)EMPTY_TREE_SHA1_BIN)) {
>> +                             warning("empty tree detected! Will be removed in new commits");
>> +                             cnt = -1;
>> +                             break;
>> +                     }
>
> You shouldn't need the cast (if you did, then hashcmp() macro should be
> fixed so that you don't need to).

Or perhaps EMPTY_TREE_SHA1_BIN should be casted to const unsigned char *. That would eliminate 4 typecastings elsewhere.

> I don't think warning() is warranted for an operation you introduced to
> keep the internal data structure consistent.

Worse. I don't think users know an empty tree is added or removed. diff-tree does not show it (or should not, I haven't tested).

Show 7 quoted lines
> Should this comparison done after we parsed the subtree, or should we be
> doing that before it?
>
> If you are adding this new check to a point where we have already parsed
> the subtree object, don't you have a better and cheaper way to detect if
> the subtree is empty than the 20-byte comparision, namely, perhaps by
> looking at subtree->size?
OK before is better.
-- 
Duy
Previous: Junio C HamanoNext: Jonathan Nieder
Message 7 of 20 in “cache-tree: do not cache empty trees”
  1. cache-tree: do not cache empty treesNguyễn Thái Ngọc Duy, Feb 5, 2011
  2. cache-tree: do not cache empty treesNguyễn Thái Ngọc Duy, Feb 5, 2011
  3. Jonathan NiederFeb 5, 2011
  4. Nguyen Thai Ngoc DuyFeb 5, 2011
  5. cache-tree: do not cache empty treesNguyễn Thái Ngọc Duy, Feb 5, 2011
  6. Junio C HamanoFeb 7, 2011
  7. Nguyen Thai Ngoc DuyFeb 7, 2011
  8. correct type of EMPTY_TREE_SHA1_BINJonathan Nieder, Feb 7, 2011
  9. Junio C HamanoFeb 9, 2011
  10. Jonathan NiederFeb 7, 2011
  11. Nguyen Thai Ngoc DuyFeb 7, 2011
  12. Ilari LiusvaaraFeb 7, 2011
  13. Nguyen Thai Ngoc DuyFeb 7, 2011
  14. Jonathan NiederFeb 7, 2011
  15. Junio C HamanoFeb 7, 2011
  16. Nguyen Thai Ngoc DuyFeb 8, 2011
  17. Jonathan NiederFeb 8, 2011
  18. Yann DirsonFeb 15, 2011
  19. Jakub NarebskiFeb 16, 2011
  20. Ilari LiusvaaraFeb 8, 2011

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.