diff options
author | Russell Belfer <rb@github.com> | 2014-04-29 03:39:53 +0400 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-05-02 20:21:33 +0400 |
commit | cd424ad5518c7cfbba10a764d7bc097377ec3995 (patch) | |
tree | 1550287498b398515c12cc24c5f974d8ba2dcc45 /tests/diff/workdir.c | |
parent | 94fb4aadc80c927a59696dc01db03f3a0629dae7 (diff) |
Add GIT_STATUS_OPT_UPDATE_INDEX and use trace API
This adds an option to refresh the stat cache while generating
status. It also rips out the GIT_PERF stuff I had an makes use
of the trace API to keep statistics about what happens during diff.
Diffstat (limited to 'tests/diff/workdir.c')
-rw-r--r-- | tests/diff/workdir.c | 66 |
1 files changed, 45 insertions, 21 deletions
diff --git a/tests/diff/workdir.c b/tests/diff/workdir.c index 9e4608e9d..a225ebc89 100644 --- a/tests/diff/workdir.c +++ b/tests/diff/workdir.c @@ -1,21 +1,43 @@ #include "clar_libgit2.h" #include "diff_helpers.h" #include "repository.h" - -#ifdef GIT_PERF -/* access to diff usage statistics */ -# include "diff.h" -#endif +#include <git2/trace.h> static git_repository *g_repo = NULL; +static struct { + size_t stat_calls; + size_t oid_calcs; + size_t submodule_lookups; +} g_diff_perf; + +static void add_stats(git_trace_level_t level, const char *msg) +{ + const char *assign = strchr(msg, '='); + + GIT_UNUSED(level); + + if (!assign) + return; + + if (!strncmp("stat", msg, (assign - msg))) + g_diff_perf.stat_calls += atoi(assign + 1); + else if (!strncmp("submodule_lookup", msg, (assign - msg))) + g_diff_perf.submodule_lookups += atoi(assign + 1); + else if (!strncmp("oid_calculation", msg, (assign - msg))) + g_diff_perf.oid_calcs += atoi(assign + 1); +} + void test_diff_workdir__initialize(void) { + memset(&g_diff_perf, 0, sizeof(g_diff_perf)); + cl_git_pass(git_trace_set(GIT_TRACE_TRACE, add_stats)); } void test_diff_workdir__cleanup(void) { cl_git_sandbox_cleanup(); + cl_git_pass(git_trace_set(0, NULL)); } void test_diff_workdir__to_index(void) @@ -64,11 +86,11 @@ void test_diff_workdir__to_index(void) cl_assert_equal_i(4, exp.line_adds); cl_assert_equal_i(5, exp.line_dels); -#ifdef GIT_PERF +#ifdef GIT_TRACE cl_assert_equal_sz( - 13 /* in root */ + 3 /* in subdir */, diff->stat_calls); - cl_assert_equal_sz(5, diff->oid_calculations); - cl_assert_equal_sz(1, diff->submodule_lookups); + 13 /* in root */ + 3 /* in subdir */, g_diff_perf.stat_calls); + cl_assert_equal_sz(5, g_diff_perf.oid_calcs); + cl_assert_equal_sz(1, g_diff_perf.submodule_lookups); #endif } @@ -1525,6 +1547,8 @@ static void basic_diff_status(git_diff **out, const git_diff_options *opts) { diff_expects exp; + memset(&g_diff_perf, 0, sizeof(g_diff_perf)); + cl_git_pass(git_diff_index_to_workdir(out, g_repo, NULL, opts)); memset(&exp, 0, sizeof(exp)); @@ -1558,10 +1582,10 @@ void test_diff_workdir__can_update_index(void) opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; basic_diff_status(&diff, &opts); -#ifdef GIT_PERF - cl_assert_equal_sz(diff->stat_calls, 13 + 3); - cl_assert_equal_sz(diff->oid_calculations, 5); - cl_assert_equal_sz(diff->submodule_lookups, 1); +#ifdef GIT_TRACE + cl_assert_equal_sz(13 + 3, g_diff_perf.stat_calls); + cl_assert_equal_sz(5, g_diff_perf.oid_calcs); + cl_assert_equal_sz(1, g_diff_perf.submodule_lookups); #endif git_diff_free(diff); @@ -1570,10 +1594,10 @@ void test_diff_workdir__can_update_index(void) opts.flags |= GIT_DIFF_UPDATE_INDEX; basic_diff_status(&diff, &opts); -#ifdef GIT_PERF - cl_assert_equal_sz(diff->stat_calls, 13 + 3); - cl_assert_equal_sz(diff->oid_calculations, 5); - cl_assert_equal_sz(diff->submodule_lookups, 1); +#ifdef GIT_TRACE + cl_assert_equal_sz(13 + 3, g_diff_perf.stat_calls); + cl_assert_equal_sz(5, g_diff_perf.oid_calcs); + cl_assert_equal_sz(1, g_diff_perf.submodule_lookups); #endif git_diff_free(diff); @@ -1581,10 +1605,10 @@ void test_diff_workdir__can_update_index(void) /* now if we do it again, we should see fewer OID calculations */ basic_diff_status(&diff, &opts); -#ifdef GIT_PERF - cl_assert_equal_sz(diff->stat_calls, 13 + 3); - cl_assert_equal_sz(diff->oid_calculations, 0); /* Yay */ - cl_assert_equal_sz(diff->submodule_lookups, 1); +#ifdef GIT_TRACE + cl_assert_equal_sz(13 + 3, g_diff_perf.stat_calls); + cl_assert_equal_sz(0, g_diff_perf.oid_calcs); /* Yay */ + cl_assert_equal_sz(1, g_diff_perf.submodule_lookups); #endif git_diff_free(diff); |