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>
Heiko Voigt committed
Jul 28, 2016 at 14:49 UTC
0918e25077cb9321011a973703cc597b078f0ab5
1 file changed
+12
-19
submodule-config.c
+12
-19
@@ -376,7 +376,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
376
{
377
struct strbuf rev = STRBUF_INIT;
378
unsigned long config_size;
379
- char *config;
379
+ char *config = NULL;
380
unsigned char sha1[20];
381
enum object_type type;
382
const struct submodule *submodule = NULL;
@@ -397,10 +397,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,
397
return entry->config;
398
}
399
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;
402
403
switch (lookup_type) {
404
case lookup_name:
@@ -410,22 +408,12 @@ static const struct submodule *config_from(struct submodule_cache *cache,
408
submodule = cache_lookup_path(cache, sha1, key);
409
break;
410
}
413
- if (submodule) {
414
- strbuf_release(&rev);
415
- return submodule;
416
- }
411
+ if (submodule)
412
+ goto out;
413
414
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;
417
418
/* fill the submodule config into the cache */
419
parameter.cache = cache;
@@ -445,6 +433,11 @@ static const struct submodule *config_from(struct submodule_cache *cache,
433
default:
434
return NULL;
435
}
436
+
437
+out:
438
+ strbuf_release(&rev);
439
+ free(config);
440
+ return submodule;
441
}
442
443
static const struct submodule *config_from_path(struct submodule_cache *cache,