ref_transaction_delete(): remove "have_old" parameter

Instead, verify the reference's old value if and only if old_sha1 is non-NULL. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Feb 17, 2015 at 18:00 UTC fb5a6bb61c215546b94156bbb54d43225424f7d0
4 files changed +13 -12
builtin/receive-pack.c
+1 -2
@@ -953,8 +953,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
953 if (ref_transaction_delete(transaction,
954 namespaced_name,
955 old_sha1,
956 - 0, old_sha1 != NULL,
957 - "push", &err)) {
956 + 0, "push", &err)) {
957 rp_error("%s", err.buf);
958 strbuf_release(&err);
959 return "failed to delete";
builtin/update-ref.c
+3 -2
@@ -265,8 +265,9 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
265 if (*next != line_termination)
266 die("delete %s: extra input: %s", refname, next);
267
268 - if (ref_transaction_delete(transaction, refname, old_sha1,
269 - update_flags, have_old, msg, &err))
268 + if (ref_transaction_delete(transaction, refname,
269 + have_old ? old_sha1 : NULL,
270 + update_flags, msg, &err))
271 die("%s", err.buf);
272
273 update_flags = 0;
refs.c
+6 -5
@@ -2576,7 +2576,7 @@ static void prune_ref(struct ref_to_prune *r)
2576 transaction = ref_transaction_begin(&err);
2577 if (!transaction ||
2578 ref_transaction_delete(transaction, r->name, r->sha1,
2579 - REF_ISPRUNING, 1, NULL, &err) ||
2579 + REF_ISPRUNING, NULL, &err) ||
2580 ref_transaction_commit(transaction, &err)) {
2581 ref_transaction_free(transaction);
2582 error("%s", err.buf);
@@ -2753,8 +2753,9 @@ int delete_ref(const char *refname, const unsigned char *sha1, unsigned int flag
2753
2754 transaction = ref_transaction_begin(&err);
2755 if (!transaction ||
2756 - ref_transaction_delete(transaction, refname, sha1, flags,
2757 - sha1 && !is_null_sha1(sha1), NULL, &err) ||
2756 + ref_transaction_delete(transaction, refname,
2757 + (sha1 && !is_null_sha1(sha1)) ? sha1 : NULL,
2758 + flags, NULL, &err) ||
2759 ref_transaction_commit(transaction, &err)) {
2760 error("%s", err.buf);
2761 ref_transaction_free(transaction);
@@ -3696,11 +3697,11 @@ int ref_transaction_create(struct ref_transaction *transaction,
3697 int ref_transaction_delete(struct ref_transaction *transaction,
3698 const char *refname,
3699 const unsigned char *old_sha1,
3699 - unsigned int flags, int have_old, const char *msg,
3700 + unsigned int flags, const char *msg,
3701 struct strbuf *err)
3702 {
3703 return ref_transaction_update(transaction, refname,
3703 - null_sha1, have_old ? old_sha1 : NULL,
3704 + null_sha1, old_sha1,
3705 flags, msg, err);
3706 }
3707
refs.h
+3 -3
@@ -295,8 +295,8 @@ int ref_transaction_create(struct ref_transaction *transaction,
295 struct strbuf *err);
296
297 /*
298 - * Add a reference deletion to transaction. If have_old is true, then
299 - * old_sha1 holds the value that the reference should have had before
298 + * Add a reference deletion to transaction. If old_sha1 is non-NULL, then
299 + * it holds the value that the reference should have had before
300 * the update (which must not be the null SHA-1).
301 * Function returns 0 on success and non-zero on failure. A failure to delete
302 * means that the transaction as a whole has failed and will need to be
@@ -305,7 +305,7 @@ int ref_transaction_create(struct ref_transaction *transaction,
305 int ref_transaction_delete(struct ref_transaction *transaction,
306 const char *refname,
307 const unsigned char *old_sha1,
308 - unsigned int flags, int have_old, const char *msg,
308 + unsigned int flags, const char *msg,
309 struct strbuf *err);
310
311 /*