Merge branch 'rs/ref-transaction-1'
authorJunio C Hamano <gitster@pobox.com>
Thu, 11 Sep 2014 17:33:30 +0000 (10:33 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 11 Sep 2014 17:33:31 +0000 (10:33 -0700)
The second batch of the transactional ref update series.

* rs/ref-transaction-1: (22 commits)
update-ref --stdin: pass transaction around explicitly
update-ref --stdin: narrow scope of err strbuf
refs.c: make delete_ref use a transaction
refs.c: make prune_ref use a transaction to delete the ref
refs.c: remove lock_ref_sha1
refs.c: remove the update_ref_write function
refs.c: remove the update_ref_lock function
refs.c: make lock_ref_sha1 static
walker.c: use ref transaction for ref updates
fast-import.c: use a ref transaction when dumping tags
receive-pack.c: use a reference transaction for updating the refs
refs.c: change update_ref to use a transaction
branch.c: use ref transaction for all ref updates
fast-import.c: change update_branch to use ref transactions
sequencer.c: use ref transactions for all ref updates
commit.c: use ref transactions for updates
replace.c: use the ref transaction functions for updates
tag.c: use ref transactions when doing updates
refs.c: add transaction.status and track OPEN/CLOSED
refs.c: make ref_transaction_begin take an err argument
...

1  2 
branch.c
builtin/commit.c
builtin/receive-pack.c
builtin/replace.c
builtin/tag.c
fast-import.c
refs.c
refs.h
sequencer.c
walker.c
diff --cc branch.c
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc builtin/tag.c
Simple merge
diff --cc fast-import.c
Simple merge
diff --cc refs.c
Simple merge
diff --cc refs.h
Simple merge
diff --cc sequencer.c
index 3c060e054720b7b17f9a868cabb1a0ef62aa1b50,5e93b6ab5fdf2f5af4233986137d15351f7a741b..5e8a207474bc6971a0de4f9ff6160a5681ac7b6d
@@@ -243,17 -278,27 +243,27 @@@ static int fast_forward_to(const unsign
  
        read_cache();
        if (checkout_fast_forward(from, to, 1))
 -              exit(1); /* the callee should have complained already */
 +              exit(128); /* the callee should have complained already */
-       ref_lock = lock_any_ref_for_update("HEAD", unborn ? null_sha1 : from,
-                                          0, NULL);
-       if (!ref_lock)
-               return error(_("Failed to lock HEAD during fast_forward_to"));
  
        strbuf_addf(&sb, "%s: fast-forward", action_name(opts));
-       ret = write_ref_sha1(ref_lock, to, sb.buf);
+       transaction = ref_transaction_begin(&err);
+       if (!transaction ||
+           ref_transaction_update(transaction, "HEAD",
+                                  to, unborn ? null_sha1 : from,
+                                  0, 1, &err) ||
+           ref_transaction_commit(transaction, sb.buf, &err)) {
+               ref_transaction_free(transaction);
+               error("%s", err.buf);
+               strbuf_release(&sb);
+               strbuf_release(&err);
+               return -1;
+       }
  
        strbuf_release(&sb);
-       return ret;
+       strbuf_release(&err);
+       ref_transaction_free(transaction);
+       return 0;
  }
  
  static int do_recursive_merge(struct commit *base, struct commit *next,
diff --cc walker.c
index 014826464e07c93374868c61673cfe308961dfb7,b8a5441d6a7cf1d3981ef17473f41a1984e73647..b929dcc6c043cc69b07846c16fb8aeb021aa3ae3
+++ b/walker.c
@@@ -284,31 -280,45 +280,44 @@@ int walker_fetch(struct walker *walker
        }
  
        if (loop(walker))
-               goto unlock_and_fail;
-       if (write_ref_log_details)
-               msg = to_free = xstrfmt("fetch from %s", write_ref_log_details);
-       else
-               msg = "fetch (unknown)";
+               goto done;
+       if (!write_ref) {
+               ret = 0;
+               goto done;
+       }
+       if (write_ref_log_details) {
 -              msg = xmalloc(strlen(write_ref_log_details) + 12);
 -              sprintf(msg, "fetch from %s", write_ref_log_details);
++              msg = xstrfmt("fetch from %s", write_ref_log_details);
+       } else {
+               msg = NULL;
+       }
        for (i = 0; i < targets; i++) {
-               if (!write_ref || !write_ref[i])
+               if (!write_ref[i])
                        continue;
-               ret = write_ref_sha1(lock[i], &sha1[20 * i], msg);
-               lock[i] = NULL;
-               if (ret)
-                       goto unlock_and_fail;
+               strbuf_reset(&refname);
+               strbuf_addf(&refname, "refs/%s", write_ref[i]);
+               if (ref_transaction_update(transaction, refname.buf,
+                                          &sha1[20 * i], NULL, 0, 0,
+                                          &err)) {
+                       error("%s", err.buf);
+                       goto done;
+               }
+       }
+       if (ref_transaction_commit(transaction,
+                                  msg ? msg : "fetch (unknown)",
+                                  &err)) {
+               error("%s", err.buf);
+               goto done;
        }
-       free(to_free);
-       return 0;
  
- unlock_and_fail:
-       for (i = 0; i < targets; i++)
-               if (lock[i])
-                       unlock_ref(lock[i]);
-       free(to_free);
+       ret = 0;
  
-       return -1;
+ done:
+       ref_transaction_free(transaction);
+       free(msg);
+       free(sha1);
+       strbuf_release(&err);
+       strbuf_release(&refname);
+       return ret;
  }
  
  void walker_free(struct walker *walker)