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

[PATCH 2/5] cache-tree.c::cache_tree_find(): simplify inernal API

From
Junio C Hamano <gitster@pobox.com>
Date
May 23, 2009, 19:24 UTC
Message-ID
<1243106678-6343-3-git-send-email-gitster@pobox.com>
In-Reply-To
<1243106678-6343-2-git-send-email-gitster@pobox.com>

Earlier cache_tree_find() needs to be called with a valid cache_tree, but repeated look-up may find an invalid or missing cache_tree in between. Help simplify the callers by returning NULL to mean "nothing appropriate found" when the input is NULL.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 cache-tree.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/cache-tree.c b/cache-tree.c
index 6dd8411..5481e43 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -514,6 +514,8 @@ struct cache_tree *cache_tree_read(const char *buffer, unsigned long size)
 
 static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *path)
 {
+	if (!it)
+		return NULL;
 	while (*path) {
 		const char *slash;
 		struct cache_tree_sub *sub;
-- 
1.6.3.1.145.gb74d77
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 7 in “Speeding up "git status" and "git diff --cached"”
  1. 0/5 Speeding up "git status" and "git diff --cached"Junio C Hamano, May 23, 2009
  2. 1/5 write-tree --ignore-cache-treeJunio C Hamano, May 23, 2009
  3. 2/5 cache-tree.c::cache_tree_find(): simplify inernal APIJunio C Hamano, May 23, 2009
  4. 3/5 t4007: modernize the styleJunio C Hamano, May 23, 2009
  5. 4/5 Optimize "diff-index --cached" using cache-treeJunio C Hamano, May 23, 2009
  6. 5/5 Avoid "diff-index --cached" optimization under --find-copies-harderJunio C Hamano, May 23, 2009
  7. Jeff KingMay 25, 2009

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.