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>maint
parent
514dea905a
commit
0918e25077
|
@ -376,7 +376,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
|
||||||
{
|
{
|
||||||
struct strbuf rev = STRBUF_INIT;
|
struct strbuf rev = STRBUF_INIT;
|
||||||
unsigned long config_size;
|
unsigned long config_size;
|
||||||
char *config;
|
char *config = NULL;
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
const struct submodule *submodule = NULL;
|
const struct submodule *submodule = NULL;
|
||||||
|
@ -397,10 +397,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,
|
||||||
return entry->config;
|
return entry->config;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gitmodule_sha1_from_commit(commit_sha1, sha1, &rev)) {
|
if (!gitmodule_sha1_from_commit(commit_sha1, sha1, &rev))
|
||||||
strbuf_release(&rev);
|
goto out;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (lookup_type) {
|
switch (lookup_type) {
|
||||||
case lookup_name:
|
case lookup_name:
|
||||||
|
@ -410,22 +408,12 @@ static const struct submodule *config_from(struct submodule_cache *cache,
|
||||||
submodule = cache_lookup_path(cache, sha1, key);
|
submodule = cache_lookup_path(cache, sha1, key);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (submodule) {
|
if (submodule)
|
||||||
strbuf_release(&rev);
|
goto out;
|
||||||
return submodule;
|
|
||||||
}
|
|
||||||
|
|
||||||
config = read_sha1_file(sha1, &type, &config_size);
|
config = read_sha1_file(sha1, &type, &config_size);
|
||||||
if (!config) {
|
if (!config || type != OBJ_BLOB)
|
||||||
strbuf_release(&rev);
|
goto out;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type != OBJ_BLOB) {
|
|
||||||
strbuf_release(&rev);
|
|
||||||
free(config);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* fill the submodule config into the cache */
|
/* fill the submodule config into the cache */
|
||||||
parameter.cache = cache;
|
parameter.cache = cache;
|
||||||
|
@ -445,6 +433,11 @@ static const struct submodule *config_from(struct submodule_cache *cache,
|
||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
strbuf_release(&rev);
|
||||||
|
free(config);
|
||||||
|
return submodule;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct submodule *config_from_path(struct submodule_cache *cache,
|
static const struct submodule *config_from_path(struct submodule_cache *cache,
|
||||||
|
|
Loading…
Reference in New Issue