diff options
-rw-r--r-- | include/git2/sys/diff.h | 12 | ||||
-rw-r--r-- | src/diff_driver.c | 34 | ||||
-rw-r--r-- | tests/diff/drivers.c | 9 |
3 files changed, 51 insertions, 4 deletions
diff --git a/include/git2/sys/diff.h b/include/git2/sys/diff.h index 034d5c478..f54bd2e77 100644 --- a/include/git2/sys/diff.h +++ b/include/git2/sys/diff.h @@ -89,6 +89,18 @@ GIT_EXTERN(int) git_diff_get_perfdata( GIT_EXTERN(int) git_status_list_get_perfdata( git_diff_perfdata *out, const git_status_list *status); +/** + * Compile all builtin diff drivers. + * + * Normally builtin diff drivers are only compiled on-demand when they are + * used. This function loops through the internal table and compiles and + * caches all of the builtin diff drivers. This can be done for testing + * purposes or to control when the driver compilation costs are paid. + * + * @return 0 for success, <0 for error + */ +GIT_EXTERN(int) git_diff_driver_compile_builtins(git_repository *repo); + /** @} */ GIT_END_DECL #endif diff --git a/src/diff_driver.c b/src/diff_driver.c index c3c5f365b..9ae72ac6c 100644 --- a/src/diff_driver.c +++ b/src/diff_driver.c @@ -203,11 +203,11 @@ static int git_diff_driver_builtin( error = 0; done: - if (error && drv) + if (error && drv) { git_diff_driver_free(drv); - else - *out = drv; - + drv = NULL; + } + *out = drv; return error; } @@ -335,6 +335,32 @@ done: return error; } +int git_diff_driver_compile_builtins(git_repository *repo) +{ + int error = 0; + git_diff_driver_registry *reg; + git_diff_driver *drv; + size_t i; + + assert(repo); + + if ((reg = git_repository_driver_registry(repo)) == NULL) + return -1; + + for (i = 0; i < ARRAY_SIZE(builtin_defs); ++i) { + const char *name = builtin_defs[i].name; + khiter_t pos = git_strmap_lookup_index(reg->drivers, name); + + if (!git_strmap_valid_index(reg->drivers, pos) && + (error = git_diff_driver_builtin(&drv, reg, name)) < 0) + break; + + fprintf(stderr, "compiled diff driver '%s'\n", name); + } + + return error; +} + int git_diff_driver_lookup( git_diff_driver **out, git_repository *repo, const char *path) { diff --git a/tests/diff/drivers.c b/tests/diff/drivers.c index 8b12368ea..6a54e1428 100644 --- a/tests/diff/drivers.c +++ b/tests/diff/drivers.c @@ -250,3 +250,12 @@ void test_diff_drivers__builtins(void) git_buf_free(&expected); git_vector_free(&files); } + +#include "git2/sys/diff.h" + +void test_diff_drivers__check_builtins(void) +{ + g_repo = cl_git_sandbox_init("empty_standard_repo"); + cl_git_pass(git_diff_driver_compile_builtins(g_repo)); +} + |