summaryrefslogtreecommitdiff
path: root/cache-tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'cache-tree.c')
-rw-r--r--cache-tree.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/cache-tree.c b/cache-tree.c
index ec23d8c03d..71d092ed51 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -131,9 +131,8 @@ static int do_invalidate_path(struct cache_tree *it, const char *path)
* move 4 and 5 up one place (2 entries)
* 2 = 6 - 3 - 1 = subtree_nr - pos - 1
*/
- memmove(it->down+pos, it->down+pos+1,
- sizeof(struct cache_tree_sub *) *
- (it->subtree_nr - pos - 1));
+ MOVE_ARRAY(it->down + pos, it->down + pos + 1,
+ it->subtree_nr - pos - 1);
it->subtree_nr--;
}
return 1;
@@ -604,19 +603,16 @@ static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *pat
int write_index_as_tree(unsigned char *sha1, struct index_state *index_state, const char *index_path, int flags, const char *prefix)
{
int entries, was_valid, newfd;
- struct lock_file *lock_file;
+ struct lock_file lock_file = LOCK_INIT;
+ int ret = 0;
- /*
- * We can't free this memory, it becomes part of a linked list
- * parsed atexit()
- */
- lock_file = xcalloc(1, sizeof(struct lock_file));
-
- newfd = hold_lock_file_for_update(lock_file, index_path, LOCK_DIE_ON_ERROR);
+ newfd = hold_lock_file_for_update(&lock_file, index_path, LOCK_DIE_ON_ERROR);
entries = read_index_from(index_state, index_path);
- if (entries < 0)
- return WRITE_TREE_UNREADABLE_INDEX;
+ if (entries < 0) {
+ ret = WRITE_TREE_UNREADABLE_INDEX;
+ goto out;
+ }
if (flags & WRITE_TREE_IGNORE_CACHE_TREE)
cache_tree_free(&index_state->cache_tree);
@@ -625,10 +621,12 @@ int write_index_as_tree(unsigned char *sha1, struct index_state *index_state, co
was_valid = cache_tree_fully_valid(index_state->cache_tree);
if (!was_valid) {
- if (cache_tree_update(index_state, flags) < 0)
- return WRITE_TREE_UNMERGED_INDEX;
+ if (cache_tree_update(index_state, flags) < 0) {
+ ret = WRITE_TREE_UNMERGED_INDEX;
+ goto out;
+ }
if (0 <= newfd) {
- if (!write_locked_index(index_state, lock_file, COMMIT_LOCK))
+ if (!write_locked_index(index_state, &lock_file, COMMIT_LOCK))
newfd = -1;
}
/* Not being able to write is fine -- we are only interested
@@ -642,17 +640,19 @@ int write_index_as_tree(unsigned char *sha1, struct index_state *index_state, co
if (prefix) {
struct cache_tree *subtree;
subtree = cache_tree_find(index_state->cache_tree, prefix);
- if (!subtree)
- return WRITE_TREE_PREFIX_ERROR;
+ if (!subtree) {
+ ret = WRITE_TREE_PREFIX_ERROR;
+ goto out;
+ }
hashcpy(sha1, subtree->oid.hash);
}
else
hashcpy(sha1, index_state->cache_tree->oid.hash);
+out:
if (0 <= newfd)
- rollback_lock_file(lock_file);
-
- return 0;
+ rollback_lock_file(&lock_file);
+ return ret;
}
int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)