Skip to content

Commit ab5ac95

Browse files
jrngitster
authored andcommitted
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 <[email protected]> Reviewed-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7521cc4 commit ab5ac95

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

builtin/update-ref.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ static struct ref_transaction *transaction;
1616

1717
static char line_termination = '\n';
1818
static int update_flags;
19-
static struct strbuf err = STRBUF_INIT;
2019

2120
/*
2221
* 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,
179178

180179
static const char *parse_cmd_update(struct strbuf *input, const char *next)
181180
{
181+
struct strbuf err = STRBUF_INIT;
182182
char *refname;
183183
unsigned char new_sha1[20];
184184
unsigned char old_sha1[20];
@@ -204,12 +204,14 @@ static const char *parse_cmd_update(struct strbuf *input, const char *next)
204204

205205
update_flags = 0;
206206
free(refname);
207+
strbuf_release(&err);
207208

208209
return next;
209210
}
210211

211212
static const char *parse_cmd_create(struct strbuf *input, const char *next)
212213
{
214+
struct strbuf err = STRBUF_INIT;
213215
char *refname;
214216
unsigned char new_sha1[20];
215217

@@ -232,12 +234,14 @@ static const char *parse_cmd_create(struct strbuf *input, const char *next)
232234

233235
update_flags = 0;
234236
free(refname);
237+
strbuf_release(&err);
235238

236239
return next;
237240
}
238241

239242
static const char *parse_cmd_delete(struct strbuf *input, const char *next)
240243
{
244+
struct strbuf err = STRBUF_INIT;
241245
char *refname;
242246
unsigned char old_sha1[20];
243247
int have_old;
@@ -264,12 +268,14 @@ static const char *parse_cmd_delete(struct strbuf *input, const char *next)
264268

265269
update_flags = 0;
266270
free(refname);
271+
strbuf_release(&err);
267272

268273
return next;
269274
}
270275

271276
static const char *parse_cmd_verify(struct strbuf *input, const char *next)
272277
{
278+
struct strbuf err = STRBUF_INIT;
273279
char *refname;
274280
unsigned char new_sha1[20];
275281
unsigned char old_sha1[20];
@@ -297,6 +303,7 @@ static const char *parse_cmd_verify(struct strbuf *input, const char *next)
297303

298304
update_flags = 0;
299305
free(refname);
306+
strbuf_release(&err);
300307

301308
return next;
302309
}
@@ -365,6 +372,8 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
365372
die("Refusing to perform update with empty message.");
366373

367374
if (read_stdin) {
375+
struct strbuf err = STRBUF_INIT;
376+
368377
transaction = ref_transaction_begin(&err);
369378
if (!transaction)
370379
die("%s", err.buf);

0 commit comments

Comments
 (0)