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

[RFC PATCH] cache-tree: Teach write_cache_as_tree to discard_cache

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
May 20, 2011, 08:30 UTC
Message-ID
<1305880223-7542-1-git-send-email-artagnon@gmail.com>
In-Reply-To
<20110520071609.GA6755@domU-12-31-39-06-A8-0A.compute-1.internal>

If the read_cache() call succeeds, the function must call discard_cache() before returning to the caller.

Suggested-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 cache-tree.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/cache-tree.c b/cache-tree.c
index f755590..17c5bab 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -573,8 +573,10 @@ int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
 
 		if (cache_tree_update(active_cache_tree,
 				      active_cache, active_nr,
-				      missing_ok, 0) < 0)
+				      missing_ok, 0) < 0) {
+			discard_cache();
 			return WRITE_TREE_UNMERGED_INDEX;
+		}
 		if (0 <= newfd) {
 			if (!write_cache(newfd, active_cache, active_nr) &&
 			    !commit_lock_file(lock_file))
@@ -591,8 +593,10 @@ int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
 	if (prefix) {
 		struct cache_tree *subtree =
 			cache_tree_find(active_cache_tree, prefix);
-		if (!subtree)
+		if (!subtree) {
+			discard_cache();
 			return WRITE_TREE_PREFIX_ERROR;
+		}
 		hashcpy(sha1, subtree->sha1);
 	}
 	else
@@ -601,6 +605,7 @@ int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
 	if (0 <= newfd)
 		rollback_lock_file(lock_file);
 
+	discard_cache();
 	return 0;
 }
 
-- 
1.7.5.GIT
Previous: Christian CouderNext: Ramkumar Ramachandra
Message 4 of 11 in “Better error-handling around revert”
  1. Ramkumar RamachandraMay 20, 2011
  2. Ramkumar RamachandraMay 20, 2011
  3. Christian CouderMay 21, 2011
  4. cache-tree: Teach write_cache_as_tree to discard_cacheRamkumar Ramachandra, May 20, 2011
  5. revert: Use assert to catch inherent program bugsRamkumar Ramachandra, May 20, 2011
  6. Junio C HamanoMay 20, 2011
  7. Jonathan NiederMay 20, 2011
  8. wrapper: Introduce xclose to restart close on EINTRRamkumar Ramachandra, May 20, 2011
  9. Jonathan NiederMay 20, 2011
  10. Junio C HamanoMay 20, 2011
  11. Jonathan NiederMay 20, 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.