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

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

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Feb 7, 2011, 09:17 UTC
Message-ID
<20110207091740.GA5391@elie>
In-Reply-To
<1296914835-808-1-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy wrote:
> Let's do it in a consistent way, always disregard empty trees in
> index. If users choose to create empty trees their own way, they
> should not use index at all.
While this violates some seeming invariants, like
1.
	git reset --hard
	git commit --allow-empty
	git rev-parse HEAD^^{tree} >expect
	git rev-parse HEAD^{tree} >actual
	test_cmp expect actual
2.
	git reset --hard
	git revert HEAD
	if git rev-parse HEAD~2
	then
		git rev-parse HEAD~2^{tree} >expect
		git rev-parse HEAD^{tree} >actual
		test_cmp expect actual
	fi

, I think it's a good change. Malformed modes in trees already break those false invariants iiuc.

Thanks.
Show 11 quoted lines
> --- 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;
> +			}
Aside from the warning, this part is an optimization, right?
Show 7 quoted lines
>  			sub = cache_tree_sub(it, entry.path);
>  			sub->cache_tree = cache_tree();
>  			prime_cache_tree_rec(sub->cache_tree, subtree);
> +			if (sub->cache_tree->entry_count == -1) {
> +				cnt = -1;
> +				break;
> +			}
Would be nice to include a test for this, like so:
	subdir/
		empty1/
		subsubdir/
			empty2/
			empty3/
Show 10 quoted lines
> --- /dev/null
> +++ b/t/t1013-read-tree-empty.sh
> @@ -0,0 +1,20 @@
> +#!/bin/sh
> +
> +test_description='read-tree with empty trees'
> +
> +. ./test-lib.sh
> +
> +EMPTY_TREE=4b825dc642cb6eb9a060e54bf8d69288fbee4904

If we _have_ to hard-code this (why?) then I'd prefer to do so in test-lib.sh.

[...]
Show 5 quoted lines
> +test_expect_success 'write-tree removes empty tree' '
> +	git read-tree `cat tree` &&
> +	git write-tree >actual
> +	echo $EMPTY_TREE >expected
> +	test_cmp expected actual

Broken &&-chain. Not sure why this test relies on virtual objects and another (independently nice) patch instead of adding the empty tree to the object db --- is there something subtle I am missing?

The test does not distinguish between success due to git read-tree omitting empty trees and success due to git mktree omitting empty trees.

Hope that helps, Jonathan

Previous: Junio C HamanoNext: Nguyen Thai Ngoc Duy
Message 10 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.