Skip to content

Commit

Permalink
cat-file: refactor error handling of batch_objects
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jan 7, 2014
1 parent 832cf74 commit 07e2383
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions builtin/cat-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)";
Expand All @@ -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
Expand All @@ -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[] = {
Expand Down

0 comments on commit 07e2383

Please sign in to comment.