summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/diff/diff_helpers.c19
-rw-r--r--tests/diff/diff_helpers.h14
-rw-r--r--tests/diff/workdir.c60
-rw-r--r--tests/status/worktree.c75
-rw-r--r--tests/trace/trace.c39
5 files changed, 73 insertions, 134 deletions
diff --git a/tests/diff/diff_helpers.c b/tests/diff/diff_helpers.c
index 5de9834ba..279cb20c5 100644
--- a/tests/diff/diff_helpers.c
+++ b/tests/diff/diff_helpers.c
@@ -229,22 +229,3 @@ void diff_print_raw(FILE *fp, git_diff *diff)
git_diff_print(diff, GIT_DIFF_FORMAT_RAW,
git_diff_print_callback__to_file_handle, fp ? fp : stderr));
}
-
-void diff_perf_track_stats(
- git_trace_level_t level,
- void *cb_payload,
- void *msg_payload,
- const char *msg)
-{
- diff_perf *data = cb_payload;
-
- if (!(level & GIT_TRACE_PERF))
- return;
-
- if (!strcmp("stat", msg))
- data->stat_calls += msg_payload ? *((size_t *)msg_payload) : 1;
- else if (!strcmp("submodule_lookup", msg))
- data->submodule_lookups++;
- else if (!strcmp("oid_calculation", msg))
- data->oid_calcs++;
-}
diff --git a/tests/diff/diff_helpers.h b/tests/diff/diff_helpers.h
index 3ed538702..bf21f4b1f 100644
--- a/tests/diff/diff_helpers.h
+++ b/tests/diff/diff_helpers.h
@@ -62,17 +62,3 @@ extern int diff_foreach_via_iterator(
extern void diff_print(FILE *fp, git_diff *diff);
extern void diff_print_raw(FILE *fp, git_diff *diff);
-
-#include "git2/trace.h"
-
-typedef struct {
- size_t stat_calls;
- size_t oid_calcs;
- size_t submodule_lookups;
-} diff_perf;
-
-extern void diff_perf_track_stats(
- git_trace_level_t level,
- void *cb_payload,
- void *msg_payload,
- const char *msg);
diff --git a/tests/diff/workdir.c b/tests/diff/workdir.c
index 952c9022b..a6d48abc6 100644
--- a/tests/diff/workdir.c
+++ b/tests/diff/workdir.c
@@ -1,28 +1,13 @@
#include "clar_libgit2.h"
#include "diff_helpers.h"
#include "repository.h"
+#include "git2/sys/diff.h"
static git_repository *g_repo = NULL;
-#ifdef GIT_TRACE
-static diff_perf g_diff_perf;
-#endif
-
-void test_diff_workdir__initialize(void)
-{
-#ifdef GIT_TRACE
- memset(&g_diff_perf, 0, sizeof(g_diff_perf));
- cl_git_pass(git_trace_set(
- GIT_TRACE_PERF, diff_perf_track_stats, &g_diff_perf));
-#endif
-}
-
void test_diff_workdir__cleanup(void)
{
cl_git_sandbox_cleanup();
-#ifdef GIT_TRACE
- cl_git_pass(git_trace_set(GIT_TRACE_NONE, NULL, NULL));
-#endif
}
void test_diff_workdir__to_index(void)
@@ -70,13 +55,14 @@ void test_diff_workdir__to_index(void)
cl_assert_equal_i(5, exp.line_ctxt);
cl_assert_equal_i(4, exp.line_adds);
cl_assert_equal_i(5, exp.line_dels);
+ }
-#ifdef GIT_TRACE
+ {
+ git_diff_perfdata perf = GIT_DIFF_PERFDATA_INIT;
+ cl_git_pass(git_diff_get_perfdata(&perf, diff));
cl_assert_equal_sz(
- 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
+ 13 /* in root */ + 3 /* in subdir */, perf.stat_calls);
+ cl_assert_equal_sz(5, perf.oid_calculations);
}
git_diff_free(diff);
@@ -1532,10 +1518,6 @@ static void basic_diff_status(git_diff **out, const git_diff_options *opts)
{
diff_expects exp;
-#ifdef GIT_TRACE
- memset(&g_diff_perf, 0, sizeof(g_diff_perf));
-#endif
-
cl_git_pass(git_diff_index_to_workdir(out, g_repo, NULL, opts));
memset(&exp, 0, sizeof(exp));
@@ -1555,6 +1537,7 @@ void test_diff_workdir__can_update_index(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff *diff = NULL;
+ git_diff_perfdata perf = GIT_DIFF_PERFDATA_INIT;
g_repo = cl_git_sandbox_init("status");
@@ -1569,11 +1552,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_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
+
+ cl_git_pass(git_diff_get_perfdata(&perf, diff));
+ cl_assert_equal_sz(13 + 3, perf.stat_calls);
+ cl_assert_equal_sz(5, perf.oid_calculations);
git_diff_free(diff);
@@ -1581,22 +1563,20 @@ void test_diff_workdir__can_update_index(void)
opts.flags |= GIT_DIFF_UPDATE_INDEX;
basic_diff_status(&diff, &opts);
-#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
+
+ cl_git_pass(git_diff_get_perfdata(&perf, diff));
+ cl_assert_equal_sz(13 + 3, perf.stat_calls);
+ cl_assert_equal_sz(5, perf.oid_calculations);
git_diff_free(diff);
/* now if we do it again, we should see fewer OID calculations */
basic_diff_status(&diff, &opts);
-#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
+
+ cl_git_pass(git_diff_get_perfdata(&perf, diff));
+ cl_assert_equal_sz(13 + 3, perf.stat_calls);
+ cl_assert_equal_sz(0, perf.oid_calculations);
git_diff_free(diff);
}
diff --git a/tests/status/worktree.c b/tests/status/worktree.c
index 06864ad59..ca9068aba 100644
--- a/tests/status/worktree.c
+++ b/tests/status/worktree.c
@@ -6,19 +6,7 @@
#include "util.h"
#include "path.h"
#include "../diff/diff_helpers.h"
-
-#ifdef GIT_TRACE
-static diff_perf g_diff_perf;
-#endif
-
-void test_status_worktree__initialize(void)
-{
-#ifdef GIT_TRACE
- memset(&g_diff_perf, 0, sizeof(g_diff_perf));
- cl_git_pass(git_trace_set(
- GIT_TRACE_PERF, diff_perf_track_stats, &g_diff_perf));
-#endif
-}
+#include "git2/sys/diff.h"
/**
* Cleanup
@@ -29,9 +17,6 @@ void test_status_worktree__initialize(void)
void test_status_worktree__cleanup(void)
{
cl_git_sandbox_cleanup();
-#ifdef GIT_TRACE
- cl_git_pass(git_trace_set(GIT_TRACE_NONE, NULL, NULL));
-#endif
}
/**
@@ -903,38 +888,50 @@ void test_status_worktree__long_filenames(void)
* while reducing the amount of work that needs to be done
*/
+static void check_status0(git_status_list *status)
+{
+ size_t i, max_i = git_status_list_entrycount(status);
+ cl_assert_equal_sz(entry_count0, max_i);
+ for (i = 0; i < max_i; ++i) {
+ const git_status_entry *entry = git_status_byindex(status, i);
+ cl_assert_equal_i(entry_statuses0[i], entry->status);
+ }
+}
+
void test_status_worktree__update_stat_cache_0(void)
{
git_repository *repo = cl_git_sandbox_init("status");
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ git_status_list *status;
+ git_diff_perfdata perf = GIT_DIFF_PERFDATA_INIT;
- assert_show(entry_count0, entry_paths0, entry_statuses0,
- repo, GIT_STATUS_SHOW_INDEX_AND_WORKDIR, 0);
+ opts.flags = GIT_STATUS_OPT_DEFAULTS;
-#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);
+ cl_git_pass(git_status_list_new(&status, repo, &opts));
+ check_status0(status);
+ cl_git_pass(git_status_list_get_perfdata(&perf, status));
+ cl_assert_equal_sz(13 + 3, perf.stat_calls);
+ cl_assert_equal_sz(5, perf.oid_calculations);
- memset(&g_diff_perf, 0, sizeof(g_diff_perf));
-#endif
+ git_status_list_free(status);
- assert_show(entry_count0, entry_paths0, entry_statuses0,
- repo, GIT_STATUS_SHOW_INDEX_AND_WORKDIR, GIT_STATUS_OPT_UPDATE_INDEX);
+ opts.flags |= GIT_STATUS_OPT_UPDATE_INDEX;
+
+ cl_git_pass(git_status_list_new(&status, repo, &opts));
+ check_status0(status);
+ cl_git_pass(git_status_list_get_perfdata(&perf, status));
+ cl_assert_equal_sz(13 + 3, perf.stat_calls);
+ cl_assert_equal_sz(5, perf.oid_calculations);
-#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);
+ git_status_list_free(status);
- memset(&g_diff_perf, 0, sizeof(g_diff_perf));
-#endif
+ opts.flags &= ~GIT_STATUS_OPT_UPDATE_INDEX;
- assert_show(entry_count0, entry_paths0, entry_statuses0,
- repo, GIT_STATUS_SHOW_INDEX_AND_WORKDIR, 0);
+ cl_git_pass(git_status_list_new(&status, repo, &opts));
+ check_status0(status);
+ cl_git_pass(git_status_list_get_perfdata(&perf, status));
+ cl_assert_equal_sz(13 + 3, perf.stat_calls);
+ cl_assert_equal_sz(0, perf.oid_calculations);
-#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);
-#endif
+ git_status_list_free(status);
}
diff --git a/tests/trace/trace.c b/tests/trace/trace.c
index 328539379..87b325378 100644
--- a/tests/trace/trace.c
+++ b/tests/trace/trace.c
@@ -3,49 +3,44 @@
static int written = 0;
-static void trace_callback(
- git_trace_level_t level,
- void *cb_payload,
- void *msg_payload,
- const char *msg)
+static void trace_callback(git_trace_level_t level, const char *message)
{
- GIT_UNUSED(level); GIT_UNUSED(msg_payload);
+ GIT_UNUSED(level);
- cl_assert(strcmp(msg, "Hello world!") == 0);
+ cl_assert(strcmp(message, "Hello world!") == 0);
- if (cb_payload)
- *((int *)cb_payload) = 1;
+ written = 1;
}
void test_trace_trace__initialize(void)
{
- git_trace_set(GIT_TRACE_INFO_AND_BELOW, trace_callback, &written);
+ git_trace_set(GIT_TRACE_INFO, trace_callback);
written = 0;
}
void test_trace_trace__cleanup(void)
{
- git_trace_set(GIT_TRACE_NONE, NULL, NULL);
+ git_trace_set(GIT_TRACE_NONE, NULL);
}
void test_trace_trace__sets(void)
{
#ifdef GIT_TRACE
- cl_assert(git_trace_level() == GIT_TRACE_INFO_AND_BELOW);
+ cl_assert(git_trace_level() == GIT_TRACE_INFO);
#endif
}
void test_trace_trace__can_reset(void)
{
#ifdef GIT_TRACE
- cl_assert(git_trace_level() == GIT_TRACE_INFO_AND_BELOW);
- cl_git_pass(git_trace_set(GIT_TRACE_ERROR, trace_callback, &written));
+ cl_assert(git_trace_level() == GIT_TRACE_INFO);
+ cl_git_pass(git_trace_set(GIT_TRACE_ERROR, trace_callback));
cl_assert(written == 0);
- git_trace(GIT_TRACE_INFO, NULL, "Hello %s!", "world");
+ git_trace(GIT_TRACE_INFO, "Hello %s!", "world");
cl_assert(written == 0);
- git_trace(GIT_TRACE_ERROR, NULL, "Hello %s!", "world");
+ git_trace(GIT_TRACE_ERROR, "Hello %s!", "world");
cl_assert(written == 1);
#endif
}
@@ -53,13 +48,13 @@ void test_trace_trace__can_reset(void)
void test_trace_trace__can_unset(void)
{
#ifdef GIT_TRACE
- cl_assert(git_trace_level() == GIT_TRACE_INFO_AND_BELOW);
- cl_git_pass(git_trace_set(GIT_TRACE_NONE, NULL, NULL));
+ cl_assert(git_trace_level() == GIT_TRACE_INFO);
+ cl_git_pass(git_trace_set(GIT_TRACE_NONE, NULL));
cl_assert(git_trace_level() == GIT_TRACE_NONE);
cl_assert(written == 0);
- git_trace(GIT_TRACE_FATAL, NULL, "Hello %s!", "world");
+ git_trace(GIT_TRACE_FATAL, "Hello %s!", "world");
cl_assert(written == 0);
#endif
}
@@ -68,7 +63,7 @@ void test_trace_trace__skips_higher_level(void)
{
#ifdef GIT_TRACE
cl_assert(written == 0);
- git_trace(GIT_TRACE_DEBUG, NULL, "Hello %s!", "world");
+ git_trace(GIT_TRACE_DEBUG, "Hello %s!", "world");
cl_assert(written == 0);
#endif
}
@@ -77,7 +72,7 @@ void test_trace_trace__writes(void)
{
#ifdef GIT_TRACE
cl_assert(written == 0);
- git_trace(GIT_TRACE_INFO, NULL, "Hello %s!", "world");
+ git_trace(GIT_TRACE_INFO, "Hello %s!", "world");
cl_assert(written == 1);
#endif
}
@@ -86,7 +81,7 @@ void test_trace_trace__writes_lower_level(void)
{
#ifdef GIT_TRACE
cl_assert(written == 0);
- git_trace(GIT_TRACE_ERROR, NULL, "Hello %s!", "world");
+ git_trace(GIT_TRACE_ERROR, "Hello %s!", "world");
cl_assert(written == 1);
#endif
}