summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2015-10-14 19:31:54 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2015-11-04 17:11:17 -0800
commitaef97245450bbe11debc5335bb9d3abc4e0d9479 (patch)
tree2546f88cce38301687a273bfeba86ff73d9d49eb
parent18ff20f885928cc2d092f6e91dc7b4ab75775595 (diff)
downloadlibgit2-aef97245450bbe11debc5335bb9d3abc4e0d9479.tar.gz
odb: Prioritize alternate backends
For most real use cases, repositories with alternates use them as main object storage. Checking the alternate for objects before the main repository should result in measurable speedups. Because of this, we're changing the sorting algorithm to prioritize alternates *in cases where two backends have the same priority*. This means that the pack backend for the alternate will be checked before the pack backend for the main repository *but* both of them will be checked before any loose backends.
-rw-r--r--src/odb.c12
-rw-r--r--tests/odb/sorting.c16
2 files changed, 16 insertions, 12 deletions
diff --git a/src/odb.c b/src/odb.c
index 2ed35749b..805d2c333 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -374,10 +374,14 @@ static int backend_sort_cmp(const void *a, const void *b)
const backend_internal *backend_a = (const backend_internal *)(a);
const backend_internal *backend_b = (const backend_internal *)(b);
- if (backend_a->is_alternate == backend_b->is_alternate)
- return (backend_b->priority - backend_a->priority);
-
- return backend_a->is_alternate ? 1 : -1;
+ if (backend_b->priority == backend_a->priority) {
+ if (backend_a->is_alternate)
+ return -1;
+ if (backend_b->is_alternate)
+ return 1;
+ return 0;
+ }
+ return (backend_b->priority - backend_a->priority);
}
int git_odb_new(git_odb **out)
diff --git a/tests/odb/sorting.c b/tests/odb/sorting.c
index 147a160c8..22d057b3b 100644
--- a/tests/odb/sorting.c
+++ b/tests/odb/sorting.c
@@ -56,14 +56,14 @@ void test_odb_sorting__basic_backends_sorting(void)
void test_odb_sorting__alternate_backends_sorting(void)
{
- cl_git_pass(git_odb_add_backend(_odb, new_backend(0), 5));
- cl_git_pass(git_odb_add_backend(_odb, new_backend(2), 3));
- cl_git_pass(git_odb_add_backend(_odb, new_backend(1), 4));
- cl_git_pass(git_odb_add_backend(_odb, new_backend(3), 1));
- cl_git_pass(git_odb_add_alternate(_odb, new_backend(4), 5));
- cl_git_pass(git_odb_add_alternate(_odb, new_backend(6), 3));
- cl_git_pass(git_odb_add_alternate(_odb, new_backend(5), 4));
- cl_git_pass(git_odb_add_alternate(_odb, new_backend(7), 1));
+ cl_git_pass(git_odb_add_backend(_odb, new_backend(1), 5));
+ cl_git_pass(git_odb_add_backend(_odb, new_backend(5), 3));
+ cl_git_pass(git_odb_add_backend(_odb, new_backend(3), 4));
+ cl_git_pass(git_odb_add_backend(_odb, new_backend(7), 1));
+ cl_git_pass(git_odb_add_alternate(_odb, new_backend(0), 5));
+ cl_git_pass(git_odb_add_alternate(_odb, new_backend(4), 3));
+ cl_git_pass(git_odb_add_alternate(_odb, new_backend(2), 4));
+ cl_git_pass(git_odb_add_alternate(_odb, new_backend(6), 1));
check_backend_sorting(_odb);
}