summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2011-03-15 19:55:01 +0200
committerVicent Marti <tanoku@gmail.com>2011-03-15 19:55:01 +0200
commitb5abb881a623b8b492e0375b8e9c8936079c39bb (patch)
treec24dfb2c039739cb25e6a6656f8ae4e65ae45f5d
parentd40d30cb76ddcc9935471af0fb6fa6b2a66efc4c (diff)
downloadlibgit2-b5abb881a623b8b492e0375b8e9c8936079c39bb.tar.gz
Do not segfault when listing unpacked references
-rw-r--r--src/refs.c3
-rw-r--r--tests/t10-refs.c19
2 files changed, 21 insertions, 1 deletions
diff --git a/src/refs.c b/src/refs.c
index cb11159fb..ea39608df 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -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)
diff --git a/tests/t10-refs.c b/tests/t10-refs.c
index 2c4c8a2dd..565d636ba 100644
--- a/tests/t10-refs.c
+++ b/tests/t10-refs.c
@@ -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