summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonnie Sahlberg <sahlberg@google.com>2014-11-07 11:38:59 -0800
committerJunio C Hamano <gitster@pobox.com>2014-11-07 15:46:23 -0800
commit474b775ca728c41dc89f88727c1d7d3b485a0e2e (patch)
tree37b6ef987bfbed22c5f2ea823acc38d00cda5583
parent17ab3258225328ec1e56527485f8aeb0f83031ef (diff)
downloadgit-474b775ca728c41dc89f88727c1d7d3b485a0e2e.tar.gz
remote.c: use a transaction for deleting refs
Transactions now use packed refs when deleting multiple refs so there is no need to do it manually from remote.c any more. Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/remote.c80
1 files changed, 40 insertions, 40 deletions
diff --git a/builtin/remote.c b/builtin/remote.c
index 6806251f3f..42702d78ba 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -750,30 +750,27 @@ static int mv(int argc, const char **argv)
static int remove_branches(struct string_list *branches)
{
- struct strbuf err = STRBUF_INIT;
int i, result = 0;
+ struct transaction *transaction;
+ struct strbuf err = STRBUF_INIT;
- if (lock_packed_refs(0)) {
- struct strbuf err = STRBUF_INIT;
-
- unable_to_lock_message(git_path("packed-refs"), errno, &err);
- error("%s", err.buf);
- strbuf_release(&err);
- return -1;
- }
+ transaction = transaction_begin(&err);
+ if (!transaction)
+ die("%s", err.buf);
- if (repack_without_refs(branches, &err))
+ for (i = 0; i < branches->nr; i++)
+ if (transaction_delete_ref(transaction,
+ branches->items[i].string, NULL,
+ 0, 0, "remote-branches", &err)) {
+ result |= error("%s", err.buf);
+ goto cleanup;
+ }
+ if (transaction_commit(transaction, &err))
result |= error("%s", err.buf);
- strbuf_release(&err);
-
- for (i = 0; i < branches->nr; i++) {
- struct string_list_item *item = branches->items + i;
- const char *refname = item->string;
-
- if (delete_ref(refname, NULL, 0))
- result |= error(_("Could not remove branch %s"), refname);
- }
+ cleanup:
+ strbuf_release(&err);
+ transaction_free(transaction);
return result;
}
@@ -1325,42 +1322,38 @@ static int prune_remote(const char *remote, int dry_run)
const char *dangling_msg = dry_run
? _(" %s will become dangling!")
: _(" %s has become dangling!");
+ struct transaction *transaction = NULL;
+ struct strbuf err = STRBUF_INIT;
memset(&states, 0, sizeof(states));
get_remote_ref_states(remote, &states, GET_REF_STATES);
- for (i = 0; i < states.stale.nr; i++) {
- string_list_insert(&delete_refs_list,
- states.stale.items[i].util);
- }
-
if (states.stale.nr) {
printf_ln(_("Pruning %s"), remote);
printf_ln(_("URL: %s"),
states.remote->url_nr
? states.remote->url[0]
: _("(no URL)"));
-
- if (!dry_run) {
- struct strbuf err = STRBUF_INIT;
-
- if (lock_packed_refs(0)) {
- unable_to_lock_message(git_path("packed-refs"),
- errno, &err);
- result |= error("%s", err.buf);
- } else
- if (repack_without_refs(&delete_refs_list,
- &err))
- result |= error("%s", err.buf);
- strbuf_release(&err);
- }
}
+ if (!dry_run) {
+ transaction = transaction_begin(&err);
+ if (!transaction)
+ die("%s", err.buf);
+ }
for (i = 0; i < states.stale.nr; i++) {
const char *refname = states.stale.items[i].util;
- if (!dry_run)
- result |= delete_ref(refname, NULL, 0);
+ string_list_insert(&delete_refs_list, refname);
+
+ if (!dry_run) {
+ if (transaction_delete_ref(transaction,
+ refname, NULL,
+ 0, 0, "remote-branches", &err)) {
+ result |= error("%s", err.buf);
+ goto cleanup;
+ }
+ }
if (dry_run)
printf_ln(_(" * [would prune] %s"),
@@ -1370,6 +1363,13 @@ static int prune_remote(const char *remote, int dry_run)
abbrev_ref(refname, "refs/remotes/"));
}
+ if (!dry_run)
+ if (transaction_commit(transaction, &err))
+ result |= error("%s", err.buf);
+
+ cleanup:
+ strbuf_release(&err);
+ transaction_free(transaction);
warn_dangling_symrefs(stdout, dangling_msg, &delete_refs_list);
string_list_clear(&delete_refs_list, 0);