]> git.proxmox.com Git - libgit2.git/blob - tests/perf/helper__perf__do_merge.c
c77b46a1fe037eb53cc7320149093de804a95b5e
[libgit2.git] / tests / perf / helper__perf__do_merge.c
1 #include "clar_libgit2.h"
2 #include "helper__perf__do_merge.h"
3 #include "helper__perf__timer.h"
4
5 static git_repository * g_repo;
6
7 void perf__do_merge(const char *fixture,
8 const char *test_name,
9 const char *id_a,
10 const char *id_b)
11 {
12 git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
13 git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
14 git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
15 git_oid oid_a;
16 git_oid oid_b;
17 git_reference *ref_branch_a = NULL;
18 git_reference *ref_branch_b = NULL;
19 git_commit *commit_a = NULL;
20 git_commit *commit_b = NULL;
21 git_annotated_commit *annotated_commits[1] = { NULL };
22 perf_timer t_total = PERF_TIMER_INIT;
23 perf_timer t_clone = PERF_TIMER_INIT;
24 perf_timer t_checkout = PERF_TIMER_INIT;
25 perf_timer t_merge = PERF_TIMER_INIT;
26
27 perf__timer__start(&t_total);
28
29 checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
30 clone_opts.checkout_opts = checkout_opts;
31
32 perf__timer__start(&t_clone);
33 cl_git_pass(git_clone(&g_repo, fixture, test_name, &clone_opts));
34 perf__timer__stop(&t_clone);
35
36 git_oid_fromstr(&oid_a, id_a);
37 cl_git_pass(git_commit_lookup(&commit_a, g_repo, &oid_a));
38 cl_git_pass(git_branch_create(&ref_branch_a, g_repo,
39 "A", commit_a,
40 0));
41
42 perf__timer__start(&t_checkout);
43 cl_git_pass(git_checkout_tree(g_repo, (git_object*)commit_a, &checkout_opts));
44 perf__timer__stop(&t_checkout);
45
46 cl_git_pass(git_repository_set_head(g_repo, git_reference_name(ref_branch_a)));
47
48 git_oid_fromstr(&oid_b, id_b);
49 cl_git_pass(git_commit_lookup(&commit_b, g_repo, &oid_b));
50 cl_git_pass(git_branch_create(&ref_branch_b, g_repo,
51 "B", commit_b,
52 0));
53
54 cl_git_pass(git_annotated_commit_lookup(&annotated_commits[0], g_repo, &oid_b));
55
56 perf__timer__start(&t_merge);
57 cl_git_pass(git_merge(g_repo,
58 (const git_annotated_commit **)annotated_commits, 1,
59 &merge_opts, &checkout_opts));
60 perf__timer__stop(&t_merge);
61
62 git_reference_free(ref_branch_a);
63 git_reference_free(ref_branch_b);
64 git_commit_free(commit_a);
65 git_commit_free(commit_b);
66 git_annotated_commit_free(annotated_commits[0]);
67 git_repository_free(g_repo);
68
69 perf__timer__stop(&t_total);
70
71 perf__timer__report(&t_clone, "%s: clone", test_name);
72 perf__timer__report(&t_checkout, "%s: checkout", test_name);
73 perf__timer__report(&t_merge, "%s: merge", test_name);
74 perf__timer__report(&t_total, "%s: total", test_name);
75 }