Commit b5abb881 by Vicent Marti

Do not segfault when listing unpacked references

parent d40d30cb
......@@ -560,7 +560,8 @@ static int _dirent_loose_listall(void *_data, char *full_path)
return gitfo_dirent(full_path, GIT_PATH_MAX, _dirent_loose_listall, _data);
/* do not add twice a reference that exists already in the packfile */
if (git_hashtable_lookup(data->repo->references.packfile, file_path) != NULL)
if ((data->list_flags & GIT_REF_PACKED) != 0 &&
git_hashtable_lookup(data->repo->references.packfile, file_path) != NULL)
return GIT_SUCCESS;
if ((data->list_flags & loose_guess_rtype(full_path)) == 0)
......
......@@ -717,6 +717,12 @@ BEGIN_TEST(list0, "try to list all the references in our test repo")
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_reference_listall(&ref_list, repo, GIT_REF_LISTALL));
/*{
unsigned short i;
for (i = 0; i < ref_list.count; ++i)
printf("# %s\n", ref_list.strings[i]);
}*/
/* We have exactly 7 refs in total if we include the packed ones:
* there is a reference that exists both in the packfile and as
* loose, but we only list it once */
......@@ -726,6 +732,18 @@ BEGIN_TEST(list0, "try to list all the references in our test repo")
git_repository_free(repo);
END_TEST
BEGIN_TEST(list1, "try to list only the symbolic references")
git_repository *repo;
git_strarray ref_list;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_reference_listall(&ref_list, repo, GIT_REF_SYMBOLIC));
must_be_true(ref_list.count == 0); /* no symrefs in the test repo */
git_strarray_free(&ref_list);
git_repository_free(repo);
END_TEST
BEGIN_SUITE(refs)
ADD_TEST(readtag0);
......@@ -758,4 +776,5 @@ BEGIN_SUITE(refs)
ADD_TEST(delete0);
ADD_TEST(list0);
ADD_TEST(list1);
END_SUITE
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