1 #include "clar_libgit2.h"
2 #include "helper__perf__do_merge.h"
3 #include "helper__perf__timer.h"
5 static git_repository
* g_repo
;
7 void perf__do_merge(const char *fixture
,
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
;
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
;
27 perf__timer__start(&t_total
);
29 checkout_opts
.checkout_strategy
= GIT_CHECKOUT_SAFE
;
30 clone_opts
.checkout_opts
= checkout_opts
;
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
);
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
,
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
);
46 cl_git_pass(git_repository_set_head(g_repo
, git_reference_name(ref_branch_a
)));
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
,
54 cl_git_pass(git_annotated_commit_lookup(&annotated_commits
[0], g_repo
, &oid_b
));
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
);
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
);
69 perf__timer__stop(&t_total
);
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
);