From: Ronnie Sahlberg <sahlberg@google.com>
To: git@vger.kernel.org
Cc: Ronnie Sahlberg <sahlberg@google.com>
Subject: [PATCH v2 11/17] remote.c: use a transaction for deleting refs
Date: Mon, 3 Nov 2014 11:02:13 -0800 [thread overview]
Message-ID: <1415041339-18450-12-git-send-email-sahlberg@google.com> (raw)
In-Reply-To: <1415041339-18450-1-git-send-email-sahlberg@google.com>
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>
---
builtin/remote.c | 80 ++++++++++++++++++++++++++++----------------------------
1 file changed, 40 insertions(+), 40 deletions(-)
diff --git a/builtin/remote.c b/builtin/remote.c
index 6806251..42702d7 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);
--
2.1.0.rc2.206.gedb03e5
next prev parent reply other threads:[~2014-11-03 19:02 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-03 19:02 [PATCH v2 00/17] ref-transaction-rename Ronnie Sahlberg
2014-11-03 19:02 ` [PATCH v2 01/17] refs.c: allow passing raw git_committer_info as email to _update_reflog Ronnie Sahlberg
2014-11-03 19:02 ` [PATCH v2 02/17] refs.c: return error instead of dying when locking fails during transaction Ronnie Sahlberg
2014-11-03 19:02 ` [PATCH v2 03/17] refs.c: use packed refs when deleting refs during a transaction Ronnie Sahlberg
2014-11-03 19:02 ` [PATCH v2 04/17] refs.c: use a stringlist for repack_without_refs Ronnie Sahlberg
2014-11-03 19:02 ` [PATCH v2 05/17] refs.c: add transaction support for replacing a reflog Ronnie Sahlberg
2014-11-03 21:06 ` Junio C Hamano
2014-11-03 19:02 ` [PATCH v2 06/17] refs.c: add new function copy_reflog_into_strbuf Ronnie Sahlberg
2014-11-03 19:02 ` [PATCH v2 07/17] refs.c: update rename_ref to use a transaction Ronnie Sahlberg
2014-11-03 19:02 ` [PATCH v2 08/17] refs.c: rollback the lockfile before we die() in repack_without_refs Ronnie Sahlberg
2014-11-03 19:02 ` [PATCH v2 09/17] refs.c: move reflog updates into its own function Ronnie Sahlberg
2014-11-03 19:02 ` [PATCH v2 10/17] refs.c: write updates to packed refs when a transaction has more than one ref Ronnie Sahlberg
2014-11-03 19:02 ` Ronnie Sahlberg [this message]
2014-11-03 19:02 ` [PATCH v2 12/17] refs.c: make repack_without_refs static Ronnie Sahlberg
2014-11-03 19:02 ` [PATCH v2 13/17] refs.c: make the *_packed_refs functions static Ronnie Sahlberg
2014-11-03 19:02 ` [PATCH v2 14/17] refs.c: replace the onerr argument in update_ref with a strbuf err Ronnie Sahlberg
2014-11-03 19:02 ` [PATCH v2 15/17] refs.c: make add_packed_ref return an error instead of calling die Ronnie Sahlberg
2014-11-03 19:02 ` [PATCH v2 16/17] refs.c: make lock_packed_refs take an err argument Ronnie Sahlberg
2014-11-03 19:02 ` [PATCH v2 17/17] refs.c: add an err argument to pack_refs Ronnie Sahlberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1415041339-18450-12-git-send-email-sahlberg@google.com \
--to=sahlberg@google.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).