git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Heiko Voigt <hvoigt@hvoigt.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Stefan Beller" <sbeller@google.com>,
	"Git List" <git@vger.kernel.org>,
	"Lars Schneider" <larsxschneider@gmail.com>,
	"René Scharfe" <l.s.r@web.de>
Subject: [PATCH 2/3] submodule-config: combine early return code into one goto
Date: Thu, 28 Jul 2016 14:49:47 +0200	[thread overview]
Message-ID: <20160728124947.GB2530@sandbox> (raw)
In-Reply-To: <xmqqmvl4xdlm.fsf@gitster.mtv.corp.google.com>

So we have simpler return handling code and all the cleanup code in
almost one place.

Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
---
This is an updated cleanup patch. Now with goto so we have simpler code.

 submodule-config.c | 31 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 19 deletions(-)

diff --git a/submodule-config.c b/submodule-config.c
index 853989e..a887574 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -376,7 +376,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
 {
 	struct strbuf rev = STRBUF_INIT;
 	unsigned long config_size;
-	char *config;
+	char *config = NULL;
 	unsigned char sha1[20];
 	enum object_type type;
 	const struct submodule *submodule = NULL;
@@ -397,10 +397,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,
 		return entry->config;
 	}
 
-	if (!gitmodule_sha1_from_commit(commit_sha1, sha1, &rev)) {
-		strbuf_release(&rev);
-		return NULL;
-	}
+	if (!gitmodule_sha1_from_commit(commit_sha1, sha1, &rev))
+		goto out;
 
 	switch (lookup_type) {
 	case lookup_name:
@@ -410,22 +408,12 @@ static const struct submodule *config_from(struct submodule_cache *cache,
 		submodule = cache_lookup_path(cache, sha1, key);
 		break;
 	}
-	if (submodule) {
-		strbuf_release(&rev);
-		return submodule;
-	}
+	if (submodule)
+		goto out;
 
 	config = read_sha1_file(sha1, &type, &config_size);
-	if (!config) {
-		strbuf_release(&rev);
-		return NULL;
-	}
-
-	if (type != OBJ_BLOB) {
-		strbuf_release(&rev);
-		free(config);
-		return NULL;
-	}
+	if (!config || type != OBJ_BLOB)
+		goto out;
 
 	/* fill the submodule config into the cache */
 	parameter.cache = cache;
@@ -445,6 +433,11 @@ static const struct submodule *config_from(struct submodule_cache *cache,
 	default:
 		return NULL;
 	}
+
+out:
+	strbuf_release(&rev);
+	free(config);
+	return submodule;
 }
 
 static const struct submodule *config_from_path(struct submodule_cache *cache,
-- 
2.0.2.832.g083c931


  parent reply	other threads:[~2016-07-28 12:49 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-19 19:05 [PATCH] submodule-config: use explicit empty string instead of strbuf in config_from() René Scharfe
2016-07-19 19:15 ` Junio C Hamano
2016-07-19 19:24   ` Stefan Beller
2016-07-20  8:25 ` Heiko Voigt
2016-07-21 18:57   ` René Scharfe
2016-07-25 14:37     ` Heiko Voigt
2016-07-25 14:58       ` Junio C Hamano
2016-07-26  9:49         ` [PATCH 1/2] fix passing a name for config from submodules Heiko Voigt
2016-07-26 17:22           ` Stefan Beller
2016-07-26 22:02             ` Junio C Hamano
2016-07-28 12:49               ` [PATCH 1/3] submodule-config: passing name reference for .gitmodule blobs Heiko Voigt
2016-07-28 16:26                 ` Stefan Beller
2016-07-28 12:49               ` Heiko Voigt [this message]
2016-07-28 12:50               ` [PATCH 3/3] submodule-config: fix test binary crashing when no arguments given Heiko Voigt
2016-07-28 11:17             ` [PATCH 1/2] fix passing a name for config from submodules Heiko Voigt
2016-07-28 12:55               ` [PATCH] document how to reference previous commits Heiko Voigt
2016-07-28 15:38                 ` Junio C Hamano
2016-07-28 15:57                   ` Stefan Beller
2016-08-17 11:36                 ` Heiko Voigt
2016-08-17 17:45                   ` Junio C Hamano
2016-07-28 14:59               ` [PATCH 1/2] fix passing a name for config from submodules Junio C Hamano
2016-07-26  9:49         ` [PATCH 2/2] submodule-config: combine error checking if clauses Heiko Voigt
2016-07-26 17:24           ` Stefan Beller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160728124947.GB2530@sandbox \
    --to=hvoigt@hvoigt.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    --cc=larsxschneider@gmail.com \
    --cc=sbeller@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).