From: Ronnie Sahlberg <sahlberg@google.com>
To: git@vger.kernel.org
Cc: Ronnie Sahlberg <sahlberg@google.com>
Subject: [PATCH 2/5] refs.c: make add_packed_ref return an error instead of calling die
Date: Tue, 19 Aug 2014 09:17:01 -0700 [thread overview]
Message-ID: <1408465024-23162-3-git-send-email-sahlberg@google.com> (raw)
In-Reply-To: <1408465024-23162-1-git-send-email-sahlberg@google.com>
Change add_packed_ref to return an error instead of calling die().
Update all callers to check the return value of add_packed_ref.
We can also skip checking the refname format since this function is now
static and only called from the transaction code.
If we are updating a ref and the refname is bad then we fail the transaction
already in transaction_update_sha1().
For the ref deletion case the only caveat is that we would not want
to move the badly named ref into the packed refs file during transaction
commit. This again is not a problem since if the name is bad, then
resolve_ref_unsafe() will fail which protects us from calling add_packed_ref()
with the bad name.
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
---
refs.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/refs.c b/refs.c
index 65eee72..0aad8c8 100644
--- a/refs.c
+++ b/refs.c
@@ -1135,17 +1135,16 @@ static struct ref_dir *get_packed_refs(struct ref_cache *refs)
return get_packed_ref_dir(get_packed_ref_cache(refs));
}
-static void add_packed_ref(const char *refname, const unsigned char *sha1)
+static int add_packed_ref(const char *refname, const unsigned char *sha1)
{
struct packed_ref_cache *packed_ref_cache =
get_packed_ref_cache(&ref_cache);
if (!packed_ref_cache->lock)
- die("internal error: packed refs not locked");
- if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL|REFNAME_DOT_COMPONENT))
- die("Reference has invalid format: '%s'", refname);
+ return -1;
add_ref(get_packed_ref_dir(packed_ref_cache),
create_ref_entry(refname, sha1, REF_ISPACKED));
+ return 0;
}
/*
@@ -3666,7 +3665,13 @@ int transaction_commit(struct ref_transaction *transaction,
RESOLVE_REF_READING, NULL))
continue;
- add_packed_ref(update->refname, sha1);
+ if (add_packed_ref(update->refname, sha1)) {
+ if (err)
+ strbuf_addf(err, "Failed to add %s to packed "
+ "refs", update->refname);
+ ret = -1;
+ goto cleanup;
+ }
need_repack = 1;
}
if (need_repack) {
@@ -3778,7 +3783,13 @@ int transaction_commit(struct ref_transaction *transaction,
packed = get_packed_refs(&ref_cache);
remove_entry(packed, update->refname);
- add_packed_ref(update->refname, update->new_sha1);
+ if (add_packed_ref(update->refname, update->new_sha1)) {
+ if (err)
+ strbuf_addf(err, "Failed to add %s to packed "
+ "refs", update->refname);
+ ret = -1;
+ goto cleanup;
+ }
need_repack = 1;
try_remove_empty_parents((char *)update->refname);
--
2.0.1.556.ge8f7cba.dirty
next prev parent reply other threads:[~2014-08-19 16:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-19 16:16 [PATCH 0/5] ref-transactions-req-strbuf-err Ronnie Sahlberg
2014-08-19 16:17 ` [PATCH 1/5] refs.c: replace the onerr argument in update_ref with a strbuf err Ronnie Sahlberg
2014-08-19 16:17 ` Ronnie Sahlberg [this message]
2014-08-19 16:17 ` [PATCH 3/5] refs.c: make lock_packed_refs take an err argument Ronnie Sahlberg
2014-08-19 16:17 ` [PATCH 4/5] refs.c: add an err argument to commit_packed_refs Ronnie Sahlberg
2014-08-19 16:17 ` [PATCH 5/5] refs.c: add an err argument to pack_refs Ronnie Sahlberg
-- strict thread matches above, loose matches on Subject: below --
2014-07-31 21:25 [PATCH 0/5] ref-transactions-req-strbuf-err Ronnie Sahlberg
2014-07-31 21:25 ` [PATCH 2/5] refs.c: make add_packed_ref return an error instead of calling die 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=1408465024-23162-3-git-send-email-sahlberg@google.com \
--to=sahlberg@google.com \
--cc=git@vger.kernel.org \
/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).