Commit 62221033 by Carlos Martín Nieto

Merge pull request #1575 from arrbee/ref-iterator-early-exit

Fix refdb iteration early termination bug
parents 7b5bc8f4 99d32707
...@@ -671,16 +671,19 @@ static int refdb_fs_backend__next(const char **out, git_reference_iterator *_ite ...@@ -671,16 +671,19 @@ static int refdb_fs_backend__next(const char **out, git_reference_iterator *_ite
{ {
refdb_fs_iter *iter = (refdb_fs_iter *)_iter; refdb_fs_iter *iter = (refdb_fs_iter *)_iter;
/* First round of checks to make sure where we are */ if (iter->loose)
if (!iter->loose && iter->k == kh_end(iter->h)) { return iter_loose(out, iter);
if (iter->k != kh_end(iter->h)) {
int error = iter_packed(out, iter);
if (error != GIT_ITEROVER)
return error;
}
if (iter_loose_setup(iter) < 0) if (iter_loose_setup(iter) < 0)
return -1; return -1;
iter->loose = 1; iter->loose = 1;
}
if (!iter->loose)
return iter_packed(out, iter);
else
return iter_loose(out, iter); return iter_loose(out, iter);
} }
......
...@@ -24,6 +24,8 @@ void test_refs_branches_foreach__cleanup(void) ...@@ -24,6 +24,8 @@ void test_refs_branches_foreach__cleanup(void)
repo = NULL; repo = NULL;
cl_fixture_cleanup("testrepo.git"); cl_fixture_cleanup("testrepo.git");
cl_git_sandbox_cleanup();
} }
static int count_branch_list_cb(const char *branch_name, git_branch_t branch_type, void *payload) static int count_branch_list_cb(const char *branch_name, git_branch_t branch_type, void *payload)
...@@ -72,14 +74,11 @@ static void assert_branch_has_been_found(struct expectations *findings, const ch ...@@ -72,14 +74,11 @@ static void assert_branch_has_been_found(struct expectations *findings, const ch
{ {
int pos = 0; int pos = 0;
while (findings[pos].branch_name) for (pos = 0; findings[pos].branch_name; ++pos) {
{
if (strcmp(expected_branch_name, findings[pos].branch_name) == 0) { if (strcmp(expected_branch_name, findings[pos].branch_name) == 0) {
cl_assert_equal_i(1, findings[pos].encounters); cl_assert_equal_i(1, findings[pos].encounters);
return; return;
} }
pos++;
} }
cl_fail("expected branch not found in list."); cl_fail("expected branch not found in list.");
...@@ -94,12 +93,9 @@ static int contains_branch_list_cb(const char *branch_name, git_branch_t branch_ ...@@ -94,12 +93,9 @@ static int contains_branch_list_cb(const char *branch_name, git_branch_t branch_
exp = (struct expectations *)payload; exp = (struct expectations *)payload;
while (exp[pos].branch_name) for (pos = 0; exp[pos].branch_name; ++pos) {
{
if (strcmp(branch_name, exp[pos].branch_name) == 0) if (strcmp(branch_name, exp[pos].branch_name) == 0)
exp[pos].encounters++; exp[pos].encounters++;
pos++;
} }
return 0; return 0;
...@@ -153,3 +149,25 @@ void test_refs_branches_foreach__can_cancel(void) ...@@ -153,3 +149,25 @@ void test_refs_branches_foreach__can_cancel(void)
cl_assert_equal_i(5, count); cl_assert_equal_i(5, count);
} }
void test_refs_branches_foreach__mix_of_packed_and_loose(void)
{
struct expectations exp[] = {
{ "master", 0 },
{ "origin/HEAD", 0 },
{ "origin/master", 0 },
{ "origin/packed", 0 },
{ NULL, 0 }
};
git_repository *r2;
r2 = cl_git_sandbox_init("testrepo2");
cl_git_pass(git_branch_foreach(r2, GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE,
contains_branch_list_cb, &exp));
assert_branch_has_been_found(exp, "master");
assert_branch_has_been_found(exp, "origin/HEAD");
assert_branch_has_been_found(exp, "origin/master");
assert_branch_has_been_found(exp, "origin/packed");
}
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = false
[remote "origin"]
url = https://github.com/libgit2/false.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
rebase = true
Unnamed repository; edit this file 'description' to name the repository.
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
0000000000000000000000000000000000000000 36060c58702ed4c2a40832c51758d5344201d89a Russell Belfer <rb@github.com> 1368278260 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/../../../rugged/test/fixtures/testrepo.git
0000000000000000000000000000000000000000 36060c58702ed4c2a40832c51758d5344201d89a Russell Belfer <rb@github.com> 1368278260 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/../../../rugged/test/fixtures/testrepo.git
0000000000000000000000000000000000000000 36060c58702ed4c2a40832c51758d5344201d89a Russell Belfer <rb@github.com> 1368278260 -0700 clone: from /Users/rb/src/libgit2/tests-clar/resources/../../../rugged/test/fixtures/testrepo.git
# pack-refs with: peeled fully-peeled
36060c58702ed4c2a40832c51758d5344201d89a refs/remotes/origin/master
41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9 refs/remotes/origin/packed
5b5b025afb0b4c913b4c338a42934a3863bf3644 refs/tags/v0.9
0c37a5391bbff43c37f0d0371823a5509eed5b1d refs/tags/v1.0
^5b5b025afb0b4c913b4c338a42934a3863bf3644
36060c58702ed4c2a40832c51758d5344201d89a
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment