From: Ramkumar Ramachandra Date: Fri, 20 May 2011 08:30:21 GMT Subject: [RFC PATCH] cache-tree: Teach write_cache_as_tree to discard_cache 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 Signed-off-by: Ramkumar Ramachandra --- 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