Skip to content

Commit 0918e25

Browse files
hvoigtgitster
authored andcommitted
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 <[email protected]> Reviewed-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 514dea9 commit 0918e25

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

submodule-config.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
376376
{
377377
struct strbuf rev = STRBUF_INIT;
378378
unsigned long config_size;
379-
char *config;
379+
char *config = NULL;
380380
unsigned char sha1[20];
381381
enum object_type type;
382382
const struct submodule *submodule = NULL;
@@ -397,10 +397,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,
397397
return entry->config;
398398
}
399399

400-
if (!gitmodule_sha1_from_commit(commit_sha1, sha1, &rev)) {
401-
strbuf_release(&rev);
402-
return NULL;
403-
}
400+
if (!gitmodule_sha1_from_commit(commit_sha1, sha1, &rev))
401+
goto out;
404402

405403
switch (lookup_type) {
406404
case lookup_name:
@@ -410,22 +408,12 @@ static const struct submodule *config_from(struct submodule_cache *cache,
410408
submodule = cache_lookup_path(cache, sha1, key);
411409
break;
412410
}
413-
if (submodule) {
414-
strbuf_release(&rev);
415-
return submodule;
416-
}
411+
if (submodule)
412+
goto out;
417413

418414
config = read_sha1_file(sha1, &type, &config_size);
419-
if (!config) {
420-
strbuf_release(&rev);
421-
return NULL;
422-
}
423-
424-
if (type != OBJ_BLOB) {
425-
strbuf_release(&rev);
426-
free(config);
427-
return NULL;
428-
}
415+
if (!config || type != OBJ_BLOB)
416+
goto out;
429417

430418
/* fill the submodule config into the cache */
431419
parameter.cache = cache;
@@ -445,6 +433,11 @@ static const struct submodule *config_from(struct submodule_cache *cache,
445433
default:
446434
return NULL;
447435
}
436+
437+
out:
438+
strbuf_release(&rev);
439+
free(config);
440+
return submodule;
448441
}
449442

450443
static const struct submodule *config_from_path(struct submodule_cache *cache,

0 commit comments

Comments
 (0)