From 07e23839459465c1319c7ce91afaf01d3e31a97e Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 7 Jan 2014 17:10:15 -0500 Subject: 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 Signed-off-by: Junio C Hamano --- builtin/cat-file.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'builtin/cat-file.c') diff --git a/builtin/cat-file.c b/builtin/cat-file.c index b2ca775a80..6b65f56f44 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -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[] = { -- cgit v1.2.3 From 648027c4c85bbfdcf0663ff51e55425aefac14a9 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 7 Jan 2014 17:10:35 -0500 Subject: cat-file: fix a minor memory leak in batch_objects We should always have been freeing our strbuf, but doing so consistently was annoying until the refactoring in the previous patch. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/cat-file.c | 1 + 1 file changed, 1 insertion(+) (limited to 'builtin/cat-file.c') diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 6b65f56f44..1fdb980258 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -304,6 +304,7 @@ static int batch_objects(struct batch_options *opt) break; } + strbuf_release(&buf); return retval; } -- cgit v1.2.3 From a42fcd15d82b6660377749064e0ad25742ccc6f7 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 12 Mar 2014 16:05:43 -0400 Subject: cat-file: restore warn_on_object_refname_ambiguity flag Commit 25fba78 turned off the object/refname ambiguity check during "git cat-file --batch" operations. However, this is a global flag, so let's restore it when we are done. This shouldn't make any practical difference, as cat-file exits immediately afterwards, but is good code hygeine and would prevent an unnecessary surprise if somebody starts to call cmd_cat_file later. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/cat-file.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'builtin/cat-file.c') diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 1fdb980258..cc863ff78c 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -260,6 +260,7 @@ static int batch_objects(struct batch_options *opt) { struct strbuf buf = STRBUF_INIT; struct expand_data data; + int save_warning; int retval = 0; if (!opt->format) @@ -282,6 +283,7 @@ static int batch_objects(struct batch_options *opt) * warn) ends up dwarfing the actual cost of the object lookups * themselves. We can work around it by just turning off the warning. */ + save_warning = warn_on_object_refname_ambiguity; warn_on_object_refname_ambiguity = 0; while (strbuf_getline(&buf, stdin, '\n') != EOF) { @@ -305,6 +307,7 @@ static int batch_objects(struct batch_options *opt) } strbuf_release(&buf); + warn_on_object_refname_ambiguity = save_warning; return retval; } -- cgit v1.2.3