Merge branch 'mv/merge-refresh'
authorShawn O. Pearce <spearce@spearce.org>
Thu, 9 Oct 2008 17:19:23 +0000 (10:19 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Thu, 9 Oct 2008 17:19:23 +0000 (10:19 -0700)
* mv/merge-refresh:
builtin-merge: refresh the index before calling a strategy

1  2 
builtin-merge.c
diff --combined builtin-merge.c
index fa7c95472c984b0a8325aa61a75137c0a8c1e36e,afa01c659e4a6c6727639ca528265cbb92dfe14c..38266baf5fe9f54a0006baaae205b55f12ed15fc
@@@ -123,7 -123,8 +123,7 @@@ static struct strategy *get_strategy(co
                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;
  }
@@@ -546,6 -547,16 +546,16 @@@ static int try_merge_strategy(const cha
        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;
@@@ -722,12 -733,12 +732,12 @@@ static void add_strategies(const char *
  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);