From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Stefan Beller" <sbeller@google.com>,
"Ronnie Sahlberg" <ronniesahlberg@gmail.com>,
"Jonathan Nieder" <jrnieder@gmail.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
git@vger.kernel.org, "Michael Haggerty" <mhagger@alum.mit.edu>
Subject: [PATCH v3 06/13] ref_transaction_delete(): remove "have_old" parameter
Date: Tue, 17 Feb 2015 18:00:16 +0100 [thread overview]
Message-ID: <1424192423-27979-7-git-send-email-mhagger@alum.mit.edu> (raw)
In-Reply-To: <1424192423-27979-1-git-send-email-mhagger@alum.mit.edu>
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>
---
builtin/receive-pack.c | 3 +--
builtin/update-ref.c | 5 +++--
refs.c | 11 ++++++-----
refs.h | 6 +++---
4 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 0be50e9..70e9ce5 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -953,8 +953,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
if (ref_transaction_delete(transaction,
namespaced_name,
old_sha1,
- 0, old_sha1 != NULL,
- "push", &err)) {
+ 0, "push", &err)) {
rp_error("%s", err.buf);
strbuf_release(&err);
return "failed to delete";
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 1ad6ce1..226995f 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -265,8 +265,9 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
if (*next != line_termination)
die("delete %s: extra input: %s", refname, next);
- if (ref_transaction_delete(transaction, refname, old_sha1,
- update_flags, have_old, msg, &err))
+ if (ref_transaction_delete(transaction, refname,
+ have_old ? old_sha1 : NULL,
+ update_flags, msg, &err))
die("%s", err.buf);
update_flags = 0;
diff --git a/refs.c b/refs.c
index e88817c..e3c4ab5 100644
--- a/refs.c
+++ b/refs.c
@@ -2576,7 +2576,7 @@ static void prune_ref(struct ref_to_prune *r)
transaction = ref_transaction_begin(&err);
if (!transaction ||
ref_transaction_delete(transaction, r->name, r->sha1,
- REF_ISPRUNING, 1, NULL, &err) ||
+ REF_ISPRUNING, NULL, &err) ||
ref_transaction_commit(transaction, &err)) {
ref_transaction_free(transaction);
error("%s", err.buf);
@@ -2753,8 +2753,9 @@ int delete_ref(const char *refname, const unsigned char *sha1, unsigned int flag
transaction = ref_transaction_begin(&err);
if (!transaction ||
- ref_transaction_delete(transaction, refname, sha1, flags,
- sha1 && !is_null_sha1(sha1), NULL, &err) ||
+ ref_transaction_delete(transaction, refname,
+ (sha1 && !is_null_sha1(sha1)) ? sha1 : NULL,
+ flags, NULL, &err) ||
ref_transaction_commit(transaction, &err)) {
error("%s", err.buf);
ref_transaction_free(transaction);
@@ -3696,11 +3697,11 @@ int ref_transaction_create(struct ref_transaction *transaction,
int ref_transaction_delete(struct ref_transaction *transaction,
const char *refname,
const unsigned char *old_sha1,
- unsigned int flags, int have_old, const char *msg,
+ unsigned int flags, const char *msg,
struct strbuf *err)
{
return ref_transaction_update(transaction, refname,
- null_sha1, have_old ? old_sha1 : NULL,
+ null_sha1, old_sha1,
flags, msg, err);
}
diff --git a/refs.h b/refs.h
index dced4c9..100731d 100644
--- a/refs.h
+++ b/refs.h
@@ -295,8 +295,8 @@ int ref_transaction_create(struct ref_transaction *transaction,
struct strbuf *err);
/*
- * Add a reference deletion to transaction. If have_old is true, then
- * old_sha1 holds the value that the reference should have had before
+ * Add a reference deletion to transaction. If old_sha1 is non-NULL, then
+ * it holds the value that the reference should have had before
* the update (which must not be the null SHA-1).
* Function returns 0 on success and non-zero on failure. A failure to delete
* 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,
int ref_transaction_delete(struct ref_transaction *transaction,
const char *refname,
const unsigned char *old_sha1,
- unsigned int flags, int have_old, const char *msg,
+ unsigned int flags, const char *msg,
struct strbuf *err);
/*
--
2.1.4
next prev parent reply other threads:[~2015-02-17 17:00 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-17 17:00 [PATCH v3 00/13] Allow reference values to be checked in a transaction Michael Haggerty
2015-02-17 17:00 ` [PATCH v3 01/13] refs: move REF_DELETING to refs.c Michael Haggerty
2015-02-17 17:00 ` [PATCH v3 02/13] refs: remove the gap in the REF_* constant values Michael Haggerty
2015-02-17 17:00 ` [PATCH v3 03/13] refs.c: Change some "flags" to "unsigned int" Michael Haggerty
2015-02-17 17:00 ` [PATCH v3 04/13] struct ref_update: move "have_old" into "flags" Michael Haggerty
2015-02-17 17:00 ` [PATCH v3 05/13] ref_transaction_update(): remove "have_old" parameter Michael Haggerty
2015-02-17 17:00 ` Michael Haggerty [this message]
2015-02-17 17:00 ` [PATCH v3 07/13] commit: add tests of commit races Michael Haggerty
2015-02-17 17:00 ` [PATCH v3 08/13] commit: avoid race when creating orphan commits Michael Haggerty
2015-02-17 17:00 ` [PATCH v3 09/13] ref_transaction_create(): check that new_sha1 is valid Michael Haggerty
2015-02-17 17:00 ` [PATCH v3 10/13] ref_transaction_delete(): check that old_sha1 is not null_sha1 Michael Haggerty
2015-02-17 17:00 ` [PATCH v3 11/13] ref_transaction_verify(): new function to check a reference's value Michael Haggerty
2015-02-17 17:00 ` [PATCH v3 12/13] update_ref(): improve documentation Michael Haggerty
2015-02-17 17:00 ` [PATCH v3 13/13] refs.h: Remove duplication in function docstrings Michael Haggerty
2015-02-17 19:29 ` [PATCH v3 00/13] Allow reference values to be checked in a transaction Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1424192423-27979-7-git-send-email-mhagger@alum.mit.edu \
--to=mhagger@alum.mit.edu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=pclouds@gmail.com \
--cc=ronniesahlberg@gmail.com \
--cc=sbeller@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).