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>
Michael Haggerty committed
Sep 8, 2017 at 15:51 UTC
2fb330ca7238088eea5c1926380feb187f4867bc
2 files changed
+45
-2
refs/files-backend.c
+1
-1
@@ -1157,7 +1157,7 @@ static int files_delete_refs(struct ref_store *ref_store, const char *msg,
1157
if (packed_refs_lock(refs->packed_ref_store, 0, &err))
1158
goto error;
1159
1160
- if (repack_without_refs(refs->packed_ref_store, refnames, &err)) {
1160
+ if (refs_delete_refs(refs->packed_ref_store, msg, refnames, flags)) {
1161
packed_refs_unlock(refs->packed_ref_store);
1162
goto error;
1163
}
refs/packed-backend.c
+44
-1
@@ -1086,7 +1086,50 @@ static int packed_initial_transaction_commit(struct ref_store *ref_store,
1086
static int packed_delete_refs(struct ref_store *ref_store, const char *msg,
1087
struct string_list *refnames, unsigned int flags)
1088
{
1089
- die("BUG: not implemented yet");
1089
+ struct packed_ref_store *refs =
1090
+ packed_downcast(ref_store, REF_STORE_WRITE, "delete_refs");
1091
+ struct strbuf err = STRBUF_INIT;
1092
+ struct ref_transaction *transaction;
1093
+ struct string_list_item *item;
1094
+ int ret;
1095
+
1096
+ (void)refs; /* We need the check above, but don't use the variable */
1097
+
1098
+ if (!refnames->nr)
1099
+ return 0;
1100
+
1101
+ /*
1102
+ * Since we don't check the references' old_oids, the
1103
+ * individual updates can't fail, so we can pack all of the
1104
+ * updates into a single transaction.
1105
+ */
1106
+
1107
+ transaction = ref_store_transaction_begin(ref_store, &err);
1108
+ if (!transaction)
1109
+ return -1;
1110
+
1111
+ for_each_string_list_item(item, refnames) {
1112
+ if (ref_transaction_delete(transaction, item->string, NULL,
1113
+ flags, msg, &err)) {
1114
+ warning(_("could not delete reference %s: %s"),
1115
+ item->string, err.buf);
1116
+ strbuf_reset(&err);
1117
+ }
1118
+ }
1119
+
1120
+ ret = ref_transaction_commit(transaction, &err);
1121
+
1122
+ if (ret) {
1123
+ if (refnames->nr == 1)
1124
+ error(_("could not delete reference %s: %s"),
1125
+ refnames->items[0].string, err.buf);
1126
+ else
1127
+ error(_("could not delete references: %s"), err.buf);
1128
+ }
1129
+
1130
+ ref_transaction_free(transaction);
1131
+ strbuf_release(&err);
1132
+ return ret;
1133
}
1134
1135
static int packed_pack_refs(struct ref_store *ref_store, unsigned int flags)