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>

Michael Haggerty committed Nov 5, 2017 at 09:42 UTC b00f3cfa92d10d7180e6baf01d570eb904b5a592
2 files changed +17 -12
refs.h
+1 -3
@@ -349,9 +349,7 @@ int refs_pack_refs(struct ref_store *refs, unsigned int flags);
349 * Flags that can be passed in to ref_transaction_update
350 */
351 #define REF_TRANSACTION_UPDATE_ALLOWED_FLAGS \
352 - REF_ISPRUNING | \
353 - REF_FORCE_CREATE_REFLOG | \
354 - REF_NODEREF
352 + (REF_NODEREF | REF_FORCE_CREATE_REFLOG)
353
354 /*
355 * Setup reflog before using. Fill in err and return -1 on failure.
refs/files-backend.c
+16 -9
@@ -989,22 +989,29 @@ static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r)
989 {
990 struct ref_transaction *transaction;
991 struct strbuf err = STRBUF_INIT;
992 + int ret = -1;
993
994 if (check_refname_format(r->name, 0))
995 return;
996
997 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)
1011 error("%s", err.buf);
1003 - strbuf_release(&err);
1004 - return;
1005 - }
1006 - ref_transaction_free(transaction);
1012 strbuf_release(&err);
1013 + ref_transaction_free(transaction);
1014 + return;
1015 }
1016
1017 /*