]> git.ipfire.org Git - thirdparty/git.git/commitdiff
cat-file: refactor error handling of batch_objects
authorJeff King <peff@peff.net>
Tue, 7 Jan 2014 22:10:15 +0000 (17:10 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 Jan 2014 22:31:10 +0000 (14:31 -0800)
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>
builtin/cat-file.c

index b2ca775a80f54fcceba344d5545fe3cb34ba0184..6b65f56f447ab6856244320a4b2221807c840ea1 100644 (file)
@@ -260,6 +260,7 @@ static int batch_objects(struct batch_options *opt)
 {
        struct strbuf buf = STRBUF_INIT;
        struct expand_data data;
+       int retval = 0;
 
        if (!opt->format)
                opt->format = "%(objectname) %(objecttype) %(objectsize)";
@@ -284,8 +285,6 @@ static int batch_objects(struct batch_options *opt)
        warn_on_object_refname_ambiguity = 0;
 
        while (strbuf_getline(&buf, stdin, '\n') != EOF) {
-               int error;
-
                if (data.split_on_whitespace) {
                        /*
                         * Split at first whitespace, tying off the beginning
@@ -300,12 +299,12 @@ static int batch_objects(struct batch_options *opt)
                        data.rest = p;
                }
 
-               error = batch_one_object(buf.buf, opt, &data);
-               if (error)
-                       return error;
+               retval = batch_one_object(buf.buf, opt, &data);
+               if (retval)
+                       break;
        }
 
-       return 0;
+       return retval;
 }
 
 static const char * const cat_file_usage[] = {