summaryrefslogtreecommitdiff
path: root/tests/status/worktree.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-04-28 16:39:53 -0700
committerRussell Belfer <rb@github.com>2014-05-02 09:21:33 -0700
commitcd424ad5518c7cfbba10a764d7bc097377ec3995 (patch)
tree1550287498b398515c12cc24c5f974d8ba2dcc45 /tests/status/worktree.c
parent94fb4aadc80c927a59696dc01db03f3a0629dae7 (diff)
downloadlibgit2-cd424ad5518c7cfbba10a764d7bc097377ec3995.tar.gz
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/status/worktree.c')
-rw-r--r--tests/status/worktree.c91
1 files changed, 84 insertions, 7 deletions
diff --git a/tests/status/worktree.c b/tests/status/worktree.c
index f51c61864..0b94fb1a0 100644
--- a/tests/status/worktree.c
+++ b/tests/status/worktree.c
@@ -5,6 +5,36 @@
#include "posix.h"
#include "util.h"
#include "path.h"
+#include <git2/trace.h>
+
+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_status_worktree__initialize(void)
+{
+ memset(&g_diff_perf, 0, sizeof(g_diff_perf));
+ cl_git_pass(git_trace_set(GIT_TRACE_TRACE, add_stats));
+}
/**
* Cleanup
@@ -15,6 +45,7 @@
void test_status_worktree__cleanup(void)
{
cl_git_sandbox_cleanup();
+ cl_git_pass(git_trace_set(0, NULL));
}
/**
@@ -40,11 +71,15 @@ void test_status_worktree__whole_repository(void)
cl_assert_equal_i(0, counts.wrong_sorted_path);
}
-void assert_show(const int entry_counts, const char *entry_paths[],
- const unsigned int entry_statuses[], git_status_show_t show)
+void assert_show(
+ const int entry_counts,
+ const char *entry_paths[],
+ const unsigned int entry_statuses[],
+ git_repository *repo,
+ git_status_show_t show,
+ unsigned int extra_flags)
{
status_entry_counts counts;
- git_repository *repo = cl_git_sandbox_init("status");
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
memset(&counts, 0x0, sizeof(status_entry_counts));
@@ -52,7 +87,7 @@ void assert_show(const int entry_counts, const char *entry_paths[],
counts.expected_paths = entry_paths;
counts.expected_statuses = entry_statuses;
- opts.flags = GIT_STATUS_OPT_DEFAULTS;
+ opts.flags = GIT_STATUS_OPT_DEFAULTS | extra_flags;
opts.show = show;
cl_git_pass(
@@ -67,19 +102,19 @@ void assert_show(const int entry_counts, const char *entry_paths[],
void test_status_worktree__show_index_and_workdir(void)
{
assert_show(entry_count0, entry_paths0, entry_statuses0,
- GIT_STATUS_SHOW_INDEX_AND_WORKDIR);
+ cl_git_sandbox_init("status"), GIT_STATUS_SHOW_INDEX_AND_WORKDIR, 0);
}
void test_status_worktree__show_index_only(void)
{
assert_show(entry_count5, entry_paths5, entry_statuses5,
- GIT_STATUS_SHOW_INDEX_ONLY);
+ cl_git_sandbox_init("status"), GIT_STATUS_SHOW_INDEX_ONLY, 0);
}
void test_status_worktree__show_workdir_only(void)
{
assert_show(entry_count6, entry_paths6, entry_statuses6,
- GIT_STATUS_SHOW_WORKDIR_ONLY);
+ cl_git_sandbox_init("status"), GIT_STATUS_SHOW_WORKDIR_ONLY, 0);
}
/* this test is equivalent to t18-status.c:statuscb1 */
@@ -877,3 +912,45 @@ void test_status_worktree__long_filenames(void)
cl_assert_equal_i(0, counts.wrong_sorted_path);
}
+/* The update stat cache tests mostly just mirror other tests and try
+ * to make sure that updating the stat cache doesn't change the results
+ * while reducing the amount of work that needs to be done
+ */
+
+void test_status_worktree__update_stat_cache_0(void)
+{
+ git_repository *repo = cl_git_sandbox_init("status");
+
+ assert_show(entry_count0, entry_paths0, entry_statuses0,
+ repo, GIT_STATUS_SHOW_INDEX_AND_WORKDIR, 0);
+
+#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);
+
+ memset(&g_diff_perf, 0, sizeof(g_diff_perf));
+#endif
+
+ assert_show(entry_count0, entry_paths0, entry_statuses0,
+ repo, GIT_STATUS_SHOW_INDEX_AND_WORKDIR, GIT_STATUS_OPT_UPDATE_INDEX);
+
+#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);
+
+ memset(&g_diff_perf, 0, sizeof(g_diff_perf));
+#endif
+
+ assert_show(entry_count0, entry_paths0, entry_statuses0,
+ repo, GIT_STATUS_SHOW_INDEX_AND_WORKDIR, 0);
+
+#ifdef GIT_TRACE
+ cl_assert_equal_sz(13 + 3, g_diff_perf.stat_calls);
+ cl_assert_equal_sz(0, g_diff_perf.oid_calcs);
+ cl_assert_equal_sz(1, g_diff_perf.submodule_lookups);
+
+ memset(&g_diff_perf, 0, sizeof(g_diff_perf));
+#endif
+}