Commit b5abb881a623b8b492e0375b8e9c8936079c39bb

Vicent Marti 2011-03-15T19:55:01

Do not segfault when listing unpacked references

diff --git a/src/refs.c b/src/refs.c
index cb11159..ea39608 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 2c4c8a2..565d636 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