cat-file: refactor error handling of batch_objects

This just pulls the return value for the function out of the inner loop, so we can break out of the loop rather than do an early return. This will make it easier to put any cleanup for the function in one place. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jan 7, 2014 at 17:10 UTC 07e23839459465c1319c7ce91afaf01d3e31a97e
1 file changed +5 -6
builtin/cat-file.c
+5 -6
@@ -260,6 +260,7 @@ static int batch_objects(struct batch_options *opt)
260 {
261 struct strbuf buf = STRBUF_INIT;
262 struct expand_data data;
263 + int retval = 0;
264
265 if (!opt->format)
266 opt->format = "%(objectname) %(objecttype) %(objectsize)";
@@ -284,8 +285,6 @@ static int batch_objects(struct batch_options *opt)
285 warn_on_object_refname_ambiguity = 0;
286
287 while (strbuf_getline(&buf, stdin, '\n') != EOF) {
287 - int error;
288 -
288 if (data.split_on_whitespace) {
289 /*
290 * Split at first whitespace, tying off the beginning
@@ -300,12 +299,12 @@ static int batch_objects(struct batch_options *opt)
299 data.rest = p;
300 }
301
303 - error = batch_one_object(buf.buf, opt, &data);
304 - if (error)
305 - return error;
302 + retval = batch_one_object(buf.buf, opt, &data);
303 + if (retval)
304 + break;
305 }
306
308 - return 0;
307 + return retval;
308 }
309
310 static const char * const cat_file_usage[] = {