aboutsummaryrefslogtreecommitdiff
path: root/builtin/update-ref.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2014-09-02 14:10:52 -0700
committerJunio C Hamano <gitster@pobox.com>2014-09-03 10:04:19 -0700
commitab5ac95725f7a4f36f72be48f340a84e46996e90 (patch)
treea3496136ea02fecc20b771a7128dfb8845861ee8 /builtin/update-ref.c
parent7521cc4611a783f4a8174bd0fcec5f4a47357ac1 (diff)
downloadgit-ab5ac95725f7a4f36f72be48f340a84e46996e90.tar.gz
git-ab5ac95725f7a4f36f72be48f340a84e46996e90.tar.xz
update-ref --stdin: narrow scope of err strbuf
Making the strbuf local in each function that needs to print errors saves the reader from having to think about action at a distance, such as * errors piling up and being concatenated with no newline between them * errors unhandled in one function, to be later handled in another * concurrency issues, if this code starts using threads some day No functional change intended. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/update-ref.c')
-rw-r--r--builtin/update-ref.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 96a53b92a..866bbee67 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -16,7 +16,6 @@ static struct ref_transaction *transaction;
static char line_termination = '\n';
static int update_flags;
-static struct strbuf err = STRBUF_INIT;
/*
* Parse one whitespace- or NUL-terminated, possibly C-quoted argument
@@ -179,6 +178,7 @@ static int parse_next_sha1(struct strbuf *input, const char **next,
static const char *parse_cmd_update(struct strbuf *input, const char *next)
{
+ struct strbuf err = STRBUF_INIT;
char *refname;
unsigned char new_sha1[20];
unsigned char old_sha1[20];
@@ -204,12 +204,14 @@ static const char *parse_cmd_update(struct strbuf *input, const char *next)
update_flags = 0;
free(refname);
+ strbuf_release(&err);
return next;
}
static const char *parse_cmd_create(struct strbuf *input, const char *next)
{
+ struct strbuf err = STRBUF_INIT;
char *refname;
unsigned char new_sha1[20];
@@ -232,12 +234,14 @@ static const char *parse_cmd_create(struct strbuf *input, const char *next)
update_flags = 0;
free(refname);
+ strbuf_release(&err);
return next;
}
static const char *parse_cmd_delete(struct strbuf *input, const char *next)
{
+ struct strbuf err = STRBUF_INIT;
char *refname;
unsigned char old_sha1[20];
int have_old;
@@ -264,12 +268,14 @@ static const char *parse_cmd_delete(struct strbuf *input, const char *next)
update_flags = 0;
free(refname);
+ strbuf_release(&err);
return next;
}
static const char *parse_cmd_verify(struct strbuf *input, const char *next)
{
+ struct strbuf err = STRBUF_INIT;
char *refname;
unsigned char new_sha1[20];
unsigned char old_sha1[20];
@@ -297,6 +303,7 @@ static const char *parse_cmd_verify(struct strbuf *input, const char *next)
update_flags = 0;
free(refname);
+ strbuf_release(&err);
return next;
}
@@ -365,6 +372,8 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
die("Refusing to perform update with empty message.");
if (read_stdin) {
+ struct strbuf err = STRBUF_INIT;
+
transaction = ref_transaction_begin(&err);
if (!transaction)
die("%s", err.buf);