Skip to content

Commit b00f3cf

Browse files
mhaggergitster
authored andcommitted
prune_ref(): call ref_transaction_add_update() directly
`prune_ref()` needs to use the `REF_ISPRUNING` flag, but we want to make that flag private to the files backend. So instead of calling `ref_transaction_delete()`, which is a public function and therefore shouldn't allow the `REF_ISPRUNING` flag, change `prune_ref()` to call `ref_transaction_add_update()`, which is private to the refs module. (Note that we don't need any of the other services provided by `ref_transaction_delete()`.) This allows us to change `ref_transaction_update()` to reject the `REF_ISPRUNING` flag. Do so by adjusting `REF_TRANSACTION_UPDATE_ALLOWED_FLAGS`. Also add parentheses to its definition to avoid potential future mishaps. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b0ca411 commit b00f3cf

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

refs.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,7 @@ int refs_pack_refs(struct ref_store *refs, unsigned int flags);
349349
* Flags that can be passed in to ref_transaction_update
350350
*/
351351
#define REF_TRANSACTION_UPDATE_ALLOWED_FLAGS \
352-
REF_ISPRUNING | \
353-
REF_FORCE_CREATE_REFLOG | \
354-
REF_NODEREF
352+
(REF_NODEREF | REF_FORCE_CREATE_REFLOG)
355353

356354
/*
357355
* Setup reflog before using. Fill in err and return -1 on failure.

refs/files-backend.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -989,22 +989,29 @@ static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r)
989989
{
990990
struct ref_transaction *transaction;
991991
struct strbuf err = STRBUF_INIT;
992+
int ret = -1;
992993

993994
if (check_refname_format(r->name, 0))
994995
return;
995996

996997
transaction = ref_store_transaction_begin(&refs->base, &err);
997-
if (!transaction ||
998-
ref_transaction_delete(transaction, r->name, &r->oid,
999-
REF_ISPRUNING | REF_NODEREF, NULL, &err) ||
1000-
ref_transaction_commit(transaction, &err)) {
1001-
ref_transaction_free(transaction);
998+
if (!transaction)
999+
goto cleanup;
1000+
ref_transaction_add_update(
1001+
transaction, r->name,
1002+
REF_NODEREF | REF_HAVE_NEW | REF_HAVE_OLD | REF_ISPRUNING,
1003+
&null_oid, &r->oid, NULL);
1004+
if (ref_transaction_commit(transaction, &err))
1005+
goto cleanup;
1006+
1007+
ret = 0;
1008+
1009+
cleanup:
1010+
if (ret)
10021011
error("%s", err.buf);
1003-
strbuf_release(&err);
1004-
return;
1005-
}
1006-
ref_transaction_free(transaction);
10071012
strbuf_release(&err);
1013+
ref_transaction_free(transaction);
1014+
return;
10081015
}
10091016

10101017
/*

0 commit comments

Comments
 (0)