Skip to content

Commit 2fb330c

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2775d87 commit 2fb330c

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

refs/files-backend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ static int files_delete_refs(struct ref_store *ref_store, const char *msg,
11571157
if (packed_refs_lock(refs->packed_ref_store, 0, &err))
11581158
goto error;
11591159

1160-
if (repack_without_refs(refs->packed_ref_store, refnames, &err)) {
1160+
if (refs_delete_refs(refs->packed_ref_store, msg, refnames, flags)) {
11611161
packed_refs_unlock(refs->packed_ref_store);
11621162
goto error;
11631163
}

refs/packed-backend.c

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,50 @@ static int packed_initial_transaction_commit(struct ref_store *ref_store,
10861086
static int packed_delete_refs(struct ref_store *ref_store, const char *msg,
10871087
struct string_list *refnames, unsigned int flags)
10881088
{
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;
10901133
}
10911134

10921135
static int packed_pack_refs(struct ref_store *ref_store, unsigned int flags)

0 commit comments

Comments
 (0)