From: Ronnie Sahlberg <sahlberg@google.com>
To: git@vger.kernel.org
Cc: Ronnie Sahlberg <sahlberg@google.com>
Subject: [PATCH 5/5] refs.c: add an err argument to pack_refs
Date: Tue, 19 Aug 2014 09:17:04 -0700 [thread overview]
Message-ID: <1408465024-23162-6-git-send-email-sahlberg@google.com> (raw)
In-Reply-To: <1408465024-23162-1-git-send-email-sahlberg@google.com>
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
---
builtin/pack-refs.c | 8 +++++++-
refs.c | 13 ++++++-------
refs.h | 3 ++-
3 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/builtin/pack-refs.c b/builtin/pack-refs.c
index b20b1ec..299768e 100644
--- a/builtin/pack-refs.c
+++ b/builtin/pack-refs.c
@@ -10,6 +10,7 @@ static char const * const pack_refs_usage[] = {
int cmd_pack_refs(int argc, const char **argv, const char *prefix)
{
unsigned int flags = PACK_REFS_PRUNE;
+ struct strbuf err = STRBUF_INIT;
struct option opts[] = {
OPT_BIT(0, "all", &flags, N_("pack everything"), PACK_REFS_ALL),
OPT_BIT(0, "prune", &flags, N_("prune loose refs (default)"), PACK_REFS_PRUNE),
@@ -17,5 +18,10 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix)
};
if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))
usage_with_options(pack_refs_usage, opts);
- return pack_refs(flags);
+ if (pack_refs(flags, &err)) {
+ error("%s", err.buf);
+ strbuf_release(&err);
+ return -1;
+ }
+ return 0;
}
diff --git a/refs.c b/refs.c
index 19e73f3..5875c29 100644
--- a/refs.c
+++ b/refs.c
@@ -2328,7 +2328,7 @@ static int commit_packed_refs(struct strbuf *err)
strbuf_addf(err, "error writing packed-refs. %s",
strerror(errno));
return -1;
- }
+ }
data.fd = packed_ref_cache->lock->fd;
data.err = err;
@@ -2482,24 +2482,23 @@ static void prune_refs(struct ref_to_prune *r)
}
}
-int pack_refs(unsigned int flags)
+int pack_refs(unsigned int flags, struct strbuf *err)
{
struct pack_refs_cb_data cbdata;
- struct strbuf err = STRBUF_INIT;
memset(&cbdata, 0, sizeof(cbdata));
cbdata.flags = flags;
- if (lock_packed_refs(&err))
- die("%s", err.buf);
+ if (lock_packed_refs(err))
+ return -1;
cbdata.packed_refs = get_packed_refs(&ref_cache);
do_for_each_entry_in_dir(get_loose_refs(&ref_cache), 0,
pack_if_possible_fn, &cbdata);
- if (commit_packed_refs(&err))
- die("%s", err.buf);
+ if (commit_packed_refs(err))
+ return -1;
prune_refs(cbdata.ref_to_prune);
return 0;
diff --git a/refs.h b/refs.h
index dee9a98..1a98e27 100644
--- a/refs.h
+++ b/refs.h
@@ -122,8 +122,9 @@ extern void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct st
/*
* Write a packed-refs file for the current repository.
* flags: Combination of the above PACK_REFS_* flags.
+ * Returns 0 on success and fills in err on failure.
*/
-int pack_refs(unsigned int flags);
+int pack_refs(unsigned int flags, struct strbuf *err);
extern int ref_exists(const char *);
--
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 ` [PATCH 2/5] refs.c: make add_packed_ref return an error instead of calling die Ronnie Sahlberg
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 ` Ronnie Sahlberg [this message]
-- 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 5/5] refs.c: add an err argument to pack_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=1408465024-23162-6-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).