diff options
author | Heiko Voigt <hvoigt@hvoigt.net> | 2015-08-17 17:21:57 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-08-19 11:43:09 -0700 |
commit | 959b5455d07c7724eea9d323ca8ce6bb6ddde40e (patch) | |
tree | 350f36dc7efc567179c6fd8970039d13a1d78309 /submodule-config.h | |
parent | f86f31ab33c3406adebbb9f9f61be550dcc5a472 (diff) | |
download | git-959b5455d07c7724eea9d323ca8ce6bb6ddde40e.tar.gz |
submodule: implement a config API for lookup of .gitmodules values
In a superproject some commands need to interact with submodules. They
need to query values from the .gitmodules file either from the worktree
of from certain revisions. At the moment this is quite hard since a
caller would need to read the .gitmodules file from the history and then
parse the values. We want to provide an API for this so we have one
place to get values from .gitmodules from any revision (including the
worktree).
The API is realized as a cache which allows us to lazily read
.gitmodules configurations by commit into a runtime cache which can then
be used to easily lookup values from it. Currently only the values for
path or name are stored but it can be extended for any value needed.
It is expected that .gitmodules files do not change often between
commits. Thats why we lookup the .gitmodules sha1 from a commit and then
either lookup an already parsed configuration or parse and cache an
unknown one for each sha1. The cache is lazily build on demand for each
requested commit.
This cache can be used for all purposes which need knowledge about
submodule configurations. Example use cases are:
* Recursive submodule checkout needs to lookup a submodule name from
its path when a submodule first appears. This needs be done before
this configuration exists in the worktree.
* The implementation of submodule support for 'git archive' needs to
lookup the submodule name to generate the archive when given a
revision that is not checked out.
* 'git fetch' when given the --recurse-submodules=on-demand option (or
configuration) needs to lookup submodule names by path from the
database rather than reading from the worktree. For new submodule it
needs to lookup the name from its path to allow cloning new
submodules into the .git folder so they can be checked out without
any network interaction when the user does a checkout of that
revision.
Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'submodule-config.h')
-rw-r--r-- | submodule-config.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/submodule-config.h b/submodule-config.h new file mode 100644 index 0000000000..cd68030e58 --- /dev/null +++ b/submodule-config.h @@ -0,0 +1,27 @@ +#ifndef SUBMODULE_CONFIG_CACHE_H +#define SUBMODULE_CONFIG_CACHE_H + +#include "hashmap.h" +#include "strbuf.h" + +/* + * Submodule entry containing the information about a certain submodule + * in a certain revision. + */ +struct submodule { + const char *path; + const char *name; + const char *url; + int fetch_recurse; + const char *ignore; + /* the sha1 blob id of the responsible .gitmodules file */ + unsigned char gitmodules_sha1[20]; +}; + +const struct submodule *submodule_from_name(const unsigned char *commit_sha1, + const char *name); +const struct submodule *submodule_from_path(const unsigned char *commit_sha1, + const char *path); +void submodule_free(void); + +#endif /* SUBMODULE_CONFIG_H */ |