summaryrefslogtreecommitdiff
path: root/submodule-config.c
diff options
context:
space:
mode:
authorHeiko Voigt <hvoigt@hvoigt.net>2016-07-28 12:49:47 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-07-28 20:05:31 (GMT)
commit0918e25077cb9321011a973703cc597b078f0ab5 (patch)
tree6b2c4aca60fe7dd0604c67ab3027db44b42e89db /submodule-config.c
parent514dea905a3c72c8f7268347793f2947efd547be (diff)
downloadgit-0918e25077cb9321011a973703cc597b078f0ab5.zip
git-0918e25077cb9321011a973703cc597b078f0ab5.tar.gz
git-0918e25077cb9321011a973703cc597b078f0ab5.tar.bz2
submodule-config: combine early return code into one goto
So we have simpler return handling code and all the cleanup code in almost one place. Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net> Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'submodule-config.c')
-rw-r--r--submodule-config.c31
1 files 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,