submodule-config: passing name reference for .gitmodule blobs
Commit 959b5455 (submodule: implement a config API for lookup of .gitmodules values, 2015-08-18) implemented the initial version of the submodule config cache. During development of that initial version we extracted the function gitmodule_sha1_from_commit(). During that process we missed that the strbuf rev was still used in config_from() and now is left empty. Lets fix this by also returning this string. This means that now when reading .gitmodules from revisions, the error messages also contain a reference to the blob they are from. 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
514dea905a3c72c8f7268347793f2947efd547be
2 files changed
+28
-9
submodule-config.c
+17
-9
@@ -349,9 +349,9 @@ static int parse_config(const char *var, const char *value, void *data)
349
}
350
351
static int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
352
- unsigned char *gitmodules_sha1)
352
+ unsigned char *gitmodules_sha1,
353
+ struct strbuf *rev)
354
{
354
- struct strbuf rev = STRBUF_INIT;
355
int ret = 0;
356
357
if (is_null_sha1(commit_sha1)) {
@@ -359,11 +359,10 @@ static int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
359
return 1;
360
}
361
362
- strbuf_addf(&rev, "%s:.gitmodules", sha1_to_hex(commit_sha1));
363
- if (get_sha1(rev.buf, gitmodules_sha1) >= 0)
362
+ strbuf_addf(rev, "%s:.gitmodules", sha1_to_hex(commit_sha1));
363
+ if (get_sha1(rev->buf, gitmodules_sha1) >= 0)
364
ret = 1;
365
366
- strbuf_release(&rev);
366
return ret;
367
}
368
@@ -375,6 +374,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
374
const unsigned char *commit_sha1, const char *key,
375
enum lookup_type lookup_type)
376
{
377
+ struct strbuf rev = STRBUF_INIT;
378
unsigned long config_size;
379
char *config;
380
unsigned char sha1[20];
@@ -397,8 +397,10 @@ 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))
400
+ if (!gitmodule_sha1_from_commit(commit_sha1, sha1, &rev)) {
401
+ strbuf_release(&rev);
402
return NULL;
403
+ }
404
405
switch (lookup_type) {
406
case lookup_name:
@@ -408,14 +410,19 @@ static const struct submodule *config_from(struct submodule_cache *cache,
410
submodule = cache_lookup_path(cache, sha1, key);
411
break;
412
}
411
- if (submodule)
413
+ if (submodule) {
414
+ strbuf_release(&rev);
415
return submodule;
416
+ }
417
418
config = read_sha1_file(sha1, &type, &config_size);
415
- if (!config)
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
}
@@ -425,8 +432,9 @@ static const struct submodule *config_from(struct submodule_cache *cache,
432
parameter.commit_sha1 = commit_sha1;
433
parameter.gitmodules_sha1 = sha1;
434
parameter.overwrite = 0;
428
- git_config_from_mem(parse_config, "submodule-blob", "",
435
+ git_config_from_mem(parse_config, "submodule-blob", rev.buf,
436
config, config_size, ¶meter);
437
+ strbuf_release(&rev);
438
free(config);
439
440
switch (lookup_type) {
t/t7411-submodule-config.sh
+11
@@ -82,6 +82,17 @@ test_expect_success 'error in one submodule config lets continue' '
82
)
83
'
84
85
+test_expect_success 'error message contains blob reference' '
86
+ (cd super &&
87
+ sha1=$(git rev-parse HEAD) &&
88
+ test-submodule-config \
89
+ HEAD b \
90
+ HEAD submodule \
91
+ 2>actual_err &&
92
+ grep "submodule-blob $sha1:.gitmodules" actual_err >/dev/null
93
+ )
94
+'
95
+
96
cat >super/expect_url <<EOF
97
Submodule url: 'git@somewhere.else.net:a.git' for path 'b'
98
Submodule url: 'git@somewhere.else.net:submodule.git' for path 'submodule'