summaryrefslogtreecommitdiff
path: root/cache-tree.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-02-11 16:46:27 -0800
committerJunio C Hamano <gitster@pobox.com>2008-02-11 16:46:27 -0800
commitc21fdf3b60884222d5d28a09d854cef83c3e60ac (patch)
tree607cc5260d49966c9e2dea0d504ed251b74c2608 /cache-tree.c
parente0197c9aae39b0f1ba6c21d1f6d0bae5de03a44d (diff)
parent45525bd022dda75ec935c9c579e452577dcfd31f (diff)
downloadgit-c21fdf3b60884222d5d28a09d854cef83c3e60ac.tar.gz
Merge branch 'jc/error-message-in-cherry-pick'
* jc/error-message-in-cherry-pick: Make error messages from cherry-pick/revert more sensible
Diffstat (limited to 'cache-tree.c')
-rw-r--r--cache-tree.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/cache-tree.c b/cache-tree.c
index bfc95d2dc9..39da54d1e5 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -529,3 +529,58 @@ struct cache_tree *cache_tree_find(struct cache_tree *it, const char *path)
}
return it;
}
+
+int write_cache_as_tree(unsigned char *sha1, int missing_ok, const char *prefix)
+{
+ int entries, was_valid, newfd;
+
+ /*
+ * We can't free this memory, it becomes part of a linked list
+ * parsed atexit()
+ */
+ struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
+
+ newfd = hold_locked_index(lock_file, 1);
+
+ entries = read_cache();
+ if (entries < 0)
+ return WRITE_TREE_UNREADABLE_INDEX;
+
+ if (!active_cache_tree)
+ active_cache_tree = cache_tree();
+
+ was_valid = cache_tree_fully_valid(active_cache_tree);
+
+ if (!was_valid) {
+ if (cache_tree_update(active_cache_tree,
+ active_cache, active_nr,
+ missing_ok, 0) < 0)
+ return WRITE_TREE_UNMERGED_INDEX;
+ if (0 <= newfd) {
+ if (!write_cache(newfd, active_cache, active_nr) &&
+ !commit_lock_file(lock_file))
+ newfd = -1;
+ }
+ /* Not being able to write is fine -- we are only interested
+ * in updating the cache-tree part, and if the next caller
+ * ends up using the old index with unupdated cache-tree part
+ * it misses the work we did here, but that is just a
+ * performance penalty and not a big deal.
+ */
+ }
+
+ if (prefix) {
+ struct cache_tree *subtree =
+ cache_tree_find(active_cache_tree, prefix);
+ if (!subtree)
+ return WRITE_TREE_PREFIX_ERROR;
+ hashcpy(sha1, subtree->sha1);
+ }
+ else
+ hashcpy(sha1, active_cache_tree->sha1);
+
+ if (0 <= newfd)
+ rollback_lock_file(lock_file);
+
+ return 0;
+}