summaryrefslogtreecommitdiff
path: root/submodule-config.c
diff options
context:
space:
mode:
authorHeiko Voigt <hvoigt@hvoigt.net>2016-07-28 12:49:11 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-07-28 20:05:14 (GMT)
commit514dea905a3c72c8f7268347793f2947efd547be (patch)
tree8d4e54782d8bdfa4eece467e5b7a4112b0a9a560 /submodule-config.c
parent508a285ceab4523412546a92cd9444f8e78065e1 (diff)
downloadgit-514dea905a3c72c8f7268347793f2947efd547be.zip
git-514dea905a3c72c8f7268347793f2947efd547be.tar.gz
git-514dea905a3c72c8f7268347793f2947efd547be.tar.bz2
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>
Diffstat (limited to 'submodule-config.c')
-rw-r--r--submodule-config.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/submodule-config.c b/submodule-config.c
index 1210b26..853989e 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -349,9 +349,9 @@ static int parse_config(const char *var, const char *value, void *data)
}
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;
if (is_null_sha1(commit_sha1)) {
@@ -359,11 +359,10 @@ static int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
return 1;
}
- strbuf_addf(&rev, "%s:.gitmodules", sha1_to_hex(commit_sha1));
- if (get_sha1(rev.buf, gitmodules_sha1) >= 0)
+ strbuf_addf(rev, "%s:.gitmodules", sha1_to_hex(commit_sha1));
+ if (get_sha1(rev->buf, gitmodules_sha1) >= 0)
ret = 1;
- strbuf_release(&rev);
return ret;
}
@@ -375,6 +374,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
const unsigned char *commit_sha1, const char *key,
enum lookup_type lookup_type)
{
+ struct strbuf rev = STRBUF_INIT;
unsigned long config_size;
char *config;
unsigned char sha1[20];
@@ -397,8 +397,10 @@ static const struct submodule *config_from(struct submodule_cache *cache,
return entry->config;
}
- if (!gitmodule_sha1_from_commit(commit_sha1, sha1))
+ if (!gitmodule_sha1_from_commit(commit_sha1, sha1, &rev)) {
+ strbuf_release(&rev);
return NULL;
+ }
switch (lookup_type) {
case lookup_name:
@@ -408,14 +410,19 @@ static const struct submodule *config_from(struct submodule_cache *cache,
submodule = cache_lookup_path(cache, sha1, key);
break;
}
- if (submodule)
+ if (submodule) {
+ strbuf_release(&rev);
return submodule;
+ }
config = read_sha1_file(sha1, &type, &config_size);
- if (!config)
+ if (!config) {
+ strbuf_release(&rev);
return NULL;
+ }
if (type != OBJ_BLOB) {
+ strbuf_release(&rev);
free(config);
return NULL;
}
@@ -425,8 +432,9 @@ static const struct submodule *config_from(struct submodule_cache *cache,
parameter.commit_sha1 = commit_sha1;
parameter.gitmodules_sha1 = sha1;
parameter.overwrite = 0;
- git_config_from_mem(parse_config, "submodule-blob", "",
+ git_config_from_mem(parse_config, "submodule-blob", rev.buf,
config, config_size, &parameter);
+ strbuf_release(&rev);
free(config);
switch (lookup_type) {