mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
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>
This commit is contained in:
committed by
David Turner
parent
ca05857e71
commit
4d99c4cfc6
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user