aboutsummaryrefslogtreecommitdiff
path: root/refs/packed-backend.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2017-09-08 15:51:46 +0200
committerJunio C Hamano <gitster@pobox.com>2017-09-09 03:18:04 +0900
commit2fb330ca7238088eea5c1926380feb187f4867bc (patch)
tree93dedf7ea3435e72a5fab58a73456eeaa5ab301a /refs/packed-backend.c
parent2775d8724d73ba2705af72db075b0cdfba3c94f1 (diff)
downloadgit-2fb330ca7238088eea5c1926380feb187f4867bc.tar.gz
git-2fb330ca7238088eea5c1926380feb187f4867bc.tar.xz
packed_delete_refs(): implement method
Implement `packed_delete_refs()` using a reference transaction. This means that `files_delete_refs()` can use `refs_delete_refs()` instead of `repack_without_refs()` to delete any packed references, decreasing the coupling between the classes. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs/packed-backend.c')
-rw-r--r--refs/packed-backend.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 9ab65c5a0..9d5f76b1d 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1086,7 +1086,50 @@ static int packed_initial_transaction_commit(struct ref_store *ref_store,
static int packed_delete_refs(struct ref_store *ref_store, const char *msg,
struct string_list *refnames, unsigned int flags)
{
- die("BUG: not implemented yet");
+ struct packed_ref_store *refs =
+ packed_downcast(ref_store, REF_STORE_WRITE, "delete_refs");
+ struct strbuf err = STRBUF_INIT;
+ struct ref_transaction *transaction;
+ struct string_list_item *item;
+ int ret;
+
+ (void)refs; /* We need the check above, but don't use the variable */
+
+ if (!refnames->nr)
+ return 0;
+
+ /*
+ * Since we don't check the references' old_oids, the
+ * individual updates can't fail, so we can pack all of the
+ * updates into a single transaction.
+ */
+
+ transaction = ref_store_transaction_begin(ref_store, &err);
+ if (!transaction)
+ return -1;
+
+ for_each_string_list_item(item, refnames) {
+ if (ref_transaction_delete(transaction, item->string, NULL,
+ flags, msg, &err)) {
+ warning(_("could not delete reference %s: %s"),
+ item->string, err.buf);
+ strbuf_reset(&err);
+ }
+ }
+
+ ret = ref_transaction_commit(transaction, &err);
+
+ if (ret) {
+ if (refnames->nr == 1)
+ error(_("could not delete reference %s: %s"),
+ refnames->items[0].string, err.buf);
+ else
+ error(_("could not delete references: %s"), err.buf);
+ }
+
+ ref_transaction_free(transaction);
+ strbuf_release(&err);
+ return ret;
}
static int packed_pack_refs(struct ref_store *ref_store, unsigned int flags)