Merge branch 'rs/submodule-config-code-cleanup' into maint
Code cleanup. * rs/submodule-config-code-cleanup: submodule-config: fix test binary crashing when no arguments given submodule-config: combine early return code into one goto submodule-config: passing name reference for .gitmodule blobs submodule-config: use explicit empty string instead of strbuf in config_from()
This commit is contained in:
commit
f7b01d3eb7
@ -362,9 +362,9 @@ static int parse_config(const char *var, const char *value, void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
|
static int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
|
||||||
unsigned char *gitmodules_sha1)
|
unsigned char *gitmodules_sha1,
|
||||||
|
struct strbuf *rev)
|
||||||
{
|
{
|
||||||
struct strbuf rev = STRBUF_INIT;
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (is_null_sha1(commit_sha1)) {
|
if (is_null_sha1(commit_sha1)) {
|
||||||
@ -372,11 +372,10 @@ static int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strbuf_addf(&rev, "%s:.gitmodules", sha1_to_hex(commit_sha1));
|
strbuf_addf(rev, "%s:.gitmodules", sha1_to_hex(commit_sha1));
|
||||||
if (get_sha1(rev.buf, gitmodules_sha1) >= 0)
|
if (get_sha1(rev->buf, gitmodules_sha1) >= 0)
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
strbuf_release(&rev);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,7 +389,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;
|
||||||
@ -411,8 +410,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))
|
if (!gitmodule_sha1_from_commit(commit_sha1, sha1, &rev))
|
||||||
return NULL;
|
goto out;
|
||||||
|
|
||||||
switch (lookup_type) {
|
switch (lookup_type) {
|
||||||
case lookup_name:
|
case lookup_name:
|
||||||
@ -423,16 +422,11 @@ static const struct submodule *config_from(struct submodule_cache *cache,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (submodule)
|
if (submodule)
|
||||||
return submodule;
|
goto out;
|
||||||
|
|
||||||
config = read_sha1_file(sha1, &type, &config_size);
|
config = read_sha1_file(sha1, &type, &config_size);
|
||||||
if (!config)
|
if (!config || type != OBJ_BLOB)
|
||||||
return NULL;
|
goto out;
|
||||||
|
|
||||||
if (type != OBJ_BLOB) {
|
|
||||||
free(config);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* fill the submodule config into the cache */
|
/* fill the submodule config into the cache */
|
||||||
parameter.cache = cache;
|
parameter.cache = cache;
|
||||||
@ -441,6 +435,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
|
|||||||
parameter.overwrite = 0;
|
parameter.overwrite = 0;
|
||||||
git_config_from_mem(parse_config, "submodule-blob", rev.buf,
|
git_config_from_mem(parse_config, "submodule-blob", rev.buf,
|
||||||
config, config_size, ¶meter);
|
config, config_size, ¶meter);
|
||||||
|
strbuf_release(&rev);
|
||||||
free(config);
|
free(config);
|
||||||
|
|
||||||
switch (lookup_type) {
|
switch (lookup_type) {
|
||||||
@ -451,6 +446,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,
|
||||||
|
@ -23,7 +23,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
arg++;
|
arg++;
|
||||||
my_argc--;
|
my_argc--;
|
||||||
while (starts_with(arg[0], "--")) {
|
while (arg[0] && starts_with(arg[0], "--")) {
|
||||||
if (!strcmp(arg[0], "--url"))
|
if (!strcmp(arg[0], "--url"))
|
||||||
output_url = 1;
|
output_url = 1;
|
||||||
if (!strcmp(arg[0], "--name"))
|
if (!strcmp(arg[0], "--name"))
|
||||||
|
@ -82,6 +82,17 @@ test_expect_success 'error in one submodule config lets continue' '
|
|||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'error message contains blob reference' '
|
||||||
|
(cd super &&
|
||||||
|
sha1=$(git rev-parse HEAD) &&
|
||||||
|
test-submodule-config \
|
||||||
|
HEAD b \
|
||||||
|
HEAD submodule \
|
||||||
|
2>actual_err &&
|
||||||
|
grep "submodule-blob $sha1:.gitmodules" actual_err >/dev/null
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
cat >super/expect_url <<EOF
|
cat >super/expect_url <<EOF
|
||||||
Submodule url: 'git@somewhere.else.net:a.git' for path 'b'
|
Submodule url: 'git@somewhere.else.net:a.git' for path 'b'
|
||||||
Submodule url: 'git@somewhere.else.net:submodule.git' for path 'submodule'
|
Submodule url: 'git@somewhere.else.net:submodule.git' for path 'submodule'
|
||||||
|
Loading…
Reference in New Issue
Block a user