From d769a3fdda81be4936a3760bd29f39935b32376a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 5 May 2015 06:03:21 +0200 Subject: [PATCH] submodule: bring back finding by path During the removal of the cache, we also removed the ability to use `_lookup()` to search by path rather than name. Bring this logic back. --- src/submodule.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/submodule.c b/src/submodule.c index c6effdef8..37d420525 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -124,6 +124,26 @@ static void submodule_set_lookup_error(int error, const char *name) "Submodule '%s' has not been added yet", name); } +typedef struct { + const char *path; + char *name; +} fbp_data; + +static int find_by_path(const git_config_entry *entry, void *payload) +{ + fbp_data *data = payload; + + if (!strcmp(entry->value, data->path)) { + const char *fdot, *ldot; + fdot = strchr(entry->name, '.'); + ldot = strrchr(entry->name, '.'); + data->name = git__strndup(fdot + 1, ldot - fdot - 1); + GITERR_CHECK_ALLOC(data->name); + } + + return 0; +} + int git_submodule_lookup( git_submodule **out, /* NULL if user only wants to test existence */ git_repository *repo, @@ -147,6 +167,28 @@ int git_submodule_lookup( return error; } + /* Didn't find it via the name, maybe it's the path */ + if (!sm->url) { + const char *pattern = "submodule\\..*\\.path"; + fbp_data data = { name, NULL }; + + if ((error = git_config_file_foreach_match(mods, pattern, find_by_path, &data)) < 0) + return error; + + if (data.name) { + git__free(sm->name); + sm->name = data.name; + sm->path = git__strdup(name); + GITERR_CHECK_ALLOC(sm->path); + + /* Try to load again with the right name */ + if ((error = git_submodule_reload(sm, false)) < 0) { + git_submodule_free(sm); + return error; + } + } + } + /* If we didn't find the url, consider it missing */ if (!sm->url) { git_submodule_free(sm); -- 2.39.5