From: Ronnie Sahlberg <sahlberg@google.com>
To: git@vger.kernel.org
Cc: mhagger@alum.mit.edu, Ronnie Sahlberg <sahlberg@google.com>
Subject: [PATCH 16/31] refs.c: add an error argument to create/delete/update just like commit
Date: Wed, 14 May 2014 15:13:15 -0700 [thread overview]
Message-ID: <1400105610-21194-17-git-send-email-sahlberg@google.com> (raw)
In-Reply-To: <1400105610-21194-1-git-send-email-sahlberg@google.com>
Update the signatures for transaction create/delete/update and add
a strbuf err argument we can use to pass an error back to the caller.
We will need this later once we start moving checks from _commit to _update.
Change all callers that would die() on _commit failures to handle _update
failures similarly.
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
---
branch.c | 3 ++-
builtin/commit.c | 2 +-
builtin/fetch.c | 2 +-
builtin/receive-pack.c | 3 ++-
builtin/replace.c | 2 +-
builtin/tag.c | 2 +-
builtin/update-ref.c | 20 ++++++++++++--------
fast-import.c | 8 +++++---
refs.c | 24 ++++++++++++++----------
refs.h | 9 ++++++---
sequencer.c | 2 +-
walker.c | 3 ++-
12 files changed, 48 insertions(+), 32 deletions(-)
diff --git a/branch.c b/branch.c
index 0a4d4f3..0b9fd61 100644
--- a/branch.c
+++ b/branch.c
@@ -301,7 +301,8 @@ void create_branch(const char *head,
transaction = transaction_begin();
if (!transaction ||
transaction_update_sha1(transaction, ref.buf, sha1,
- null_sha1, 0, !forcing, msg) ||
+ null_sha1, 0, !forcing, msg,
+ &err) ||
transaction_commit(transaction, &err))
die_errno(_("%s: failed to write ref: %s"),
ref.buf, err.buf);
diff --git a/builtin/commit.c b/builtin/commit.c
index 386dfb1..fd61a8e 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1721,7 +1721,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
transaction_update_sha1(transaction, "HEAD", sha1,
current_head ?
current_head->object.sha1 : NULL,
- 0, !!current_head, sb.buf) ||
+ 0, !!current_head, sb.buf, &err) ||
transaction_commit(transaction, &err)) {
rollback_index_files();
die(_("HEAD: cannot update ref: %s"), err.buf);
diff --git a/builtin/fetch.c b/builtin/fetch.c
index f74a267..e5e891f 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -384,7 +384,7 @@ static int s_update_ref(const char *action,
snprintf(msg, sizeof(msg), "%s: %s", rla, action);
if (transaction_update_sha1(transaction, ref->name, ref->new_sha1,
- ref->old_sha1, 0, check_old, msg))
+ ref->old_sha1, 0, check_old, msg, NULL))
return STORE_REF_ERROR_OTHER;
return 0;
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 0461f93..777ecf8 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -582,7 +582,8 @@ static const char *update(struct command *cmd, struct shallow_info *si)
return "shallow error";
if (transaction_update_sha1(transaction, namespaced_name,
- new_sha1, old_sha1, 0, 1, "push"))
+ new_sha1, old_sha1, 0, 1, "push",
+ &err))
return "failed to update";
return NULL; /* good */
}
diff --git a/builtin/replace.c b/builtin/replace.c
index 2587a06..1598d69 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -160,7 +160,7 @@ static int replace_object_sha1(const char *object_ref,
transaction = transaction_begin();
if (!transaction ||
transaction_update_sha1(transaction, ref, repl, prev,
- 0, !is_null_sha1(prev), NULL) ||
+ 0, !is_null_sha1(prev), NULL, &err) ||
transaction_commit(transaction, &err))
die(_("%s: failed to replace ref: %s"), ref, err.buf);
diff --git a/builtin/tag.c b/builtin/tag.c
index 3739e23..9b6da6c 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -705,7 +705,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
transaction = transaction_begin();
if (!transaction ||
transaction_update_sha1(transaction, ref.buf, object, prev,
- 0, !is_null_sha1(prev), NULL) ||
+ 0, !is_null_sha1(prev), NULL, &err) ||
transaction_commit(transaction, &err))
die(_("%s: cannot update the ref: %s"), ref.buf, err.buf);
transaction_free(transaction);
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index f7e33bd..1b0c889 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -183,6 +183,7 @@ static const char *parse_cmd_update(struct strbuf *input, const char *next)
unsigned char new_sha1[20];
unsigned char old_sha1[20];
int have_old;
+ struct strbuf err = STRBUF_INIT;
refname = parse_refname(input, &next);
if (!refname)
@@ -199,8 +200,8 @@ static const char *parse_cmd_update(struct strbuf *input, const char *next)
die("update %s: extra input: %s", refname, next);
if (transaction_update_sha1(transaction, refname, new_sha1, old_sha1,
- update_flags, have_old, msg))
- die("update %s: failed", refname);
+ update_flags, have_old, msg, &err))
+ die("%s", err.buf);
update_flags = 0;
free(refname);
@@ -212,6 +213,7 @@ static const char *parse_cmd_create(struct strbuf *input, const char *next)
{
char *refname;
unsigned char new_sha1[20];
+ struct strbuf err = STRBUF_INIT;
refname = parse_refname(input, &next);
if (!refname)
@@ -227,8 +229,8 @@ static const char *parse_cmd_create(struct strbuf *input, const char *next)
die("create %s: extra input: %s", refname, next);
if (transaction_create_sha1(transaction, refname, new_sha1,
- update_flags, msg))
- die("failed transaction create for %s", refname);
+ update_flags, msg, &err))
+ die("%s", err.buf);
update_flags = 0;
free(refname);
@@ -241,6 +243,7 @@ static const char *parse_cmd_delete(struct strbuf *input, const char *next)
char *refname;
unsigned char old_sha1[20];
int have_old;
+ struct strbuf err = STRBUF_INIT;
refname = parse_refname(input, &next);
if (!refname)
@@ -259,8 +262,8 @@ static const char *parse_cmd_delete(struct strbuf *input, const char *next)
die("delete %s: extra input: %s", refname, next);
if (transaction_delete_sha1(transaction, refname, old_sha1,
- update_flags, have_old, msg))
- die("failed transaction delete for %s", refname);
+ update_flags, have_old, msg, &err))
+ die("%s", err.buf);
update_flags = 0;
free(refname);
@@ -274,6 +277,7 @@ static const char *parse_cmd_verify(struct strbuf *input, const char *next)
unsigned char new_sha1[20];
unsigned char old_sha1[20];
int have_old;
+ struct strbuf err = STRBUF_INIT;
refname = parse_refname(input, &next);
if (!refname)
@@ -292,8 +296,8 @@ static const char *parse_cmd_verify(struct strbuf *input, const char *next)
die("verify %s: extra input: %s", refname, next);
if (transaction_update_sha1(transaction, refname, new_sha1, old_sha1,
- update_flags, have_old, msg))
- die("failed transaction update for %s", refname);
+ update_flags, have_old, msg, &err))
+ die("%s", err.buf);
update_flags = 0;
free(refname);
diff --git a/fast-import.c b/fast-import.c
index 2fa1d29..24378d1 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1710,7 +1710,7 @@ static int update_branch(struct branch *b)
transaction = transaction_begin();
if (!transaction ||
transaction_update_sha1(transaction, b->name, b->sha1, old_sha1,
- 0, 1, msg) ||
+ 0, 1, msg, &err) ||
transaction_commit(transaction, &err)) {
transaction_rollback(transaction);
error("Unable to update branch %s: %s", b->name, err.buf);
@@ -1745,8 +1745,10 @@ static void dump_tags(void)
sprintf(ref_name, "refs/tags/%s", t->name);
if (transaction_update_sha1(transaction, ref_name, t->sha1,
- NULL, 0, 0, msg))
- failure |= error("Unable to update %s", err.buf);
+ NULL, 0, 0, msg, &err)) {
+ failure |= 1;
+ break;
+ }
}
if (failure || transaction_commit(transaction, &err))
failure |= error("Unable to update %s", err.buf);
diff --git a/refs.c b/refs.c
index b006238..59f1ca1 100644
--- a/refs.c
+++ b/refs.c
@@ -2364,7 +2364,7 @@ static void prune_ref(struct ref_to_prune *r)
transaction = transaction_begin();
if (!transaction ||
transaction_delete_sha1(transaction, r->name, r->sha1,
- REF_ISPRUNING, 1, NULL) ||
+ REF_ISPRUNING, 1, NULL, &err) ||
transaction_commit(transaction, &err)) {
transaction_rollback(transaction);
warning("prune_ref: %s", err.buf);
@@ -2528,7 +2528,7 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
transaction = transaction_begin();
if (!transaction ||
transaction_delete_sha1(transaction, refname, sha1, delopt,
- sha1 && !is_null_sha1(sha1), NULL) ||
+ sha1 && !is_null_sha1(sha1), NULL, NULL) ||
transaction_commit(transaction, NULL)) {
transaction_rollback(transaction);
return 1;
@@ -2633,9 +2633,9 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
if (!transaction ||
transaction_delete_sha1(transaction, oldrefname, sha1,
REF_NODEREF | REF_ISPACKONLY,
- 1, NULL) ||
+ 1, NULL, &err) ||
transaction_update_sha1(transaction, newrefname, sha1,
- NULL, 0, 0, logmsg) ||
+ NULL, 0, 0, logmsg, &err) ||
transaction_commit(transaction, &err)) {
transaction_rollback(transaction);
error("rename_ref failed: %s", err.buf);
@@ -3410,7 +3410,8 @@ int transaction_update_sha1(struct ref_transaction *transaction,
const char *refname,
const unsigned char *new_sha1,
const unsigned char *old_sha1,
- int flags, int have_old, const char *msg)
+ int flags, int have_old, const char *msg,
+ struct strbuf *err)
{
struct ref_update *update;
@@ -3454,7 +3455,8 @@ int transaction_update_sha1(struct ref_transaction *transaction,
int transaction_create_sha1(struct ref_transaction *transaction,
const char *refname,
const unsigned char *new_sha1,
- int flags, const char *msg)
+ int flags, const char *msg,
+ struct strbuf *err)
{
struct ref_update *update;
@@ -3468,13 +3470,14 @@ int transaction_create_sha1(struct ref_transaction *transaction,
die("BUG: REF_ISPACKONLY can not be used with create");
return transaction_update_sha1(transaction, refname, new_sha1,
- null_sha1, flags, 1, msg);
+ null_sha1, flags, 1, msg, err);
}
int transaction_delete_sha1(struct ref_transaction *transaction,
const char *refname,
const unsigned char *old_sha1,
- int flags, int have_old, const char *msg)
+ int flags, int have_old, const char *msg,
+ struct strbuf *err)
{
struct ref_update *update;
@@ -3488,7 +3491,8 @@ int transaction_delete_sha1(struct ref_transaction *transaction,
die("BUG: delete on transaction that is not open");
return transaction_update_sha1(transaction, refname, null_sha1,
- old_sha1, flags, have_old, msg);
+ old_sha1, flags, have_old, msg,
+ err);
}
int update_ref(const char *action, const char *refname,
@@ -3501,7 +3505,7 @@ int update_ref(const char *action, const char *refname,
t = transaction_begin();
if (!t ||
transaction_update_sha1(t, refname, sha1, oldval, flags,
- !!oldval, action) ||
+ !!oldval, action, &err) ||
transaction_commit(t, &err)) {
const char *str = "update_ref failed for ref '%s': %s";
diff --git a/refs.h b/refs.h
index c552f04..ebe7368 100644
--- a/refs.h
+++ b/refs.h
@@ -244,7 +244,8 @@ int transaction_update_sha1(struct ref_transaction *transaction,
const char *refname,
const unsigned char *new_sha1,
const unsigned char *old_sha1,
- int flags, int have_old, const char *msg);
+ int flags, int have_old, const char *msg,
+ struct strbuf *err);
/*
* Add a reference creation to transaction. new_sha1 is the value
@@ -256,7 +257,8 @@ int transaction_update_sha1(struct ref_transaction *transaction,
int transaction_create_sha1(struct ref_transaction *transaction,
const char *refname,
const unsigned char *new_sha1,
- int flags, const char *msg);
+ int flags, const char *msg,
+ struct strbuf *err);
/*
* Add a reference deletion to transaction. If have_old is true, then
@@ -267,7 +269,8 @@ int transaction_create_sha1(struct ref_transaction *transaction,
int transaction_delete_sha1(struct ref_transaction *transaction,
const char *refname,
const unsigned char *old_sha1,
- int flags, int have_old, const char *msg);
+ int flags, int have_old, const char *msg,
+ struct strbuf *err);
#define REFLOG_TRUNCATE 0x01
/*
diff --git a/sequencer.c b/sequencer.c
index 3f7996f..604df39 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -285,7 +285,7 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from,
transaction = transaction_begin();
if (!transaction ||
transaction_update_sha1(transaction, "HEAD", to, from,
- 0, !unborn, sb.buf) ||
+ 0, !unborn, sb.buf, &err) ||
transaction_commit(transaction, &err)) {
transaction_rollback(transaction);
error(_("HEAD: Could not fast-forward: %s\n"), err.buf);
diff --git a/walker.c b/walker.c
index 3701c78..8630fcb 100644
--- a/walker.c
+++ b/walker.c
@@ -292,7 +292,8 @@ int walker_fetch(struct walker *walker, int targets, char **target,
if (transaction_update_sha1(transaction, ref_name,
&sha1[20 * i], NULL,
0, 0,
- msg ? msg : "fetch (unknown)"))
+ msg ? msg : "fetch (unknown)",
+ &err))
goto rollback_and_fail;
}
--
2.0.0.rc3.506.g3739a35
next prev parent reply other threads:[~2014-05-14 22:14 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-14 22:12 [PATCH 00/31] Finish implementing ref and reflog transactions Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 01/31] refs.c make ref_transaction_create a wrapper to ref_transaction_update Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 02/31] refs.c: make ref_transaction_delete a wrapper for ref_transaction_update Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 03/31] refs.c: rename the transaction functions Ronnie Sahlberg
2014-05-16 21:15 ` Junio C Hamano
2014-05-19 23:11 ` Ronnie Sahlberg
2014-05-19 23:25 ` Junio C Hamano
2014-05-14 22:13 ` [PATCH 04/31] refs.c: add a new update_type field to ref_update Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 05/31] refs.c: add a function to append a reflog entry to a fd Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 06/31] refs.c: add a transaction function to append a reflog entry Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 07/31] refs.c: add a flag to allow reflog updates to truncate the log Ronnie Sahlberg
2014-05-16 21:20 ` Junio C Hamano
2014-05-19 23:27 ` Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 08/31] refs.c: only write reflog update if msg is non-NULL Ronnie Sahlberg
2014-05-16 21:24 ` Junio C Hamano
2014-05-19 22:55 ` Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 09/31] refs.c: allow multiple reflog updates during a single transaction Ronnie Sahlberg
2014-05-16 21:35 ` Junio C Hamano
2014-05-16 22:01 ` Eric Sunshine
2014-05-19 22:58 ` Ronnie Sahlberg
2014-05-19 23:06 ` Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 10/31] reflog.c: use a reflog transaction when writing during expire Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 11/31] refs.c: null terminate the string in copy_msg Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 12/31] refs.c: track the refnames we are deleting in the transaction structure Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 13/31] refs.c: update the list of deleted refs during _update instead of _commit Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 14/31] refs.c: return error instead of dying when locking fails during transaction Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 15/31] refs.c: lock the ref during _update instead of during _commit Ronnie Sahlberg
2014-05-14 22:13 ` Ronnie Sahlberg [this message]
2014-05-14 22:13 ` [PATCH 17/31] refs.c: make _update_reflog take an error argument Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 18/31] refs.c: return immediately from _commit if the transaction has an error Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 19/31] tests: move tests for -z update/delete/verify to after the ref is created Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 20/31] refs.c: check for lock conflicts already in _update Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 21/31] refs.c allow multiple updates of the same ref in a transaction Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 22/31] refs.c: release all remaining locks during transaction_free Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 23/31] reflog.c: use the existing transaction to also lock and update the ref Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 24/31] refs.c: make unlock_ref static Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 25/31] refs.c: make close_ref static Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 26/31] refs.c: make commit_ref static Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 27/31] refs.c: remove the function lock_any_ref_for_update Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 28/31] refs.c: make struct ref_lock private to refs.c Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 29/31] refs.c: allow passing raw git_committer_info as email to _update_reflog Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 30/31] refs.c: move ref_update and other definitions to earlier in the file Ronnie Sahlberg
2014-05-14 22:13 ` [PATCH 31/31] refs.c: use the transaction to manage the reflog in rename_refs Ronnie Sahlberg
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=1400105610-21194-17-git-send-email-sahlberg@google.com \
--to=sahlberg@google.com \
--cc=git@vger.kernel.org \
--cc=mhagger@alum.mit.edu \
/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).