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, 09:57 UTC
Message-ID
<20110207095713.GA19653@do>
In-Reply-To
<20110207091740.GA5391@elie>
On Mon, Feb 07, 2011 at 03:17:40AM -0600, Jonathan Nieder wrote:
Show 21 quoted lines
> 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.

Perhaps it's not a good approach after all. What I wanted was to make pre-1.8.0 tolerate empty trees created by 1.8.0. Perhaps it's better to just let pre-1.8.0 refuse to work with empty trees, forcing users to upgrade to 1.8.0?

The (untested) patch below would make git refuse to create an index from a tree that contains empty trees. Hmm?

diff --git a/cache-tree.c b/cache-tree.c
index f755590..e33998a 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -619,6 +619,8 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
 		else {
 			struct cache_tree_sub *sub;
 			struct tree *subtree = lookup_tree(entry.sha1);
+			if (!hashcmp(entry.sha1, EMPTY_TREE_SHA1_BIN))
+				die("empty tree .../%s detected!", entry.path);
 			if (!subtree->object.parsed)
 				parse_tree(subtree);
 			sub = cache_tree_sub(it, entry.path);
diff --git a/unpack-trees.c b/unpack-trees.c
index 1ca41b1..0e6738e 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -434,6 +434,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long
 	void *buf[MAX_UNPACK_TREES];
 	struct traverse_info newinfo;
 	struct name_entry *p;
+	struct unpack_trees_options *o = info->data;
 
 	p = names;
 	while (!p->mode)
@@ -447,8 +448,11 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long
 
 	for (i = 0; i < n; i++, dirmask >>= 1) {
 		const unsigned char *sha1 = NULL;
-		if (dirmask & 1)
+		if (dirmask & 1) {
 			sha1 = names[i].sha1;
+			if (o->merge && !hashcmp(sha1, EMPTY_TREE_SHA1_BIN))
+				return error("empty tree .../%s detected!", p->path);
+		}
 		buf[i] = fill_tree_descriptor(t+i, sha1);
 	}
 
-- 
Duy
Previous: Jonathan NiederNext: Ilari Liusvaara
Message 11 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.