Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a0a1b19

Browse files
committed
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.
1 parent 43820f2 commit a0a1b19

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/odb.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,14 @@ static int backend_sort_cmp(const void *a, const void *b)
374374
const backend_internal *backend_a = (const backend_internal *)(a);
375375
const backend_internal *backend_b = (const backend_internal *)(b);
376376

377-
if (backend_a->is_alternate == backend_b->is_alternate)
378-
return (backend_b->priority - backend_a->priority);
379-
380-
return backend_a->is_alternate ? 1 : -1;
377+
if (backend_b->priority == backend_a->priority) {
378+
if (backend_a->is_alternate)
379+
return -1;
380+
if (backend_b->is_alternate)
381+
return 1;
382+
return 0;
383+
}
384+
return (backend_b->priority - backend_a->priority);
381385
}
382386

383387
int git_odb_new(git_odb **out)

tests/odb/sorting.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ void test_odb_sorting__basic_backends_sorting(void)
5757

5858
void test_odb_sorting__alternate_backends_sorting(void)
5959
{
60-
cl_git_pass(git_odb_add_backend(_odb, new_backend(0), 5));
61-
cl_git_pass(git_odb_add_backend(_odb, new_backend(2), 3));
62-
cl_git_pass(git_odb_add_backend(_odb, new_backend(1), 4));
63-
cl_git_pass(git_odb_add_backend(_odb, new_backend(3), 1));
64-
cl_git_pass(git_odb_add_alternate(_odb, new_backend(4), 5));
65-
cl_git_pass(git_odb_add_alternate(_odb, new_backend(6), 3));
66-
cl_git_pass(git_odb_add_alternate(_odb, new_backend(5), 4));
67-
cl_git_pass(git_odb_add_alternate(_odb, new_backend(7), 1));
60+
cl_git_pass(git_odb_add_backend(_odb, new_backend(1), 5));
61+
cl_git_pass(git_odb_add_backend(_odb, new_backend(5), 3));
62+
cl_git_pass(git_odb_add_backend(_odb, new_backend(3), 4));
63+
cl_git_pass(git_odb_add_backend(_odb, new_backend(7), 1));
64+
cl_git_pass(git_odb_add_alternate(_odb, new_backend(0), 5));
65+
cl_git_pass(git_odb_add_alternate(_odb, new_backend(4), 3));
66+
cl_git_pass(git_odb_add_alternate(_odb, new_backend(2), 4));
67+
cl_git_pass(git_odb_add_alternate(_odb, new_backend(6), 1));
6868

6969
check_backend_sorting(_odb);
7070
}

0 commit comments

Comments
 (0)