diff options
Diffstat (limited to 'builtin-merge.c')
-rw-r--r-- | builtin-merge.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/builtin-merge.c b/builtin-merge.c index 5c65a58699..38266baf5f 100644 --- a/builtin-merge.c +++ b/builtin-merge.c @@ -123,8 +123,7 @@ static struct strategy *get_strategy(const char *name) exit(1); } - ret = xmalloc(sizeof(struct strategy)); - memset(ret, 0, sizeof(struct strategy)); + ret = xcalloc(1, sizeof(struct strategy)); ret->name = xstrdup(name); return ret; } @@ -547,6 +546,16 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common, int i = 0, ret; struct commit_list *j; struct strbuf buf; + int index_fd; + struct lock_file *lock = xcalloc(1, sizeof(struct lock_file)); + + index_fd = hold_locked_index(lock, 1); + refresh_cache(REFRESH_QUIET); + if (active_cache_changed && + (write_cache(index_fd, active_cache, active_nr) || + commit_locked_index(lock))) + return error("Unable to write index."); + rollback_lock_file(lock); if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree")) { int clean; @@ -723,12 +732,12 @@ static void add_strategies(const char *string, unsigned attr) static int merge_trivial(void) { unsigned char result_tree[20], result_commit[20]; - struct commit_list *parent = xmalloc(sizeof(struct commit_list *)); + struct commit_list *parent = xmalloc(sizeof(*parent)); write_tree_trivial(result_tree); printf("Wonderful.\n"); parent->item = lookup_commit(head); - parent->next = xmalloc(sizeof(struct commit_list *)); + parent->next = xmalloc(sizeof(*parent->next)); parent->next->item = remoteheads->item; parent->next->next = NULL; commit_tree(merge_msg.buf, result_tree, parent, result_commit, NULL); |