Code

Implement git clone -v
[git.git] / builtin-merge.c
index 5c65a5869900ad1a1014fb3aad88c874a5410bf7..38266baf5fe9f54a0006baaae205b55f12ed15fc 100644 (file)
@@ -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);