Merge branch 'bc/object-id'
[gitweb.git] / builtin / am.c
index d7513f53759bc5834aa02bd904432f64e036ccb6..4b6f1534f88407cf569c7f8e4c4b1df4ba3fc1e0 100644 (file)
@@ -1068,8 +1068,8 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
        if (!get_oid("HEAD", &curr_head)) {
                write_state_text(state, "abort-safety", oid_to_hex(&curr_head));
                if (!state->rebasing)
-                       update_ref_oid("am", "ORIG_HEAD", &curr_head, NULL, 0,
-                                       UPDATE_REFS_DIE_ON_ERR);
+                       update_ref("am", "ORIG_HEAD", &curr_head, NULL, 0,
+                                  UPDATE_REFS_DIE_ON_ERR);
        } else {
                write_state_text(state, "abort-safety", "");
                if (!state->rebasing)
@@ -1134,11 +1134,11 @@ static const char *msgnum(const struct am_state *state)
  */
 static void refresh_and_write_cache(void)
 {
-       struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
+       struct lock_file lock_file = LOCK_INIT;
 
-       hold_locked_index(lock_file, LOCK_DIE_ON_ERROR);
+       hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
        refresh_cache(REFRESH_QUIET);
-       if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
+       if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
                die(_("unable to write index file"));
 }
 
@@ -1488,11 +1488,10 @@ static int run_apply(const struct am_state *state, const char *index_file)
        struct argv_array apply_opts = ARGV_ARRAY_INIT;
        struct apply_state apply_state;
        int res, opts_left;
-       static struct lock_file lock_file;
        int force_apply = 0;
        int options = 0;
 
-       if (init_apply_state(&apply_state, NULL, &lock_file))
+       if (init_apply_state(&apply_state, NULL))
                die("BUG: init_apply_state() failed");
 
        argv_array_push(&apply_opts, "apply");
@@ -1686,8 +1685,8 @@ static void do_commit(const struct am_state *state)
        strbuf_addf(&sb, "%s: %.*s", reflog_msg, linelen(state->msg),
                        state->msg);
 
-       update_ref_oid(sb.buf, "HEAD", &commit, old_oid, 0,
-                       UPDATE_REFS_DIE_ON_ERR);
+       update_ref(sb.buf, "HEAD", &commit, old_oid, 0,
+                  UPDATE_REFS_DIE_ON_ERR);
 
        if (state->rebasing) {
                FILE *fp = xfopen(am_path(state, "rewritten"), "a");
@@ -1946,15 +1945,14 @@ static void am_resolve(struct am_state *state)
  */
 static int fast_forward_to(struct tree *head, struct tree *remote, int reset)
 {
-       struct lock_file *lock_file;
+       struct lock_file lock_file = LOCK_INIT;
        struct unpack_trees_options opts;
        struct tree_desc t[2];
 
        if (parse_tree(head) || parse_tree(remote))
                return -1;
 
-       lock_file = xcalloc(1, sizeof(struct lock_file));
-       hold_locked_index(lock_file, LOCK_DIE_ON_ERROR);
+       hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
 
        refresh_cache(REFRESH_QUIET);
 
@@ -1970,11 +1968,11 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset)
        init_tree_desc(&t[1], remote->buffer, remote->size);
 
        if (unpack_trees(2, t, &opts)) {
-               rollback_lock_file(lock_file);
+               rollback_lock_file(&lock_file);
                return -1;
        }
 
-       if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
+       if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
                die(_("unable to write new index file"));
 
        return 0;
@@ -1986,15 +1984,14 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset)
  */
 static int merge_tree(struct tree *tree)
 {
-       struct lock_file *lock_file;
+       struct lock_file lock_file = LOCK_INIT;
        struct unpack_trees_options opts;
        struct tree_desc t[1];
 
        if (parse_tree(tree))
                return -1;
 
-       lock_file = xcalloc(1, sizeof(struct lock_file));
-       hold_locked_index(lock_file, LOCK_DIE_ON_ERROR);
+       hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
 
        memset(&opts, 0, sizeof(opts));
        opts.head_idx = 1;
@@ -2005,11 +2002,11 @@ static int merge_tree(struct tree *tree)
        init_tree_desc(&t[0], tree->buffer, tree->size);
 
        if (unpack_trees(1, t, &opts)) {
-               rollback_lock_file(lock_file);
+               rollback_lock_file(&lock_file);
                return -1;
        }
 
-       if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
+       if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
                die(_("unable to write new index file"));
 
        return 0;
@@ -2135,7 +2132,7 @@ static void am_abort(struct am_state *state)
 
        am_rerere_clear();
 
-       curr_branch = resolve_refdup("HEAD", 0, curr_head.hash, NULL);
+       curr_branch = resolve_refdup("HEAD", 0, &curr_head, NULL);
        has_curr_head = curr_branch && !is_null_oid(&curr_head);
        if (!has_curr_head)
                hashcpy(curr_head.hash, EMPTY_TREE_SHA1_BIN);
@@ -2147,9 +2144,9 @@ static void am_abort(struct am_state *state)
        clean_index(&curr_head, &orig_head);
 
        if (has_orig_head)
-               update_ref_oid("am --abort", "HEAD", &orig_head,
-                               has_curr_head ? &curr_head : NULL, 0,
-                               UPDATE_REFS_DIE_ON_ERR);
+               update_ref("am --abort", "HEAD", &orig_head,
+                          has_curr_head ? &curr_head : NULL, 0,
+                          UPDATE_REFS_DIE_ON_ERR);
        else if (curr_branch)
                delete_ref(NULL, curr_branch, NULL, REF_NODEREF);