diff options
| author | Brock Peabody <bpeabody@twosigma.com> | 2016-11-23 18:32:48 -0500 |
|---|---|---|
| committer | David Turner <dturner@twosigma.com> | 2017-01-20 17:33:56 -0500 |
| commit | 4d99c4cfc604bb141fd4e1423e934ebd3fb7e2a7 (patch) | |
| tree | 7fa6287b0ecfb6873dfd74eaf819cff1cf396bc2 /include/git2/sys | |
| parent | ca05857e71f8d11582b1ad82f63c6a61e96fe20e (diff) | |
| download | libgit2-4d99c4cfc604bb141fd4e1423e934ebd3fb7e2a7.tar.gz | |
Allow for caching of submodules.
Added `git_repository_submodule_cache_all` to initialze a cache of
submodules on the repository so that operations looking up N
submodules are O(N) and not O(N^2). Added a
`git_repository_submodule_cache_clear` function to remove the cache.
Also optimized the function that loads all submodules as it was itself
O(N^2) w.r.t the number of submodules, having to loop through the
`.gitmodules` file once per submodule. I changed it to process the
`.gitmodules` file once, into a map.
Signed-off-by: David Turner <dturner@twosigma.com>
Diffstat (limited to 'include/git2/sys')
| -rw-r--r-- | include/git2/sys/repository.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/include/git2/sys/repository.h b/include/git2/sys/repository.h index 800396c86..0c9142143 100644 --- a/include/git2/sys/repository.h +++ b/include/git2/sys/repository.h @@ -135,6 +135,35 @@ GIT_EXTERN(void) git_repository_set_index(git_repository *repo, git_index *index */ GIT_EXTERN(int) git_repository_set_bare(git_repository *repo); +/** + * Load and cache all submodules. + * + * Because the `.gitmodules` file is unstructured, loading submodules is an + * O(N) operation. Any operation (such as `git_rebase_init`) that requires + * accessing all submodules is O(N^2) in the number of submodules, if it + * has to look each one up individually. This function loads all submodules + * and caches them so that subsequent calls to `git_submodule_lookup` are O(1). + * + * @param repo the repository whose submodules will be cached. + */ +GIT_EXTERN(int) git_repository_submodule_cache_all( + git_repository *repo); + +/** + * Clear the submodule cache. + * + * Clear the submodule cache populated by `git_repository_submodule_cache_all`. + * If there is no cache, do nothing. + * + * The cache incorporates data from the repository's configuration, as well + * as the state of the working tree, the index, and HEAD. So any time any + * of these has changed, the cache might become invalid. + * + * @param repo the repository whose submodule cache will be cleared + */ +GIT_EXTERN(int) git_repository_submodule_cache_clear( + git_repository *repo); + /** @} */ GIT_END_DECL #endif |
