Skip to content

Commit 514dea9

Browse files
hvoigtgitster
authored andcommitted
submodule-config: passing name reference for .gitmodule blobs
Commit 959b545 (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 <[email protected]> Reviewed-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 508a285 commit 514dea9

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

submodule-config.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,21 +349,20 @@ static int parse_config(const char *var, const char *value, void *data)
349349
}
350350

351351
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)
353354
{
354-
struct strbuf rev = STRBUF_INIT;
355355
int ret = 0;
356356

357357
if (is_null_sha1(commit_sha1)) {
358358
hashcpy(gitmodules_sha1, null_sha1);
359359
return 1;
360360
}
361361

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)
364364
ret = 1;
365365

366-
strbuf_release(&rev);
367366
return ret;
368367
}
369368

@@ -375,6 +374,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
375374
const unsigned char *commit_sha1, const char *key,
376375
enum lookup_type lookup_type)
377376
{
377+
struct strbuf rev = STRBUF_INIT;
378378
unsigned long config_size;
379379
char *config;
380380
unsigned char sha1[20];
@@ -397,8 +397,10 @@ 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))
400+
if (!gitmodule_sha1_from_commit(commit_sha1, sha1, &rev)) {
401+
strbuf_release(&rev);
401402
return NULL;
403+
}
402404

403405
switch (lookup_type) {
404406
case lookup_name:
@@ -408,14 +410,19 @@ static const struct submodule *config_from(struct submodule_cache *cache,
408410
submodule = cache_lookup_path(cache, sha1, key);
409411
break;
410412
}
411-
if (submodule)
413+
if (submodule) {
414+
strbuf_release(&rev);
412415
return submodule;
416+
}
413417

414418
config = read_sha1_file(sha1, &type, &config_size);
415-
if (!config)
419+
if (!config) {
420+
strbuf_release(&rev);
416421
return NULL;
422+
}
417423

418424
if (type != OBJ_BLOB) {
425+
strbuf_release(&rev);
419426
free(config);
420427
return NULL;
421428
}
@@ -425,8 +432,9 @@ static const struct submodule *config_from(struct submodule_cache *cache,
425432
parameter.commit_sha1 = commit_sha1;
426433
parameter.gitmodules_sha1 = sha1;
427434
parameter.overwrite = 0;
428-
git_config_from_mem(parse_config, "submodule-blob", "",
435+
git_config_from_mem(parse_config, "submodule-blob", rev.buf,
429436
config, config_size, &parameter);
437+
strbuf_release(&rev);
430438
free(config);
431439

432440
switch (lookup_type) {

t/t7411-submodule-config.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ test_expect_success 'error in one submodule config lets continue' '
8282
)
8383
'
8484

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+
8596
cat >super/expect_url <<EOF
8697
Submodule url: '[email protected]:a.git' for path 'b'
8798
Submodule url: '[email protected]:submodule.git' for path 'submodule'

0 commit comments

Comments
 (0)