Commit de034cd2 by Edward Thomson

iterator: give the tests a proper hierarchy

Iterator tests were split over repo::iterator and diff::iterator,
with duplication between the two.  Move them to iterator::index,
iterator::tree, and iterator::workdir.
parent df25daef
#include "clar_libgit2.h"
#include "iterator.h"
#include "repository.h"
#include "fileops.h"
#include "iterator_helpers.h"
#include "../submodule/submodule_helpers.h"
#include <stdarg.h>
static git_repository *g_repo;
void test_iterator_index__initialize(void)
{
}
void test_iterator_index__cleanup(void)
{
cl_git_sandbox_cleanup();
g_repo = NULL;
}
static void index_iterator_test(
const char *sandbox,
const char *start,
const char *end,
git_iterator_flag_t flags,
int expected_count,
const char **expected_names,
const char **expected_oids)
{
git_index *index;
git_iterator *i;
const git_index_entry *entry;
int error, count = 0, caps;
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
g_repo = cl_git_sandbox_init(sandbox);
cl_git_pass(git_repository_index(&index, g_repo));
caps = git_index_caps(index);
iter_opts.flags = flags;
iter_opts.start = start;
iter_opts.end = end;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &iter_opts));
while (!(error = git_iterator_advance(&entry, i))) {
cl_assert(entry);
if (expected_names != NULL)
cl_assert_equal_s(expected_names[count], entry->path);
if (expected_oids != NULL) {
git_oid oid;
cl_git_pass(git_oid_fromstr(&oid, expected_oids[count]));
cl_assert_equal_oid(&oid, &entry->id);
}
count++;
}
cl_assert_equal_i(GIT_ITEROVER, error);
cl_assert(!entry);
cl_assert_equal_i(expected_count, count);
git_iterator_free(i);
cl_assert(caps == git_index_caps(index));
git_index_free(index);
}
static const char *expected_index_0[] = {
"attr0",
"attr1",
"attr2",
"attr3",
"binfile",
"gitattributes",
"macro_bad",
"macro_test",
"root_test1",
"root_test2",
"root_test3",
"root_test4.txt",
"sub/abc",
"sub/file",
"sub/sub/file",
"sub/sub/subsub.txt",
"sub/subdir_test1",
"sub/subdir_test2.txt",
"subdir/.gitattributes",
"subdir/abc",
"subdir/subdir_test1",
"subdir/subdir_test2.txt",
"subdir2/subdir2_test1",
};
static const char *expected_index_oids_0[] = {
"556f8c827b8e4a02ad5cab77dca2bcb3e226b0b3",
"3b74db7ab381105dc0d28f8295a77f6a82989292",
"2c66e14f77196ea763fb1e41612c1aa2bc2d8ed2",
"c485abe35abd4aa6fd83b076a78bbea9e2e7e06c",
"d800886d9c86731ae5c4a62b0b77c437015e00d2",
"2b40c5aca159b04ea8d20ffe36cdf8b09369b14a",
"5819a185d77b03325aaf87cafc771db36f6ddca7",
"ff69f8639ce2e6010b3f33a74160aad98b48da2b",
"45141a79a77842c59a63229403220a4e4be74e3d",
"4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
"108bb4e7fd7b16490dc33ff7d972151e73d7166e",
"a0f7217ae99f5ac3e88534f5cea267febc5fa85b",
"3e42ffc54a663f9401cc25843d6c0e71a33e4249",
"45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
"45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
"9e5bdc47d6a80f2be0ea3049ad74231b94609242",
"e563cf4758f0d646f1b14b76016aa17fa9e549a4",
"fb5067b1aef3ac1ada4b379dbcb7d17255df7d78",
"99eae476896f4907224978b88e5ecaa6c5bb67a9",
"3e42ffc54a663f9401cc25843d6c0e71a33e4249",
"e563cf4758f0d646f1b14b76016aa17fa9e549a4",
"fb5067b1aef3ac1ada4b379dbcb7d17255df7d78",
"dccada462d3df8ac6de596fb8c896aba9344f941"
};
void test_iterator_index__0(void)
{
index_iterator_test(
"attr", NULL, NULL, 0, ARRAY_SIZE(expected_index_0),
expected_index_0, expected_index_oids_0);
}
static const char *expected_index_1[] = {
"current_file",
"file_deleted",
"modified_file",
"staged_changes",
"staged_changes_file_deleted",
"staged_changes_modified_file",
"staged_new_file",
"staged_new_file_deleted_file",
"staged_new_file_modified_file",
"subdir.txt",
"subdir/current_file",
"subdir/deleted_file",
"subdir/modified_file",
};
static const char* expected_index_oids_1[] = {
"a0de7e0ac200c489c41c59dfa910154a70264e6e",
"5452d32f1dd538eb0405e8a83cc185f79e25e80f",
"452e4244b5d083ddf0460acf1ecc74db9dcfa11a",
"55d316c9ba708999f1918e9677d01dfcae69c6b9",
"a6be623522ce87a1d862128ac42672604f7b468b",
"906ee7711f4f4928ddcb2a5f8fbc500deba0d2a8",
"529a16e8e762d4acb7b9636ff540a00831f9155a",
"90b8c29d8ba39434d1c63e1b093daaa26e5bd972",
"ed062903b8f6f3dccb2fa81117ba6590944ef9bd",
"e8ee89e15bbe9b20137715232387b3de5b28972e",
"53ace0d1cc1145a5f4fe4f78a186a60263190733",
"1888c805345ba265b0ee9449b8877b6064592058",
"a6191982709b746d5650e93c2acf34ef74e11504"
};
void test_iterator_index__1(void)
{
index_iterator_test(
"status", NULL, NULL, 0, ARRAY_SIZE(expected_index_1),
expected_index_1, expected_index_oids_1);
}
static const char *expected_index_range[] = {
"root_test1",
"root_test2",
"root_test3",
"root_test4.txt",
};
static const char *expected_index_oids_range[] = {
"45141a79a77842c59a63229403220a4e4be74e3d",
"4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
"108bb4e7fd7b16490dc33ff7d972151e73d7166e",
"a0f7217ae99f5ac3e88534f5cea267febc5fa85b",
};
void test_iterator_index__range(void)
{
index_iterator_test(
"attr", "root", "root", 0, ARRAY_SIZE(expected_index_range),
expected_index_range, expected_index_oids_range);
}
void test_iterator_index__range_empty_0(void)
{
index_iterator_test(
"attr", "empty", "empty", 0, 0, NULL, NULL);
}
void test_iterator_index__range_empty_1(void)
{
index_iterator_test(
"attr", "z_empty_after", NULL, 0, 0, NULL, NULL);
}
void test_iterator_index__range_empty_2(void)
{
index_iterator_test(
"attr", NULL, ".aaa_empty_before", 0, 0, NULL, NULL);
}
static void check_index_range(
git_repository *repo,
const char *start,
const char *end,
bool ignore_case,
int expected_count)
{
git_index *index;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
int error, count, caps;
bool is_ignoring_case;
cl_git_pass(git_repository_index(&index, repo));
caps = git_index_caps(index);
is_ignoring_case = ((caps & GIT_INDEXCAP_IGNORE_CASE) != 0);
if (ignore_case != is_ignoring_case)
cl_git_pass(git_index_set_caps(index, caps ^ GIT_INDEXCAP_IGNORE_CASE));
i_opts.flags = 0;
i_opts.start = start;
i_opts.end = end;
cl_git_pass(git_iterator_for_index(&i, repo, index, &i_opts));
cl_assert(git_iterator_ignore_case(i) == ignore_case);
for (count = 0; !(error = git_iterator_advance(NULL, i)); ++count)
/* count em up */;
cl_assert_equal_i(GIT_ITEROVER, error);
cl_assert_equal_i(expected_count, count);
git_iterator_free(i);
git_index_free(index);
}
void test_iterator_index__range_icase(void)
{
git_index *index;
git_tree *head;
g_repo = cl_git_sandbox_init("testrepo");
/* reset index to match HEAD */
cl_git_pass(git_repository_head_tree(&head, g_repo));
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_index_read_tree(index, head));
cl_git_pass(git_index_write(index));
git_tree_free(head);
git_index_free(index);
/* do some ranged iterator checks toggling case sensitivity */
check_index_range(g_repo, "B", "C", false, 0);
check_index_range(g_repo, "B", "C", true, 1);
check_index_range(g_repo, "a", "z", false, 3);
check_index_range(g_repo, "a", "z", true, 4);
}
static const char *expected_index_cs[] = {
"B", "D", "F", "H", "J", "L/1", "L/B", "L/D", "L/a", "L/c",
"a", "c", "e", "g", "i", "k/1", "k/B", "k/D", "k/a", "k/c",
};
static const char *expected_index_ci[] = {
"a", "B", "c", "D", "e", "F", "g", "H", "i", "J",
"k/1", "k/a", "k/B", "k/c", "k/D", "L/1", "L/a", "L/B", "L/c", "L/D",
};
void test_iterator_index__case_folding(void)
{
git_buf path = GIT_BUF_INIT;
int fs_is_ci = 0;
cl_git_pass(git_buf_joinpath(&path, cl_fixture("icase"), ".gitted/CoNfIg"));
fs_is_ci = git_path_exists(path.ptr);
git_buf_free(&path);
index_iterator_test(
"icase", NULL, NULL, 0, ARRAY_SIZE(expected_index_cs),
fs_is_ci ? expected_index_ci : expected_index_cs, NULL);
cl_git_sandbox_cleanup();
index_iterator_test(
"icase", NULL, NULL, GIT_ITERATOR_IGNORE_CASE,
ARRAY_SIZE(expected_index_ci), expected_index_ci, NULL);
cl_git_sandbox_cleanup();
index_iterator_test(
"icase", NULL, NULL, GIT_ITERATOR_DONT_IGNORE_CASE,
ARRAY_SIZE(expected_index_cs), expected_index_cs, NULL);
}
/* Index contents (including pseudotrees):
*
* 0: a 5: F 10: k/ 16: L/
* 1: B 6: g 11: k/1 17: L/1
* 2: c 7: H 12: k/a 18: L/a
* 3: D 8: i 13: k/B 19: L/B
* 4: e 9: J 14: k/c 20: L/c
* 15: k/D 21: L/D
*
* 0: B 5: L/ 11: a 16: k/
* 1: D 6: L/1 12: c 17: k/1
* 2: F 7: L/B 13: e 18: k/B
* 3: H 8: L/D 14: g 19: k/D
* 4: J 9: L/a 15: i 20: k/a
* 10: L/c 21: k/c
*/
void test_iterator_index__icase_0(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
/* autoexpand with no tree entries for index */
cl_git_pass(git_iterator_for_index(&i, g_repo, index, NULL));
expect_iterator_items(i, 20, NULL, 20, NULL);
git_iterator_free(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 22, NULL, 22, NULL);
git_iterator_free(i);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 12, NULL, 22, NULL);
git_iterator_free(i);
git_index_free(index);
}
void test_iterator_index__icase_1(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
int caps;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
caps = git_index_caps(index);
/* force case sensitivity */
cl_git_pass(git_index_set_caps(index, caps & ~GIT_INDEXCAP_IGNORE_CASE));
/* autoexpand with no tree entries over range */
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 7, NULL, 7, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 3, NULL, 3, NULL);
git_iterator_free(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 8, NULL, 8, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 4, NULL, 4, NULL);
git_iterator_free(i);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 5, NULL, 8, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 1, NULL, 4, NULL);
git_iterator_free(i);
/* force case insensitivity */
cl_git_pass(git_index_set_caps(index, caps | GIT_INDEXCAP_IGNORE_CASE));
/* autoexpand with no tree entries over range */
i_opts.flags = 0;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 13, NULL, 13, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 5, NULL, 5, NULL);
git_iterator_free(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 14, NULL, 14, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 6, NULL, 6, NULL);
git_iterator_free(i);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 9, NULL, 14, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 1, NULL, 6, NULL);
git_iterator_free(i);
cl_git_pass(git_index_set_caps(index, caps));
git_index_free(index);
}
void test_iterator_index__pathlist(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
git_vector filelist;
int default_icase;
int expect;
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "a"));
cl_git_pass(git_vector_insert(&filelist, "B"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k/1"));
cl_git_pass(git_vector_insert(&filelist, "k/a"));
cl_git_pass(git_vector_insert(&filelist, "L/1"));
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
/* In this test we DO NOT force a case setting on the index. */
default_icase = ((git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0);
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
/* All iterator tests are "autoexpand with no tree entries" */
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 8, NULL, 8, NULL);
git_iterator_free(i);
i_opts.start = "c";
i_opts.end = NULL;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
/* (c D e k/1 k/a L ==> 6) vs (c e k/1 k/a ==> 4) */
expect = ((default_icase) ? 6 : 4);
expect_iterator_items(i, expect, NULL, expect, NULL);
git_iterator_free(i);
i_opts.start = NULL;
i_opts.end = "e";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
/* (a B c D e ==> 5) vs (B D L/1 a c e ==> 6) */
expect = ((default_icase) ? 5 : 6);
expect_iterator_items(i, expect, NULL, expect, NULL);
git_iterator_free(i);
git_index_free(index);
git_vector_free(&filelist);
}
void test_iterator_index__pathlist_1(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
git_vector filelist = GIT_VECTOR_INIT;
int default_icase, expect;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "0"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k/1"));
cl_git_pass(git_vector_insert(&filelist, "k/a"));
/* In this test we DO NOT force a case setting on the index. */
default_icase = ((git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0);
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.start = "b";
i_opts.end = "k/D";
/* (c D e k/1 k/a ==> 5) vs (c e k/1 ==> 3) */
expect = default_icase ? 5 : 3;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expect, NULL, expect, NULL);
git_iterator_free(i);
git_index_free(index);
git_vector_free(&filelist);
}
void test_iterator_index__pathlist_2(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
git_vector filelist = GIT_VECTOR_INIT;
int default_icase, expect;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "0"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k/"));
cl_git_pass(git_vector_insert(&filelist, "k.a"));
cl_git_pass(git_vector_insert(&filelist, "k.b"));
cl_git_pass(git_vector_insert(&filelist, "kZZZZZZZ"));
/* In this test we DO NOT force a case setting on the index. */
default_icase = ((git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0);
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.start = "b";
i_opts.end = "k/D";
/* (c D e k/1 k/a k/B k/c k/D) vs (c e k/1 k/B k/D) */
expect = default_icase ? 8 : 5;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expect, NULL, expect, NULL);
git_iterator_free(i);
git_index_free(index);
git_vector_free(&filelist);
}
void test_iterator_index__pathlist_four(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
git_vector filelist = GIT_VECTOR_INIT;
int default_icase, expect;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "0"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k"));
cl_git_pass(git_vector_insert(&filelist, "k.a"));
cl_git_pass(git_vector_insert(&filelist, "k.b"));
cl_git_pass(git_vector_insert(&filelist, "kZZZZZZZ"));
/* In this test we DO NOT force a case setting on the index. */
default_icase = ((git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0);
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.start = "b";
i_opts.end = "k/D";
/* (c D e k/1 k/a k/B k/c k/D) vs (c e k/1 k/B k/D) */
expect = default_icase ? 8 : 5;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expect, NULL, expect, NULL);
git_iterator_free(i);
git_index_free(index);
git_vector_free(&filelist);
}
void test_iterator_index__pathlist_icase(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
int caps;
git_vector filelist;
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "a"));
cl_git_pass(git_vector_insert(&filelist, "B"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k/1"));
cl_git_pass(git_vector_insert(&filelist, "k/a"));
cl_git_pass(git_vector_insert(&filelist, "L/1"));
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
caps = git_index_caps(index);
/* force case sensitivity */
cl_git_pass(git_index_set_caps(index, caps & ~GIT_INDEXCAP_IGNORE_CASE));
/* All indexfilelist iterator tests are "autoexpand with no tree entries" */
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 3, NULL, 3, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 1, NULL, 1, NULL);
git_iterator_free(i);
/* force case insensitivity */
cl_git_pass(git_index_set_caps(index, caps | GIT_INDEXCAP_IGNORE_CASE));
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 5, NULL, 5, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 2, NULL, 2, NULL);
git_iterator_free(i);
cl_git_pass(git_index_set_caps(index, caps));
git_index_free(index);
git_vector_free(&filelist);
}
void test_iterator_index__pathlist_with_directory(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
git_tree *tree;
git_index *index;
g_repo = cl_git_sandbox_init("testrepo2");
git_repository_head_tree(&tree, g_repo);
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "subdir"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 4, NULL, 4, NULL);
git_iterator_free(i);
git_index_free(index);
git_vector_free(&filelist);
}
#include "clar_libgit2.h"
#include "iterator.h"
#include "repository.h"
#include "fileops.h"
#include "iterator_helpers.h"
#include <stdarg.h>
static void assert_at_end(git_iterator *i, bool verbose)
{
const git_index_entry *end;
int error = git_iterator_advance(&end, i);
if (verbose && error != GIT_ITEROVER)
fprintf(stderr, "Expected end of iterator, got '%s'\n", end->path);
cl_git_fail_with(GIT_ITEROVER, error);
}
void expect_iterator_items(
git_iterator *i,
int expected_flat,
const char **expected_flat_paths,
int expected_total,
const char **expected_total_paths)
{
const git_index_entry *entry;
int count, error;
int no_trees = !(git_iterator_flags(i) & GIT_ITERATOR_INCLUDE_TREES);
bool v = false;
if (expected_flat < 0) { v = true; expected_flat = -expected_flat; }
if (expected_total < 0) { v = true; expected_total = -expected_total; }
if (v) fprintf(stderr, "== %s ==\n", no_trees ? "notrees" : "trees");
count = 0;
while (!git_iterator_advance(&entry, i)) {
if (v) fprintf(stderr, " %s %07o\n", entry->path, (int)entry->mode);
if (no_trees)
cl_assert(entry->mode != GIT_FILEMODE_TREE);
if (expected_flat_paths) {
const char *expect_path = expected_flat_paths[count];
size_t expect_len = strlen(expect_path);
cl_assert_equal_s(expect_path, entry->path);
if (expect_path[expect_len - 1] == '/')
cl_assert_equal_i(GIT_FILEMODE_TREE, entry->mode);
else
cl_assert(entry->mode != GIT_FILEMODE_TREE);
}
if (++count >= expected_flat)
break;
}
assert_at_end(i, v);
cl_assert_equal_i(expected_flat, count);
cl_git_pass(git_iterator_reset(i));
count = 0;
cl_git_pass(git_iterator_current(&entry, i));
if (v) fprintf(stderr, "-- %s --\n", no_trees ? "notrees" : "trees");
while (entry != NULL) {
if (v) fprintf(stderr, " %s %07o\n", entry->path, (int)entry->mode);
if (no_trees)
cl_assert(entry->mode != GIT_FILEMODE_TREE);
if (expected_total_paths) {
const char *expect_path = expected_total_paths[count];
size_t expect_len = strlen(expect_path);
cl_assert_equal_s(expect_path, entry->path);
if (expect_path[expect_len - 1] == '/')
cl_assert_equal_i(GIT_FILEMODE_TREE, entry->mode);
else
cl_assert(entry->mode != GIT_FILEMODE_TREE);
}
if (entry->mode == GIT_FILEMODE_TREE) {
error = git_iterator_advance_into(&entry, i);
/* could return NOTFOUND if directory is empty */
cl_assert(!error || error == GIT_ENOTFOUND);
if (error == GIT_ENOTFOUND) {
error = git_iterator_advance(&entry, i);
cl_assert(!error || error == GIT_ITEROVER);
}
} else {
error = git_iterator_advance(&entry, i);
cl_assert(!error || error == GIT_ITEROVER);
}
if (++count >= expected_total)
break;
}
assert_at_end(i, v);
cl_assert_equal_i(expected_total, count);
}
extern void expect_iterator_items(
git_iterator *i,
int expected_flat,
const char **expected_flat_paths,
int expected_total,
const char **expected_total_paths);
#include "clar_libgit2.h"
#include "diff_helpers.h"
#include "iterator.h"
#include "repository.h"
#include "fileops.h"
#include "tree.h"
#include "../submodule/submodule_helpers.h"
#include "../diff/diff_helpers.h"
#include "iterator_helpers.h"
#include <stdarg.h>
void test_diff_iterator__initialize(void)
static git_repository *g_repo;
void test_iterator_tree__initialize(void)
{
/* since we are doing tests with different sandboxes, defer setup
* to the actual tests. cleanup will still be done in the global
* cleanup function so that assertion failures don't result in a
* missed cleanup.
*/
}
void test_diff_iterator__cleanup(void)
void test_iterator_tree__cleanup(void)
{
cl_git_sandbox_cleanup();
g_repo = NULL;
}
/* -- TREE ITERATOR TESTS -- */
static void tree_iterator_test(
const char *sandbox,
const char *treeish,
......@@ -33,13 +33,14 @@ static void tree_iterator_test(
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry;
int error, count = 0, count_post_reset = 0;
git_repository *repo = cl_git_sandbox_init(sandbox);
g_repo = cl_git_sandbox_init(sandbox);
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
i_opts.start = start;
i_opts.end = end;
cl_assert(t = resolve_commit_oid_to_tree(repo, treeish));
cl_assert(t = resolve_commit_oid_to_tree(g_repo, treeish));
cl_git_pass(git_iterator_for_tree(&i, t, &i_opts));
/* test loop */
......@@ -91,7 +92,7 @@ const char *expected_tree_0[] = {
NULL
};
void test_diff_iterator__tree_0(void)
void test_iterator_tree__0(void)
{
tree_iterator_test("attr", "605812a", NULL, NULL, 16, expected_tree_0);
}
......@@ -114,7 +115,7 @@ const char *expected_tree_1[] = {
NULL
};
void test_diff_iterator__tree_1(void)
void test_iterator_tree__1(void)
{
tree_iterator_test("attr", "6bab5c79cd5", NULL, NULL, 13, expected_tree_1);
}
......@@ -136,7 +137,7 @@ const char *expected_tree_2[] = {
NULL
};
void test_diff_iterator__tree_2(void)
void test_iterator_tree__2(void)
{
tree_iterator_test("status", "26a125ee1", NULL, NULL, 12, expected_tree_2);
}
......@@ -153,7 +154,7 @@ const char *expected_tree_3[] = {
"staged_delete_modified_file"
};
void test_diff_iterator__tree_3(void)
void test_iterator_tree__3(void)
{
tree_iterator_test("status", "0017bd4ab1e", NULL, NULL, 8, expected_tree_3);
}
......@@ -186,14 +187,14 @@ const char *expected_tree_4[] = {
NULL
};
void test_diff_iterator__tree_4(void)
void test_iterator_tree__4(void)
{
tree_iterator_test(
"attr", "24fa9a9fc4e202313e24b648087495441dab432b", NULL, NULL,
23, expected_tree_4);
}
void test_diff_iterator__tree_4_ranged(void)
void test_iterator_tree__4_ranged(void)
{
tree_iterator_test(
"attr", "24fa9a9fc4e202313e24b648087495441dab432b",
......@@ -212,7 +213,7 @@ const char *expected_tree_ranged_0[] = {
NULL
};
void test_diff_iterator__tree_ranged_0(void)
void test_iterator_tree__ranged_0(void)
{
tree_iterator_test(
"attr", "24fa9a9fc4e202313e24b648087495441dab432b",
......@@ -225,7 +226,7 @@ const char *expected_tree_ranged_1[] = {
NULL
};
void test_diff_iterator__tree_ranged_1(void)
void test_iterator_tree__ranged_1(void)
{
tree_iterator_test(
"attr", "24fa9a9fc4e202313e24b648087495441dab432b",
......@@ -233,21 +234,21 @@ void test_diff_iterator__tree_ranged_1(void)
1, expected_tree_ranged_1);
}
void test_diff_iterator__tree_range_empty_0(void)
void test_iterator_tree__range_empty_0(void)
{
tree_iterator_test(
"attr", "24fa9a9fc4e202313e24b648087495441dab432b",
"empty", "empty", 0, NULL);
}
void test_diff_iterator__tree_range_empty_1(void)
void test_iterator_tree__range_empty_1(void)
{
tree_iterator_test(
"attr", "24fa9a9fc4e202313e24b648087495441dab432b",
"z_empty_after", NULL, 0, NULL);
}
void test_diff_iterator__tree_range_empty_2(void)
void test_iterator_tree__range_empty_2(void)
{
tree_iterator_test(
"attr", "24fa9a9fc4e202313e24b648087495441dab432b",
......@@ -290,18 +291,19 @@ static void check_tree_entry(
}
}
void test_diff_iterator__tree_special_functions(void)
void test_iterator_tree__special_functions(void)
{
git_tree *t;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry;
git_repository *repo = cl_git_sandbox_init("attr");
int error, cases = 0;
const char *rootoid = "ce39a97a7fb1fa90bcf5e711249c1e507476ae0e";
g_repo = cl_git_sandbox_init("attr");
t = resolve_commit_oid_to_tree(
repo, "24fa9a9fc4e202313e24b648087495441dab432b");
g_repo, "24fa9a9fc4e202313e24b648087495441dab432b");
cl_assert(t != NULL);
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
......@@ -348,658 +350,715 @@ void test_diff_iterator__tree_special_functions(void)
git_tree_free(t);
}
/* -- INDEX ITERATOR TESTS -- */
static void index_iterator_test(
const char *sandbox,
static void check_tree_range(
git_repository *repo,
const char *start,
const char *end,
git_iterator_flag_t flags,
int expected_count,
const char **expected_names,
const char **expected_oids)
bool ignore_case,
int expected_count)
{
git_index *index;
git_tree *head;
git_iterator *i;
const git_index_entry *entry;
int error, count = 0, caps;
git_repository *repo = cl_git_sandbox_init(sandbox);
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
cl_git_pass(git_repository_index(&index, repo));
caps = git_index_caps(index);
iter_opts.flags = flags;
iter_opts.start = start;
iter_opts.end = end;
cl_git_pass(git_iterator_for_index(&i, repo, index, &iter_opts));
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
int error, count;
while (!(error = git_iterator_advance(&entry, i))) {
cl_assert(entry);
i_opts.flags = ignore_case ? GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE;
i_opts.start = start;
i_opts.end = end;
if (expected_names != NULL)
cl_assert_equal_s(expected_names[count], entry->path);
cl_git_pass(git_repository_head_tree(&head, repo));
if (expected_oids != NULL) {
git_oid oid;
cl_git_pass(git_oid_fromstr(&oid, expected_oids[count]));
cl_assert_equal_oid(&oid, &entry->id);
}
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
count++;
}
for (count = 0; !(error = git_iterator_advance(NULL, i)); ++count)
/* count em up */;
cl_assert_equal_i(GIT_ITEROVER, error);
cl_assert(!entry);
cl_assert_equal_i(expected_count, count);
git_iterator_free(i);
cl_assert(caps == git_index_caps(index));
git_index_free(index);
git_tree_free(head);
}
static const char *expected_index_0[] = {
"attr0",
"attr1",
"attr2",
"attr3",
"binfile",
"gitattributes",
"macro_bad",
"macro_test",
"root_test1",
"root_test2",
"root_test3",
"root_test4.txt",
"sub/abc",
"sub/file",
"sub/sub/file",
"sub/sub/subsub.txt",
"sub/subdir_test1",
"sub/subdir_test2.txt",
"subdir/.gitattributes",
"subdir/abc",
"subdir/subdir_test1",
"subdir/subdir_test2.txt",
"subdir2/subdir2_test1",
};
static const char *expected_index_oids_0[] = {
"556f8c827b8e4a02ad5cab77dca2bcb3e226b0b3",
"3b74db7ab381105dc0d28f8295a77f6a82989292",
"2c66e14f77196ea763fb1e41612c1aa2bc2d8ed2",
"c485abe35abd4aa6fd83b076a78bbea9e2e7e06c",
"d800886d9c86731ae5c4a62b0b77c437015e00d2",
"2b40c5aca159b04ea8d20ffe36cdf8b09369b14a",
"5819a185d77b03325aaf87cafc771db36f6ddca7",
"ff69f8639ce2e6010b3f33a74160aad98b48da2b",
"45141a79a77842c59a63229403220a4e4be74e3d",
"4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
"108bb4e7fd7b16490dc33ff7d972151e73d7166e",
"a0f7217ae99f5ac3e88534f5cea267febc5fa85b",
"3e42ffc54a663f9401cc25843d6c0e71a33e4249",
"45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
"45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
"9e5bdc47d6a80f2be0ea3049ad74231b94609242",
"e563cf4758f0d646f1b14b76016aa17fa9e549a4",
"fb5067b1aef3ac1ada4b379dbcb7d17255df7d78",
"99eae476896f4907224978b88e5ecaa6c5bb67a9",
"3e42ffc54a663f9401cc25843d6c0e71a33e4249",
"e563cf4758f0d646f1b14b76016aa17fa9e549a4",
"fb5067b1aef3ac1ada4b379dbcb7d17255df7d78",
"dccada462d3df8ac6de596fb8c896aba9344f941"
};
void test_diff_iterator__index_0(void)
void test_iterator_tree__range_icase(void)
{
index_iterator_test(
"attr", NULL, NULL, 0, ARRAY_SIZE(expected_index_0),
expected_index_0, expected_index_oids_0);
g_repo = cl_git_sandbox_init("testrepo");
check_tree_range(g_repo, "B", "C", false, 0);
check_tree_range(g_repo, "B", "C", true, 1);
check_tree_range(g_repo, "b", "c", false, 1);
check_tree_range(g_repo, "b", "c", true, 1);
check_tree_range(g_repo, "a", "z", false, 3);
check_tree_range(g_repo, "a", "z", true, 4);
check_tree_range(g_repo, "A", "Z", false, 1);
check_tree_range(g_repo, "A", "Z", true, 4);
check_tree_range(g_repo, "a", "Z", false, 0);
check_tree_range(g_repo, "a", "Z", true, 4);
check_tree_range(g_repo, "A", "z", false, 4);
check_tree_range(g_repo, "A", "z", true, 4);
check_tree_range(g_repo, "new.txt", "new.txt", true, 1);
check_tree_range(g_repo, "new.txt", "new.txt", false, 1);
check_tree_range(g_repo, "README", "README", true, 1);
check_tree_range(g_repo, "README", "README", false, 1);
}
static const char *expected_index_range[] = {
"root_test1",
"root_test2",
"root_test3",
"root_test4.txt",
};
void test_iterator_tree__icase_0(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_tree *head;
static const char *expected_index_oids_range[] = {
"45141a79a77842c59a63229403220a4e4be74e3d",
"4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
"108bb4e7fd7b16490dc33ff7d972151e73d7166e",
"a0f7217ae99f5ac3e88534f5cea267febc5fa85b",
};
g_repo = cl_git_sandbox_init("icase");
void test_diff_iterator__index_range(void)
{
index_iterator_test(
"attr", "root", "root", 0, ARRAY_SIZE(expected_index_range),
expected_index_range, expected_index_oids_range);
}
cl_git_pass(git_repository_head_tree(&head, g_repo));
void test_diff_iterator__index_range_empty_0(void)
{
index_iterator_test(
"attr", "empty", "empty", 0, 0, NULL, NULL);
}
/* auto expand with no tree entries */
cl_git_pass(git_iterator_for_tree(&i, head, NULL));
expect_iterator_items(i, 20, NULL, 20, NULL);
git_iterator_free(i);
void test_diff_iterator__index_range_empty_1(void)
{
index_iterator_test(
"attr", "z_empty_after", NULL, 0, 0, NULL, NULL);
}
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
void test_diff_iterator__index_range_empty_2(void)
{
index_iterator_test(
"attr", NULL, ".aaa_empty_before", 0, 0, NULL, NULL);
}
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 22, NULL, 22, NULL);
git_iterator_free(i);
static const char *expected_index_1[] = {
"current_file",
"file_deleted",
"modified_file",
"staged_changes",
"staged_changes_file_deleted",
"staged_changes_modified_file",
"staged_new_file",
"staged_new_file_deleted_file",
"staged_new_file_modified_file",
"subdir.txt",
"subdir/current_file",
"subdir/deleted_file",
"subdir/modified_file",
};
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
static const char* expected_index_oids_1[] = {
"a0de7e0ac200c489c41c59dfa910154a70264e6e",
"5452d32f1dd538eb0405e8a83cc185f79e25e80f",
"452e4244b5d083ddf0460acf1ecc74db9dcfa11a",
"55d316c9ba708999f1918e9677d01dfcae69c6b9",
"a6be623522ce87a1d862128ac42672604f7b468b",
"906ee7711f4f4928ddcb2a5f8fbc500deba0d2a8",
"529a16e8e762d4acb7b9636ff540a00831f9155a",
"90b8c29d8ba39434d1c63e1b093daaa26e5bd972",
"ed062903b8f6f3dccb2fa81117ba6590944ef9bd",
"e8ee89e15bbe9b20137715232387b3de5b28972e",
"53ace0d1cc1145a5f4fe4f78a186a60263190733",
"1888c805345ba265b0ee9449b8877b6064592058",
"a6191982709b746d5650e93c2acf34ef74e11504"
};
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 12, NULL, 22, NULL);
git_iterator_free(i);
void test_diff_iterator__index_1(void)
{
index_iterator_test(
"status", NULL, NULL, 0, ARRAY_SIZE(expected_index_1),
expected_index_1, expected_index_oids_1);
git_tree_free(head);
}
static const char *expected_index_cs[] = {
"B", "D", "F", "H", "J", "L/1", "L/B", "L/D", "L/a", "L/c",
"a", "c", "e", "g", "i", "k/1", "k/B", "k/D", "k/a", "k/c",
};
void test_iterator_tree__icase_1(void)
{
git_iterator *i;
git_tree *head;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
static const char *expected_index_ci[] = {
"a", "B", "c", "D", "e", "F", "g", "H", "i", "J",
"k/1", "k/a", "k/B", "k/c", "k/D", "L/1", "L/a", "L/B", "L/c", "L/D",
};
g_repo = cl_git_sandbox_init("icase");
void test_diff_iterator__index_case_folding(void)
{
git_buf path = GIT_BUF_INIT;
int fs_is_ci = 0;
cl_git_pass(git_repository_head_tree(&head, g_repo));
cl_git_pass(git_buf_joinpath(&path, cl_fixture("icase"), ".gitted/CoNfIg"));
fs_is_ci = git_path_exists(path.ptr);
git_buf_free(&path);
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
index_iterator_test(
"icase", NULL, NULL, 0, ARRAY_SIZE(expected_index_cs),
fs_is_ci ? expected_index_ci : expected_index_cs, NULL);
/* auto expand with no tree entries */
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 7, NULL, 7, NULL);
git_iterator_free(i);
cl_git_sandbox_cleanup();
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 3, NULL, 3, NULL);
git_iterator_free(i);
index_iterator_test(
"icase", NULL, NULL, GIT_ITERATOR_IGNORE_CASE,
ARRAY_SIZE(expected_index_ci), expected_index_ci, NULL);
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_sandbox_cleanup();
/* auto expand with tree entries */
i_opts.start = "c";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 8, NULL, 8, NULL);
git_iterator_free(i);
index_iterator_test(
"icase", NULL, NULL, GIT_ITERATOR_DONT_IGNORE_CASE,
ARRAY_SIZE(expected_index_cs), expected_index_cs, NULL);
}
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 4, NULL, 4, NULL);
git_iterator_free(i);
/* -- WORKDIR ITERATOR TESTS -- */
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 5, NULL, 8, NULL);
git_iterator_free(i);
static void workdir_iterator_test(
const char *sandbox,
const char *start,
const char *end,
int expected_count,
int expected_ignores,
const char **expected_names,
const char *an_ignored_name)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry;
int error, count = 0, count_all = 0, count_all_post_reset = 0;
git_repository *repo = cl_git_sandbox_init(sandbox);
i_opts.start = "k";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 1, NULL, 4, NULL);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = start;
i_opts.end = end;
/* auto expand with no tree entries */
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, repo, NULL, NULL, &i_opts));
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 13, NULL, 13, NULL);
git_iterator_free(i);
error = git_iterator_current(&entry, i);
cl_assert((error == 0 && entry != NULL) ||
(error == GIT_ITEROVER && entry == NULL));
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 5, NULL, 5, NULL);
git_iterator_free(i);
while (entry != NULL) {
int ignored = git_iterator_current_is_ignored(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
if (S_ISDIR(entry->mode)) {
cl_git_pass(git_iterator_advance_into(&entry, i));
continue;
}
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 14, NULL, 14, NULL);
git_iterator_free(i);
if (expected_names != NULL)
cl_assert_equal_s(expected_names[count_all], entry->path);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 6, NULL, 6, NULL);
git_iterator_free(i);
if (an_ignored_name && strcmp(an_ignored_name,entry->path)==0)
cl_assert(ignored);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_DONT_AUTOEXPAND;
if (!ignored)
count++;
count_all++;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 9, NULL, 14, NULL);
git_iterator_free(i);
error = git_iterator_advance(&entry, i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 1, NULL, 6, NULL);
git_iterator_free(i);
cl_assert((error == 0 && entry != NULL) ||
(error == GIT_ITEROVER && entry == NULL));
}
git_tree_free(head);
}
cl_assert_equal_i(expected_count, count);
cl_assert_equal_i(expected_count + expected_ignores, count_all);
void test_iterator_tree__icase_2(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_tree *head;
static const char *expect_basic[] = {
"current_file",
"file_deleted",
"modified_file",
"staged_changes",
"staged_changes_file_deleted",
"staged_changes_modified_file",
"staged_delete_file_deleted",
"staged_delete_modified_file",
"subdir.txt",
"subdir/current_file",
"subdir/deleted_file",
"subdir/modified_file",
NULL,
};
static const char *expect_trees[] = {
"current_file",
"file_deleted",
"modified_file",
"staged_changes",
"staged_changes_file_deleted",
"staged_changes_modified_file",
"staged_delete_file_deleted",
"staged_delete_modified_file",
"subdir.txt",
"subdir/",
"subdir/current_file",
"subdir/deleted_file",
"subdir/modified_file",
NULL,
};
static const char *expect_noauto[] = {
"current_file",
"file_deleted",
"modified_file",
"staged_changes",
"staged_changes_file_deleted",
"staged_changes_modified_file",
"staged_delete_file_deleted",
"staged_delete_modified_file",
"subdir.txt",
"subdir/",
NULL
};
cl_git_pass(git_iterator_reset(i));
g_repo = cl_git_sandbox_init("status");
error = git_iterator_current(&entry, i);
cl_assert((error == 0 && entry != NULL) ||
(error == GIT_ITEROVER && entry == NULL));
cl_git_pass(git_repository_head_tree(&head, g_repo));
while (entry != NULL) {
if (S_ISDIR(entry->mode)) {
cl_git_pass(git_iterator_advance_into(&entry, i));
continue;
}
/* auto expand with no tree entries */
cl_git_pass(git_iterator_for_tree(&i, head, NULL));
expect_iterator_items(i, 12, expect_basic, 12, expect_basic);
git_iterator_free(i);
if (expected_names != NULL)
cl_assert_equal_s(
expected_names[count_all_post_reset], entry->path);
count_all_post_reset++;
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
error = git_iterator_advance(&entry, i);
cl_assert(error == 0 || error == GIT_ITEROVER);
}
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 13, expect_trees, 13, expect_trees);
git_iterator_free(i);
cl_assert_equal_i(count_all, count_all_post_reset);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 10, expect_noauto, 13, expect_trees);
git_iterator_free(i);
git_tree_free(head);
}
void test_diff_iterator__workdir_0(void)
/* "b=name,t=name", blob_id, tree_id */
static void build_test_tree(
git_oid *out, git_repository *repo, const char *fmt, ...)
{
workdir_iterator_test("attr", NULL, NULL, 23, 5, NULL, "ign");
}
git_oid *id;
git_treebuilder *builder;
const char *scan = fmt, *next;
char type, delimiter;
git_filemode_t mode = GIT_FILEMODE_BLOB;
git_buf name = GIT_BUF_INIT;
va_list arglist;
cl_git_pass(git_treebuilder_new(&builder, repo, NULL)); /* start builder */
va_start(arglist, fmt);
while (*scan) {
switch (type = *scan++) {
case 't': case 'T': mode = GIT_FILEMODE_TREE; break;
case 'b': case 'B': mode = GIT_FILEMODE_BLOB; break;
default:
cl_assert(type == 't' || type == 'T' || type == 'b' || type == 'B');
}
static const char *status_paths[] = {
"current_file",
"ignored_file",
"modified_file",
"new_file",
"staged_changes",
"staged_changes_modified_file",
"staged_delete_modified_file",
"staged_new_file",
"staged_new_file_modified_file",
"subdir.txt",
"subdir/current_file",
"subdir/modified_file",
"subdir/new_file",
"\xe8\xbf\x99",
NULL
};
delimiter = *scan++; /* read and skip delimiter */
for (next = scan; *next && *next != delimiter; ++next)
/* seek end */;
cl_git_pass(git_buf_set(&name, scan, (size_t)(next - scan)));
for (scan = next; *scan && (*scan == delimiter || *scan == ','); ++scan)
/* skip delimiter and optional comma */;
void test_diff_iterator__workdir_1(void)
{
workdir_iterator_test(
"status", NULL, NULL, 13, 1, status_paths, "ignored_file");
}
id = va_arg(arglist, git_oid *);
static const char *status_paths_range_0[] = {
"staged_changes",
"staged_changes_modified_file",
"staged_delete_modified_file",
"staged_new_file",
"staged_new_file_modified_file",
NULL
};
cl_git_pass(git_treebuilder_insert(NULL, builder, name.ptr, id, mode));
}
va_end(arglist);
void test_diff_iterator__workdir_1_ranged_0(void)
{
workdir_iterator_test(
"status", "staged", "staged", 5, 0, status_paths_range_0, NULL);
}
cl_git_pass(git_treebuilder_write(out, builder));
static const char *status_paths_range_1[] = {
"modified_file", NULL
};
git_treebuilder_free(builder);
git_buf_free(&name);
}
void test_diff_iterator__workdir_1_ranged_1(void)
void test_iterator_tree__case_conflicts_0(void)
{
workdir_iterator_test(
"status", "modified_file", "modified_file",
1, 0, status_paths_range_1, NULL);
}
const char *blob_sha = "d44e18fb93b7107b5cd1b95d601591d77869a1b6";
git_tree *tree;
git_oid blob_id, biga_id, littlea_id, tree_id;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
static const char *status_paths_range_3[] = {
"subdir.txt",
"subdir/current_file",
"subdir/modified_file",
NULL
};
const char *expect_cs[] = {
"A/1.file", "A/3.file", "a/2.file", "a/4.file" };
const char *expect_ci[] = {
"A/1.file", "a/2.file", "A/3.file", "a/4.file" };
const char *expect_cs_trees[] = {
"A/", "A/1.file", "A/3.file", "a/", "a/2.file", "a/4.file" };
const char *expect_ci_trees[] = {
"A/", "A/1.file", "a/2.file", "A/3.file", "a/4.file" };
void test_diff_iterator__workdir_1_ranged_3(void)
{
workdir_iterator_test(
"status", "subdir", "subdir/modified_file",
3, 0, status_paths_range_3, NULL);
}
g_repo = cl_git_sandbox_init("icase");
static const char *status_paths_range_4[] = {
"subdir/current_file",
"subdir/modified_file",
"subdir/new_file",
"\xe8\xbf\x99",
NULL
};
cl_git_pass(git_oid_fromstr(&blob_id, blob_sha)); /* lookup blob */
void test_diff_iterator__workdir_1_ranged_4(void)
{
workdir_iterator_test(
"status", "subdir/", NULL, 4, 0, status_paths_range_4, NULL);
}
/* create tree with: A/1.file, A/3.file, a/2.file, a/4.file */
build_test_tree(
&biga_id, g_repo, "b|1.file|,b|3.file|", &blob_id, &blob_id);
build_test_tree(
&littlea_id, g_repo, "b|2.file|,b|4.file|", &blob_id, &blob_id);
build_test_tree(
&tree_id, g_repo, "t|A|,t|a|", &biga_id, &littlea_id);
static const char *status_paths_range_5[] = {
"subdir/modified_file",
NULL
};
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
void test_diff_iterator__workdir_1_ranged_5(void)
{
workdir_iterator_test(
"status", "subdir/modified_file", "subdir/modified_file",
1, 0, status_paths_range_5, NULL);
}
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 4, expect_cs, 4, expect_cs);
git_iterator_free(i);
void test_diff_iterator__workdir_1_ranged_empty_0(void)
{
workdir_iterator_test(
"status", "\xff_does_not_exist", NULL,
0, 0, NULL, NULL);
}
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 4, expect_ci, 4, expect_ci);
git_iterator_free(i);
void test_diff_iterator__workdir_1_ranged_empty_1(void)
{
workdir_iterator_test(
"status", "empty", "empty",
0, 0, NULL, NULL);
}
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 6, expect_cs_trees, 6, expect_cs_trees);
git_iterator_free(i);
void test_diff_iterator__workdir_1_ranged_empty_2(void)
{
workdir_iterator_test(
"status", NULL, "aaaa_empty_before",
0, 0, NULL, NULL);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 5, expect_ci_trees, 5, expect_ci_trees);
git_iterator_free(i);
git_tree_free(tree);
}
void test_diff_iterator__workdir_builtin_ignores(void)
void test_iterator_tree__case_conflicts_1(void)
{
git_repository *repo = cl_git_sandbox_init("attr");
const char *blob_sha = "d44e18fb93b7107b5cd1b95d601591d77869a1b6";
git_tree *tree;
git_oid blob_id, Ab_id, biga_id, littlea_id, tree_id;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry;
int idx;
static struct {
const char *path;
bool ignored;
} expected[] = {
{ "dir/", true },
{ "file", false },
{ "ign", true },
{ "macro_bad", false },
{ "macro_test", false },
{ "root_test1", false },
{ "root_test2", false },
{ "root_test3", false },
{ "root_test4.txt", false },
{ "sub/", false },
{ "sub/.gitattributes", false },
{ "sub/abc", false },
{ "sub/dir/", true },
{ "sub/file", false },
{ "sub/ign/", true },
{ "sub/sub/", false },
{ "sub/sub/.gitattributes", false },
{ "sub/sub/dir", false }, /* file is not actually a dir */
{ "sub/sub/file", false },
{ NULL, false }
};
cl_git_pass(p_mkdir("attr/sub/sub/.git", 0777));
cl_git_mkfile("attr/sub/.git", "whatever");
const char *expect_cs[] = {
"A/a", "A/b/1", "A/c", "a/C", "a/a", "a/b" };
const char *expect_ci[] = {
"A/a", "a/b", "A/b/1", "A/c" };
const char *expect_cs_trees[] = {
"A/", "A/a", "A/b/", "A/b/1", "A/c", "a/", "a/C", "a/a", "a/b" };
const char *expect_ci_trees[] = {
"A/", "A/a", "a/b", "A/b/", "A/b/1", "A/c" };
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = "dir";
i_opts.end = "sub/sub/file";
cl_git_pass(git_iterator_for_workdir(
&i, repo, NULL, NULL, &i_opts));
cl_git_pass(git_iterator_current(&entry, i));
for (idx = 0; entry != NULL; ++idx) {
int ignored = git_iterator_current_is_ignored(i);
cl_assert_equal_s(expected[idx].path, entry->path);
cl_assert_(ignored == expected[idx].ignored, expected[idx].path);
if (!ignored &&
(entry->mode == GIT_FILEMODE_TREE ||
entry->mode == GIT_FILEMODE_COMMIT))
{
/* it is possible to advance "into" a submodule */
cl_git_pass(git_iterator_advance_into(&entry, i));
} else {
int error = git_iterator_advance(&entry, i);
cl_assert(!error || error == GIT_ITEROVER);
}
}
g_repo = cl_git_sandbox_init("icase");
cl_assert(expected[idx].path == NULL);
cl_git_pass(git_oid_fromstr(&blob_id, blob_sha)); /* lookup blob */
/* create: A/a A/b/1 A/c a/a a/b a/C */
build_test_tree(&Ab_id, g_repo, "b|1|", &blob_id);
build_test_tree(
&biga_id, g_repo, "b|a|,t|b|,b|c|", &blob_id, &Ab_id, &blob_id);
build_test_tree(
&littlea_id, g_repo, "b|a|,b|b|,b|C|", &blob_id, &blob_id, &blob_id);
build_test_tree(
&tree_id, g_repo, "t|A|,t|a|", &biga_id, &littlea_id);
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 6, expect_cs, 6, expect_cs);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 4, expect_ci, 4, expect_ci);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 9, expect_cs_trees, 9, expect_cs_trees);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 6, expect_ci_trees, 6, expect_ci_trees);
git_iterator_free(i);
git_tree_free(tree);
}
static void check_wd_first_through_third_range(
git_repository *repo, const char *start, const char *end)
void test_iterator_tree__case_conflicts_2(void)
{
const char *blob_sha = "d44e18fb93b7107b5cd1b95d601591d77869a1b6";
git_tree *tree;
git_oid blob_id, d1, d2, c1, c2, b1, b2, a1, a2, tree_id;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry;
int error, idx;
static const char *expected[] = { "FIRST", "second", "THIRD", NULL };
const char *expect_cs[] = {
"A/B/C/D/16", "A/B/C/D/foo", "A/B/C/d/15", "A/B/C/d/FOO",
"A/B/c/D/14", "A/B/c/D/foo", "A/B/c/d/13", "A/B/c/d/FOO",
"A/b/C/D/12", "A/b/C/D/foo", "A/b/C/d/11", "A/b/C/d/FOO",
"A/b/c/D/10", "A/b/c/D/foo", "A/b/c/d/09", "A/b/c/d/FOO",
"a/B/C/D/08", "a/B/C/D/foo", "a/B/C/d/07", "a/B/C/d/FOO",
"a/B/c/D/06", "a/B/c/D/foo", "a/B/c/d/05", "a/B/c/d/FOO",
"a/b/C/D/04", "a/b/C/D/foo", "a/b/C/d/03", "a/b/C/d/FOO",
"a/b/c/D/02", "a/b/c/D/foo", "a/b/c/d/01", "a/b/c/d/FOO", };
const char *expect_ci[] = {
"a/b/c/d/01", "a/b/c/D/02", "a/b/C/d/03", "a/b/C/D/04",
"a/B/c/d/05", "a/B/c/D/06", "a/B/C/d/07", "a/B/C/D/08",
"A/b/c/d/09", "A/b/c/D/10", "A/b/C/d/11", "A/b/C/D/12",
"A/B/c/d/13", "A/B/c/D/14", "A/B/C/d/15", "A/B/C/D/16",
"A/B/C/D/foo", };
const char *expect_ci_trees[] = {
"A/", "A/B/", "A/B/C/", "A/B/C/D/",
"a/b/c/d/01", "a/b/c/D/02", "a/b/C/d/03", "a/b/C/D/04",
"a/B/c/d/05", "a/B/c/D/06", "a/B/C/d/07", "a/B/C/D/08",
"A/b/c/d/09", "A/b/c/D/10", "A/b/C/d/11", "A/b/C/D/12",
"A/B/c/d/13", "A/B/c/D/14", "A/B/C/d/15", "A/B/C/D/16",
"A/B/C/D/foo", };
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_oid_fromstr(&blob_id, blob_sha)); /* lookup blob */
build_test_tree(&d1, g_repo, "b|16|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|15|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c1, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&d1, g_repo, "b|14|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|13|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c2, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&b1, g_repo, "t|C|,t|c|", &c1, &c2);
build_test_tree(&d1, g_repo, "b|12|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|11|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c1, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&d1, g_repo, "b|10|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|09|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c2, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&b2, g_repo, "t|C|,t|c|", &c1, &c2);
build_test_tree(&a1, g_repo, "t|B|,t|b|", &b1, &b2);
build_test_tree(&d1, g_repo, "b|08|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|07|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c1, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&d1, g_repo, "b|06|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|05|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c2, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&b1, g_repo, "t|C|,t|c|", &c1, &c2);
build_test_tree(&d1, g_repo, "b|04|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|03|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c1, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&d1, g_repo, "b|02|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|01|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c2, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&b2, g_repo, "t|C|,t|c|", &c1, &c2);
build_test_tree(&a2, g_repo, "t|B|,t|b|", &b1, &b2);
build_test_tree(&tree_id, g_repo, "t/A/,t/a/", &a1, &a2);
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 32, expect_cs, 32, expect_cs);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
i_opts.start = start;
i_opts.end = end;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 17, expect_ci, 17, expect_ci);
git_iterator_free(i);
cl_git_pass(git_iterator_for_workdir(
&i, repo, NULL, NULL, &i_opts));
cl_git_pass(git_iterator_current(&entry, i));
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 21, expect_ci_trees, 21, expect_ci_trees);
git_iterator_free(i);
for (idx = 0; entry != NULL; ++idx) {
cl_assert_equal_s(expected[idx], entry->path);
git_tree_free(tree);
}
error = git_iterator_advance(&entry, i);
cl_assert(!error || error == GIT_ITEROVER);
}
void test_iterator_tree__pathlist(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
git_tree *tree;
bool default_icase;
int expect;
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "a"));
cl_git_pass(git_vector_insert(&filelist, "B"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k.a"));
cl_git_pass(git_vector_insert(&filelist, "k.b"));
cl_git_pass(git_vector_insert(&filelist, "k/1"));
cl_git_pass(git_vector_insert(&filelist, "k/a"));
cl_git_pass(git_vector_insert(&filelist, "kZZZZZZZ"));
cl_git_pass(git_vector_insert(&filelist, "L/1"));
g_repo = cl_git_sandbox_init("icase");
git_repository_head_tree(&tree, g_repo);
/* All indexfilelist iterator tests are "autoexpand with no tree entries" */
/* In this test we DO NOT force a case on the iterators and verify default behavior. */
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 8, NULL, 8, NULL);
git_iterator_free(i);
cl_assert(expected[idx] == NULL);
i_opts.start = "c";
i_opts.end = NULL;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
default_icase = git_iterator_ignore_case(i);
/* (c D e k/1 k/a L ==> 6) vs (c e k/1 k/a ==> 4) */
expect = ((default_icase) ? 6 : 4);
expect_iterator_items(i, expect, NULL, expect, NULL);
git_iterator_free(i);
i_opts.start = NULL;
i_opts.end = "e";
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
default_icase = git_iterator_ignore_case(i);
/* (a B c D e ==> 5) vs (B D L/1 a c e ==> 6) */
expect = ((default_icase) ? 5 : 6);
expect_iterator_items(i, expect, NULL, expect, NULL);
git_iterator_free(i);
}
void test_diff_iterator__workdir_handles_icase_range(void)
{
git_repository *repo;
repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_remove_placeholders(git_repository_path(repo), "dummy-marker.txt");
cl_git_mkfile("empty_standard_repo/before", "whatever\n");
cl_git_mkfile("empty_standard_repo/FIRST", "whatever\n");
cl_git_mkfile("empty_standard_repo/second", "whatever\n");
cl_git_mkfile("empty_standard_repo/THIRD", "whatever\n");
cl_git_mkfile("empty_standard_repo/zafter", "whatever\n");
cl_git_mkfile("empty_standard_repo/Zlast", "whatever\n");
check_wd_first_through_third_range(repo, "first", "third");
check_wd_first_through_third_range(repo, "FIRST", "THIRD");
check_wd_first_through_third_range(repo, "first", "THIRD");
check_wd_first_through_third_range(repo, "FIRST", "third");
check_wd_first_through_third_range(repo, "FirSt", "tHiRd");
git_vector_free(&filelist);
git_tree_free(tree);
}
static void check_tree_range(
git_repository *repo,
const char *start,
const char *end,
bool ignore_case,
int expected_count)
void test_iterator_tree__pathlist_icase(void)
{
git_tree *head;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
int error, count;
git_vector filelist;
git_tree *tree;
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "a"));
cl_git_pass(git_vector_insert(&filelist, "B"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k.a"));
cl_git_pass(git_vector_insert(&filelist, "k.b"));
cl_git_pass(git_vector_insert(&filelist, "k/1"));
cl_git_pass(git_vector_insert(&filelist, "k/a"));
cl_git_pass(git_vector_insert(&filelist, "kZZZZ"));
cl_git_pass(git_vector_insert(&filelist, "L/1"));
g_repo = cl_git_sandbox_init("icase");
git_repository_head_tree(&tree, g_repo);
i_opts.flags = ignore_case ? GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE;
i_opts.start = start;
i_opts.end = end;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
cl_git_pass(git_repository_head_tree(&head, repo));
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 3, NULL, 3, NULL);
git_iterator_free(i);
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 1, NULL, 1, NULL);
git_iterator_free(i);
for (count = 0; !(error = git_iterator_advance(NULL, i)); ++count)
/* count em up */;
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_assert_equal_i(GIT_ITEROVER, error);
cl_assert_equal_i(expected_count, count);
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 5, NULL, 5, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 2, NULL, 2, NULL);
git_iterator_free(i);
git_tree_free(head);
}
void test_diff_iterator__tree_handles_icase_range(void)
{
git_repository *repo;
repo = cl_git_sandbox_init("testrepo");
check_tree_range(repo, "B", "C", false, 0);
check_tree_range(repo, "B", "C", true, 1);
check_tree_range(repo, "b", "c", false, 1);
check_tree_range(repo, "b", "c", true, 1);
check_tree_range(repo, "a", "z", false, 3);
check_tree_range(repo, "a", "z", true, 4);
check_tree_range(repo, "A", "Z", false, 1);
check_tree_range(repo, "A", "Z", true, 4);
check_tree_range(repo, "a", "Z", false, 0);
check_tree_range(repo, "a", "Z", true, 4);
check_tree_range(repo, "A", "z", false, 4);
check_tree_range(repo, "A", "z", true, 4);
check_tree_range(repo, "new.txt", "new.txt", true, 1);
check_tree_range(repo, "new.txt", "new.txt", false, 1);
check_tree_range(repo, "README", "README", true, 1);
check_tree_range(repo, "README", "README", false, 1);
git_vector_free(&filelist);
git_tree_free(tree);
}
static void check_index_range(
git_repository *repo,
const char *start,
const char *end,
bool ignore_case,
int expected_count)
void test_iterator_tree__pathlist_with_directory(void)
{
git_index *index;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
int error, count, caps;
bool is_ignoring_case;
git_vector filelist;
git_tree *tree;
cl_git_pass(git_repository_index(&index, repo));
g_repo = cl_git_sandbox_init("testrepo2");
git_repository_head_tree(&tree, g_repo);
caps = git_index_caps(index);
is_ignoring_case = ((caps & GIT_INDEXCAP_IGNORE_CASE) != 0);
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "subdir"));
if (ignore_case != is_ignoring_case)
cl_git_pass(git_index_set_caps(index, caps ^ GIT_INDEXCAP_IGNORE_CASE));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = 0;
i_opts.start = start;
i_opts.end = end;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 4, NULL, 4, NULL);
git_iterator_free(i);
cl_git_pass(git_iterator_for_index(&i, repo, index, &i_opts));
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "subdir/"));
cl_assert(git_iterator_ignore_case(i) == ignore_case);
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
for (count = 0; !(error = git_iterator_advance(NULL, i)); ++count)
/* count em up */;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 4, NULL, 4, NULL);
git_iterator_free(i);
cl_assert_equal_i(GIT_ITEROVER, error);
cl_assert_equal_i(expected_count, count);
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "subdir/subdir2"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 2, NULL, 2, NULL);
git_iterator_free(i);
git_index_free(index);
git_vector_free(&filelist);
}
void test_diff_iterator__index_handles_icase_range(void)
void test_iterator_tree__pathlist_with_directory_include_tree_nodes(void)
{
git_repository *repo;
git_index *index;
git_tree *head;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
git_tree *tree;
repo = cl_git_sandbox_init("testrepo");
g_repo = cl_git_sandbox_init("testrepo2");
git_repository_head_tree(&tree, g_repo);
/* reset index to match HEAD */
cl_git_pass(git_repository_head_tree(&head, repo));
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_read_tree(index, head));
cl_git_pass(git_index_write(index));
git_tree_free(head);
git_index_free(index);
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "subdir"));
i_opts.flags |= GIT_ITERATOR_INCLUDE_TREES;
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
/* do some ranged iterator checks toggling case sensitivity */
check_index_range(repo, "B", "C", false, 0);
check_index_range(repo, "B", "C", true, 1);
check_index_range(repo, "a", "z", false, 3);
check_index_range(repo, "a", "z", true, 4);
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 6, NULL, 6, NULL);
git_iterator_free(i);
git_vector_free(&filelist);
}
void test_iterator_tree__pathlist_no_match(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
git_tree *tree;
const git_index_entry *entry;
g_repo = cl_git_sandbox_init("testrepo2");
git_repository_head_tree(&tree, g_repo);
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "nonexistent/"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
cl_assert_equal_i(GIT_ITEROVER, git_iterator_current(&entry, i));
git_vector_free(&filelist);
}
......@@ -3,735 +3,338 @@
#include "repository.h"
#include "fileops.h"
#include "../submodule/submodule_helpers.h"
#include "iterator_helpers.h"
#include <stdarg.h>
static git_repository *g_repo;
void test_repo_iterator__initialize(void)
void test_iterator_workdir__initialize(void)
{
}
void test_repo_iterator__cleanup(void)
void test_iterator_workdir__cleanup(void)
{
cl_git_sandbox_cleanup();
g_repo = NULL;
}
static void assert_at_end(git_iterator *i, bool verbose)
static void workdir_iterator_test(
const char *sandbox,
const char *start,
const char *end,
int expected_count,
int expected_ignores,
const char **expected_names,
const char *an_ignored_name)
{
const git_index_entry *end;
int error = git_iterator_advance(&end, i);
if (verbose && error != GIT_ITEROVER)
fprintf(stderr, "Expected end of iterator, got '%s'\n", end->path);
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry;
int error, count = 0, count_all = 0, count_all_post_reset = 0;
cl_git_fail_with(GIT_ITEROVER, error);
}
g_repo = cl_git_sandbox_init(sandbox);
static void expect_iterator_items(
git_iterator *i,
int expected_flat,
const char **expected_flat_paths,
int expected_total,
const char **expected_total_paths)
{
const git_index_entry *entry;
int count, error;
int no_trees = !(git_iterator_flags(i) & GIT_ITERATOR_INCLUDE_TREES);
bool v = false;
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = start;
i_opts.end = end;
if (expected_flat < 0) { v = true; expected_flat = -expected_flat; }
if (expected_total < 0) { v = true; expected_total = -expected_total; }
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
if (v) fprintf(stderr, "== %s ==\n", no_trees ? "notrees" : "trees");
error = git_iterator_current(&entry, i);
cl_assert((error == 0 && entry != NULL) ||
(error == GIT_ITEROVER && entry == NULL));
count = 0;
while (entry != NULL) {
int ignored = git_iterator_current_is_ignored(i);
while (!git_iterator_advance(&entry, i)) {
if (v) fprintf(stderr, " %s %07o\n", entry->path, (int)entry->mode);
if (S_ISDIR(entry->mode)) {
cl_git_pass(git_iterator_advance_into(&entry, i));
continue;
}
if (no_trees)
cl_assert(entry->mode != GIT_FILEMODE_TREE);
if (expected_names != NULL)
cl_assert_equal_s(expected_names[count_all], entry->path);
if (expected_flat_paths) {
const char *expect_path = expected_flat_paths[count];
size_t expect_len = strlen(expect_path);
if (an_ignored_name && strcmp(an_ignored_name,entry->path)==0)
cl_assert(ignored);
cl_assert_equal_s(expect_path, entry->path);
if (!ignored)
count++;
count_all++;
if (expect_path[expect_len - 1] == '/')
cl_assert_equal_i(GIT_FILEMODE_TREE, entry->mode);
else
cl_assert(entry->mode != GIT_FILEMODE_TREE);
}
error = git_iterator_advance(&entry, i);
if (++count >= expected_flat)
break;
cl_assert((error == 0 && entry != NULL) ||
(error == GIT_ITEROVER && entry == NULL));
}
assert_at_end(i, v);
cl_assert_equal_i(expected_flat, count);
cl_assert_equal_i(expected_count, count);
cl_assert_equal_i(expected_count + expected_ignores, count_all);
cl_git_pass(git_iterator_reset(i));
count = 0;
cl_git_pass(git_iterator_current(&entry, i));
if (v) fprintf(stderr, "-- %s --\n", no_trees ? "notrees" : "trees");
error = git_iterator_current(&entry, i);
cl_assert((error == 0 && entry != NULL) ||
(error == GIT_ITEROVER && entry == NULL));
while (entry != NULL) {
if (v) fprintf(stderr, " %s %07o\n", entry->path, (int)entry->mode);
if (no_trees)
cl_assert(entry->mode != GIT_FILEMODE_TREE);
if (expected_total_paths) {
const char *expect_path = expected_total_paths[count];
size_t expect_len = strlen(expect_path);
cl_assert_equal_s(expect_path, entry->path);
if (expect_path[expect_len - 1] == '/')
cl_assert_equal_i(GIT_FILEMODE_TREE, entry->mode);
else
cl_assert(entry->mode != GIT_FILEMODE_TREE);
if (S_ISDIR(entry->mode)) {
cl_git_pass(git_iterator_advance_into(&entry, i));
continue;
}
if (entry->mode == GIT_FILEMODE_TREE) {
error = git_iterator_advance_into(&entry, i);
if (expected_names != NULL)
cl_assert_equal_s(
expected_names[count_all_post_reset], entry->path);
count_all_post_reset++;
/* could return NOTFOUND if directory is empty */
cl_assert(!error || error == GIT_ENOTFOUND);
if (error == GIT_ENOTFOUND) {
error = git_iterator_advance(&entry, i);
cl_assert(!error || error == GIT_ITEROVER);
}
} else {
error = git_iterator_advance(&entry, i);
cl_assert(!error || error == GIT_ITEROVER);
}
if (++count >= expected_total)
break;
error = git_iterator_advance(&entry, i);
cl_assert(error == 0 || error == GIT_ITEROVER);
}
assert_at_end(i, v);
cl_assert_equal_i(expected_total, count);
}
/* Index contents (including pseudotrees):
*
* 0: a 5: F 10: k/ 16: L/
* 1: B 6: g 11: k/1 17: L/1
* 2: c 7: H 12: k/a 18: L/a
* 3: D 8: i 13: k/B 19: L/B
* 4: e 9: J 14: k/c 20: L/c
* 15: k/D 21: L/D
*
* 0: B 5: L/ 11: a 16: k/
* 1: D 6: L/1 12: c 17: k/1
* 2: F 7: L/B 13: e 18: k/B
* 3: H 8: L/D 14: g 19: k/D
* 4: J 9: L/a 15: i 20: k/a
* 10: L/c 21: k/c
*/
void test_repo_iterator__index(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
/* autoexpand with no tree entries for index */
cl_git_pass(git_iterator_for_index(&i, g_repo, index, NULL));
expect_iterator_items(i, 20, NULL, 20, NULL);
git_iterator_free(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 22, NULL, 22, NULL);
git_iterator_free(i);
cl_assert_equal_i(count_all, count_all_post_reset);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 12, NULL, 22, NULL);
git_iterator_free(i);
git_index_free(index);
}
void test_repo_iterator__index_icase(void)
void test_iterator_workdir__0(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
int caps;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
caps = git_index_caps(index);
/* force case sensitivity */
cl_git_pass(git_index_set_caps(index, caps & ~GIT_INDEXCAP_IGNORE_CASE));
/* autoexpand with no tree entries over range */
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 7, NULL, 7, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 3, NULL, 3, NULL);
git_iterator_free(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 8, NULL, 8, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 4, NULL, 4, NULL);
git_iterator_free(i);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 5, NULL, 8, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 1, NULL, 4, NULL);
git_iterator_free(i);
/* force case insensitivity */
cl_git_pass(git_index_set_caps(index, caps | GIT_INDEXCAP_IGNORE_CASE));
/* autoexpand with no tree entries over range */
i_opts.flags = 0;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 13, NULL, 13, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 5, NULL, 5, NULL);
git_iterator_free(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 14, NULL, 14, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 6, NULL, 6, NULL);
git_iterator_free(i);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 9, NULL, 14, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 1, NULL, 6, NULL);
git_iterator_free(i);
cl_git_pass(git_index_set_caps(index, caps));
git_index_free(index);
workdir_iterator_test("attr", NULL, NULL, 23, 5, NULL, "ign");
}
void test_repo_iterator__tree(void)
static const char *status_paths[] = {
"current_file",
"ignored_file",
"modified_file",
"new_file",
"staged_changes",
"staged_changes_modified_file",
"staged_delete_modified_file",
"staged_new_file",
"staged_new_file_modified_file",
"subdir.txt",
"subdir/current_file",
"subdir/modified_file",
"subdir/new_file",
"\xe8\xbf\x99",
NULL
};
void test_iterator_workdir__1(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_tree *head;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_head_tree(&head, g_repo));
/* auto expand with no tree entries */
cl_git_pass(git_iterator_for_tree(&i, head, NULL));
expect_iterator_items(i, 20, NULL, 20, NULL);
git_iterator_free(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 22, NULL, 22, NULL);
git_iterator_free(i);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 12, NULL, 22, NULL);
git_iterator_free(i);
git_tree_free(head);
workdir_iterator_test(
"status", NULL, NULL, 13, 1, status_paths, "ignored_file");
}
void test_repo_iterator__tree_icase(void)
{
git_iterator *i;
git_tree *head;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_head_tree(&head, g_repo));
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
/* auto expand with no tree entries */
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 7, NULL, 7, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 3, NULL, 3, NULL);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
/* auto expand with tree entries */
i_opts.start = "c";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 8, NULL, 8, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 4, NULL, 4, NULL);
git_iterator_free(i);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 5, NULL, 8, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 1, NULL, 4, NULL);
git_iterator_free(i);
/* auto expand with no tree entries */
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 13, NULL, 13, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 5, NULL, 5, NULL);
git_iterator_free(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 14, NULL, 14, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 6, NULL, 6, NULL);
git_iterator_free(i);
static const char *status_paths_range_0[] = {
"staged_changes",
"staged_changes_modified_file",
"staged_delete_modified_file",
"staged_new_file",
"staged_new_file_modified_file",
NULL
};
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 9, NULL, 14, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 1, NULL, 6, NULL);
git_iterator_free(i);
git_tree_free(head);
}
void test_repo_iterator__tree_more(void)
void test_iterator_workdir__1_ranged_0(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_tree *head;
static const char *expect_basic[] = {
"current_file",
"file_deleted",
"modified_file",
"staged_changes",
"staged_changes_file_deleted",
"staged_changes_modified_file",
"staged_delete_file_deleted",
"staged_delete_modified_file",
"subdir.txt",
"subdir/current_file",
"subdir/deleted_file",
"subdir/modified_file",
NULL,
};
static const char *expect_trees[] = {
"current_file",
"file_deleted",
"modified_file",
"staged_changes",
"staged_changes_file_deleted",
"staged_changes_modified_file",
"staged_delete_file_deleted",
"staged_delete_modified_file",
"subdir.txt",
"subdir/",
"subdir/current_file",
"subdir/deleted_file",
"subdir/modified_file",
NULL,
};
static const char *expect_noauto[] = {
"current_file",
"file_deleted",
"modified_file",
"staged_changes",
"staged_changes_file_deleted",
"staged_changes_modified_file",
"staged_delete_file_deleted",
"staged_delete_modified_file",
"subdir.txt",
"subdir/",
NULL
};
g_repo = cl_git_sandbox_init("status");
cl_git_pass(git_repository_head_tree(&head, g_repo));
/* auto expand with no tree entries */
cl_git_pass(git_iterator_for_tree(&i, head, NULL));
expect_iterator_items(i, 12, expect_basic, 12, expect_basic);
git_iterator_free(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 13, expect_trees, 13, expect_trees);
git_iterator_free(i);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 10, expect_noauto, 13, expect_trees);
git_iterator_free(i);
git_tree_free(head);
workdir_iterator_test(
"status", "staged", "staged", 5, 0, status_paths_range_0, NULL);
}
/* "b=name,t=name", blob_id, tree_id */
static void build_test_tree(
git_oid *out, git_repository *repo, const char *fmt, ...)
{
git_oid *id;
git_treebuilder *builder;
const char *scan = fmt, *next;
char type, delimiter;
git_filemode_t mode = GIT_FILEMODE_BLOB;
git_buf name = GIT_BUF_INIT;
va_list arglist;
cl_git_pass(git_treebuilder_new(&builder, repo, NULL)); /* start builder */
va_start(arglist, fmt);
while (*scan) {
switch (type = *scan++) {
case 't': case 'T': mode = GIT_FILEMODE_TREE; break;
case 'b': case 'B': mode = GIT_FILEMODE_BLOB; break;
default:
cl_assert(type == 't' || type == 'T' || type == 'b' || type == 'B');
}
delimiter = *scan++; /* read and skip delimiter */
for (next = scan; *next && *next != delimiter; ++next)
/* seek end */;
cl_git_pass(git_buf_set(&name, scan, (size_t)(next - scan)));
for (scan = next; *scan && (*scan == delimiter || *scan == ','); ++scan)
/* skip delimiter and optional comma */;
id = va_arg(arglist, git_oid *);
cl_git_pass(git_treebuilder_insert(NULL, builder, name.ptr, id, mode));
}
va_end(arglist);
cl_git_pass(git_treebuilder_write(out, builder));
static const char *status_paths_range_1[] = {
"modified_file", NULL
};
git_treebuilder_free(builder);
git_buf_free(&name);
}
void test_repo_iterator__tree_case_conflicts_0(void)
void test_iterator_workdir__1_ranged_1(void)
{
const char *blob_sha = "d44e18fb93b7107b5cd1b95d601591d77869a1b6";
git_tree *tree;
git_oid blob_id, biga_id, littlea_id, tree_id;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const char *expect_cs[] = {
"A/1.file", "A/3.file", "a/2.file", "a/4.file" };
const char *expect_ci[] = {
"A/1.file", "a/2.file", "A/3.file", "a/4.file" };
const char *expect_cs_trees[] = {
"A/", "A/1.file", "A/3.file", "a/", "a/2.file", "a/4.file" };
const char *expect_ci_trees[] = {
"A/", "A/1.file", "a/2.file", "A/3.file", "a/4.file" };
workdir_iterator_test(
"status", "modified_file", "modified_file",
1, 0, status_paths_range_1, NULL);
}
g_repo = cl_git_sandbox_init("icase");
static const char *status_paths_range_3[] = {
"subdir.txt",
"subdir/current_file",
"subdir/modified_file",
NULL
};
cl_git_pass(git_oid_fromstr(&blob_id, blob_sha)); /* lookup blob */
void test_iterator_workdir__1_ranged_3(void)
{
workdir_iterator_test(
"status", "subdir", "subdir/modified_file",
3, 0, status_paths_range_3, NULL);
}
/* create tree with: A/1.file, A/3.file, a/2.file, a/4.file */
build_test_tree(
&biga_id, g_repo, "b|1.file|,b|3.file|", &blob_id, &blob_id);
build_test_tree(
&littlea_id, g_repo, "b|2.file|,b|4.file|", &blob_id, &blob_id);
build_test_tree(
&tree_id, g_repo, "t|A|,t|a|", &biga_id, &littlea_id);
static const char *status_paths_range_4[] = {
"subdir/current_file",
"subdir/modified_file",
"subdir/new_file",
"\xe8\xbf\x99",
NULL
};
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
void test_iterator_workdir__1_ranged_4(void)
{
workdir_iterator_test(
"status", "subdir/", NULL, 4, 0, status_paths_range_4, NULL);
}
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 4, expect_cs, 4, expect_cs);
git_iterator_free(i);
static const char *status_paths_range_5[] = {
"subdir/modified_file",
NULL
};
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 4, expect_ci, 4, expect_ci);
git_iterator_free(i);
void test_iterator_workdir__1_ranged_5(void)
{
workdir_iterator_test(
"status", "subdir/modified_file", "subdir/modified_file",
1, 0, status_paths_range_5, NULL);
}
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 6, expect_cs_trees, 6, expect_cs_trees);
git_iterator_free(i);
void test_iterator_workdir__1_ranged_5_1_ranged_empty_0(void)
{
workdir_iterator_test(
"status", "\xff_does_not_exist", NULL,
0, 0, NULL, NULL);
}
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 5, expect_ci_trees, 5, expect_ci_trees);
git_iterator_free(i);
void test_iterator_workdir__1_ranged_empty_1(void)
{
workdir_iterator_test(
"status", "empty", "empty",
0, 0, NULL, NULL);
}
git_tree_free(tree);
void test_iterator_workdir__1_ranged_empty_2(void)
{
workdir_iterator_test(
"status", NULL, "aaaa_empty_before",
0, 0, NULL, NULL);
}
void test_repo_iterator__tree_case_conflicts_1(void)
void test_iterator_workdir__builtin_ignores(void)
{
const char *blob_sha = "d44e18fb93b7107b5cd1b95d601591d77869a1b6";
git_tree *tree;
git_oid blob_id, Ab_id, biga_id, littlea_id, tree_id;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry;
int idx;
static struct {
const char *path;
bool ignored;
} expected[] = {
{ "dir/", true },
{ "file", false },
{ "ign", true },
{ "macro_bad", false },
{ "macro_test", false },
{ "root_test1", false },
{ "root_test2", false },
{ "root_test3", false },
{ "root_test4.txt", false },
{ "sub/", false },
{ "sub/.gitattributes", false },
{ "sub/abc", false },
{ "sub/dir/", true },
{ "sub/file", false },
{ "sub/ign/", true },
{ "sub/sub/", false },
{ "sub/sub/.gitattributes", false },
{ "sub/sub/dir", false }, /* file is not actually a dir */
{ "sub/sub/file", false },
{ NULL, false }
};
const char *expect_cs[] = {
"A/a", "A/b/1", "A/c", "a/C", "a/a", "a/b" };
const char *expect_ci[] = {
"A/a", "a/b", "A/b/1", "A/c" };
const char *expect_cs_trees[] = {
"A/", "A/a", "A/b/", "A/b/1", "A/c", "a/", "a/C", "a/a", "a/b" };
const char *expect_ci_trees[] = {
"A/", "A/a", "a/b", "A/b/", "A/b/1", "A/c" };
g_repo = cl_git_sandbox_init("attr");
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(p_mkdir("attr/sub/sub/.git", 0777));
cl_git_mkfile("attr/sub/.git", "whatever");
cl_git_pass(git_oid_fromstr(&blob_id, blob_sha)); /* lookup blob */
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = "dir";
i_opts.end = "sub/sub/file";
/* create: A/a A/b/1 A/c a/a a/b a/C */
build_test_tree(&Ab_id, g_repo, "b|1|", &blob_id);
build_test_tree(
&biga_id, g_repo, "b|a|,t|b|,b|c|", &blob_id, &Ab_id, &blob_id);
build_test_tree(
&littlea_id, g_repo, "b|a|,b|b|,b|C|", &blob_id, &blob_id, &blob_id);
build_test_tree(
&tree_id, g_repo, "t|A|,t|a|", &biga_id, &littlea_id);
cl_git_pass(git_iterator_for_workdir(
&i, g_repo, NULL, NULL, &i_opts));
cl_git_pass(git_iterator_current(&entry, i));
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
for (idx = 0; entry != NULL; ++idx) {
int ignored = git_iterator_current_is_ignored(i);
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 6, expect_cs, 6, expect_cs);
git_iterator_free(i);
cl_assert_equal_s(expected[idx].path, entry->path);
cl_assert_(ignored == expected[idx].ignored, expected[idx].path);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 4, expect_ci, 4, expect_ci);
git_iterator_free(i);
if (!ignored &&
(entry->mode == GIT_FILEMODE_TREE ||
entry->mode == GIT_FILEMODE_COMMIT))
{
/* it is possible to advance "into" a submodule */
cl_git_pass(git_iterator_advance_into(&entry, i));
} else {
int error = git_iterator_advance(&entry, i);
cl_assert(!error || error == GIT_ITEROVER);
}
}
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 9, expect_cs_trees, 9, expect_cs_trees);
git_iterator_free(i);
cl_assert(expected[idx].path == NULL);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 6, expect_ci_trees, 6, expect_ci_trees);
git_iterator_free(i);
git_tree_free(tree);
}
void test_repo_iterator__tree_case_conflicts_2(void)
static void check_wd_first_through_third_range(
git_repository *repo, const char *start, const char *end)
{
const char *blob_sha = "d44e18fb93b7107b5cd1b95d601591d77869a1b6";
git_tree *tree;
git_oid blob_id, d1, d2, c1, c2, b1, b2, a1, a2, tree_id;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry;
int error, idx;
static const char *expected[] = { "FIRST", "second", "THIRD", NULL };
const char *expect_cs[] = {
"A/B/C/D/16", "A/B/C/D/foo", "A/B/C/d/15", "A/B/C/d/FOO",
"A/B/c/D/14", "A/B/c/D/foo", "A/B/c/d/13", "A/B/c/d/FOO",
"A/b/C/D/12", "A/b/C/D/foo", "A/b/C/d/11", "A/b/C/d/FOO",
"A/b/c/D/10", "A/b/c/D/foo", "A/b/c/d/09", "A/b/c/d/FOO",
"a/B/C/D/08", "a/B/C/D/foo", "a/B/C/d/07", "a/B/C/d/FOO",
"a/B/c/D/06", "a/B/c/D/foo", "a/B/c/d/05", "a/B/c/d/FOO",
"a/b/C/D/04", "a/b/C/D/foo", "a/b/C/d/03", "a/b/C/d/FOO",
"a/b/c/D/02", "a/b/c/D/foo", "a/b/c/d/01", "a/b/c/d/FOO", };
const char *expect_ci[] = {
"a/b/c/d/01", "a/b/c/D/02", "a/b/C/d/03", "a/b/C/D/04",
"a/B/c/d/05", "a/B/c/D/06", "a/B/C/d/07", "a/B/C/D/08",
"A/b/c/d/09", "A/b/c/D/10", "A/b/C/d/11", "A/b/C/D/12",
"A/B/c/d/13", "A/B/c/D/14", "A/B/C/d/15", "A/B/C/D/16",
"A/B/C/D/foo", };
const char *expect_ci_trees[] = {
"A/", "A/B/", "A/B/C/", "A/B/C/D/",
"a/b/c/d/01", "a/b/c/D/02", "a/b/C/d/03", "a/b/C/D/04",
"a/B/c/d/05", "a/B/c/D/06", "a/B/C/d/07", "a/B/C/D/08",
"A/b/c/d/09", "A/b/c/D/10", "A/b/C/d/11", "A/b/C/D/12",
"A/B/c/d/13", "A/B/c/D/14", "A/B/C/d/15", "A/B/C/D/16",
"A/B/C/D/foo", };
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_oid_fromstr(&blob_id, blob_sha)); /* lookup blob */
build_test_tree(&d1, g_repo, "b|16|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|15|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c1, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&d1, g_repo, "b|14|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|13|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c2, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&b1, g_repo, "t|C|,t|c|", &c1, &c2);
build_test_tree(&d1, g_repo, "b|12|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|11|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c1, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&d1, g_repo, "b|10|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|09|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c2, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&b2, g_repo, "t|C|,t|c|", &c1, &c2);
build_test_tree(&a1, g_repo, "t|B|,t|b|", &b1, &b2);
build_test_tree(&d1, g_repo, "b|08|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|07|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c1, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&d1, g_repo, "b|06|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|05|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c2, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&b1, g_repo, "t|C|,t|c|", &c1, &c2);
build_test_tree(&d1, g_repo, "b|04|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|03|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c1, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&d1, g_repo, "b|02|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|01|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c2, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&b2, g_repo, "t|C|,t|c|", &c1, &c2);
build_test_tree(&a2, g_repo, "t|B|,t|b|", &b1, &b2);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
i_opts.start = start;
i_opts.end = end;
build_test_tree(&tree_id, g_repo, "t/A/,t/a/", &a1, &a2);
cl_git_pass(git_iterator_for_workdir(
&i, repo, NULL, NULL, &i_opts));
cl_git_pass(git_iterator_current(&entry, i));
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
for (idx = 0; entry != NULL; ++idx) {
cl_assert_equal_s(expected[idx], entry->path);
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 32, expect_cs, 32, expect_cs);
git_iterator_free(i);
error = git_iterator_advance(&entry, i);
cl_assert(!error || error == GIT_ITEROVER);
}
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 17, expect_ci, 17, expect_ci);
git_iterator_free(i);
cl_assert(expected[idx] == NULL);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 21, expect_ci_trees, 21, expect_ci_trees);
git_iterator_free(i);
}
git_tree_free(tree);
void test_iterator_workdir__handles_icase_range(void)
{
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_remove_placeholders(git_repository_path(g_repo), "dummy-marker.txt");
cl_git_mkfile("empty_standard_repo/before", "whatever\n");
cl_git_mkfile("empty_standard_repo/FIRST", "whatever\n");
cl_git_mkfile("empty_standard_repo/second", "whatever\n");
cl_git_mkfile("empty_standard_repo/THIRD", "whatever\n");
cl_git_mkfile("empty_standard_repo/zafter", "whatever\n");
cl_git_mkfile("empty_standard_repo/Zlast", "whatever\n");
check_wd_first_through_third_range(g_repo, "first", "third");
check_wd_first_through_third_range(g_repo, "FIRST", "THIRD");
check_wd_first_through_third_range(g_repo, "first", "THIRD");
check_wd_first_through_third_range(g_repo, "FIRST", "third");
check_wd_first_through_third_range(g_repo, "FirSt", "tHiRd");
}
void test_repo_iterator__workdir(void)
/*
* The workdir iterator is like the filesystem iterator, but honors
* special git type constructs (ignores, submodules, etc).
*/
void test_iterator_workdir__icase(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
......@@ -756,7 +359,7 @@ void test_repo_iterator__workdir(void)
git_iterator_free(i);
}
void test_repo_iterator__workdir_icase(void)
void test_iterator_workdir__icase_starts_and_ends(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
......@@ -891,7 +494,7 @@ static void build_workdir_tree(const char *root, int dirs, int subs)
}
}
void test_repo_iterator__workdir_depth(void)
void test_iterator_workdir__depth(void)
{
git_iterator *iter;
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
......@@ -914,7 +517,10 @@ void test_repo_iterator__workdir_depth(void)
git_iterator_free(iter);
}
void test_repo_iterator__fs(void)
/* The filesystem iterator is a workdir iterator without any special
* workdir handling capabilities (ignores, submodules, etc).
*/
void test_iterator_workdir__filesystem(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
......@@ -998,7 +604,7 @@ void test_repo_iterator__fs(void)
git_iterator_free(i);
}
void test_repo_iterator__fs2(void)
void test_iterator_workdir__filesystem2(void)
{
git_iterator *i;
static const char *expect_base[] = {
......@@ -1026,7 +632,10 @@ void test_repo_iterator__fs2(void)
git_iterator_free(i);
}
void test_repo_iterator__fs_gunk(void)
/* Lots of empty dirs, or nearly empty ones, make the old workdir
* iterator cry. Also, segfault.
*/
void test_iterator_workdir__filesystem_gunk(void)
{
git_iterator *i;
git_buf parent = GIT_BUF_INIT;
......@@ -1037,366 +646,98 @@ void test_repo_iterator__fs_gunk(void)
g_repo = cl_git_sandbox_init("testrepo");
for (n = 0; n < 100000; n++) {
git_buf_clear(&parent);
git_buf_printf(&parent, "%s/refs/heads/foo/%d/subdir",
git_repository_path(g_repo), n);
cl_assert(!git_buf_oom(&parent));
cl_git_pass(git_futils_mkdir(parent.ptr, 0775, GIT_MKDIR_PATH));
}
cl_git_pass(git_iterator_for_filesystem(&i, "testrepo/.git/refs", NULL));
/* should only have 13 items, since we're not asking for trees to be
* returned. the goal of this test is simply to not crash.
*/
expect_iterator_items(i, 13, NULL, 13, NULL);
git_iterator_free(i);
git_buf_free(&parent);
}
void test_repo_iterator__skips_unreadable_dirs(void)
{
git_iterator *i;
const git_index_entry *e;
if (!cl_is_chmod_supported())
return;
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_must_pass(p_mkdir("empty_standard_repo/r", 0777));
cl_git_mkfile("empty_standard_repo/r/a", "hello");
cl_must_pass(p_mkdir("empty_standard_repo/r/b", 0777));
cl_git_mkfile("empty_standard_repo/r/b/problem", "not me");
cl_must_pass(p_chmod("empty_standard_repo/r/b", 0000));
cl_must_pass(p_mkdir("empty_standard_repo/r/c", 0777));
cl_git_mkfile("empty_standard_repo/r/c/foo", "aloha");
cl_git_mkfile("empty_standard_repo/r/d", "final");
cl_git_pass(git_iterator_for_filesystem(
&i, "empty_standard_repo/r", NULL));
cl_git_pass(git_iterator_advance(&e, i)); /* a */
cl_assert_equal_s("a", e->path);
cl_git_pass(git_iterator_advance(&e, i)); /* c/foo */
cl_assert_equal_s("c/foo", e->path);
cl_git_pass(git_iterator_advance(&e, i)); /* d */
cl_assert_equal_s("d", e->path);
cl_must_pass(p_chmod("empty_standard_repo/r/b", 0777));
git_iterator_free(i);
}
void test_repo_iterator__skips_fifos_and_such(void)
{
#ifndef GIT_WIN32
git_iterator *i;
const git_index_entry *e;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_must_pass(p_mkdir("empty_standard_repo/dir", 0777));
cl_git_mkfile("empty_standard_repo/file", "not me");
cl_assert(!mkfifo("empty_standard_repo/fifo", 0777));
cl_assert(!access("empty_standard_repo/fifo", F_OK));
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES |
GIT_ITERATOR_DONT_AUTOEXPAND;
cl_git_pass(git_iterator_for_filesystem(
&i, "empty_standard_repo", &i_opts));
cl_git_pass(git_iterator_advance(&e, i)); /* .git */
cl_assert(S_ISDIR(e->mode));
cl_git_pass(git_iterator_advance(&e, i)); /* dir */
cl_assert(S_ISDIR(e->mode));
/* skips fifo */
cl_git_pass(git_iterator_advance(&e, i)); /* file */
cl_assert(S_ISREG(e->mode));
cl_assert_equal_i(GIT_ITEROVER, git_iterator_advance(&e, i));
git_iterator_free(i);
#endif
}
void test_repo_iterator__indexfilelist(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
git_vector filelist;
int default_icase;
int expect;
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "a"));
cl_git_pass(git_vector_insert(&filelist, "B"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k/1"));
cl_git_pass(git_vector_insert(&filelist, "k/a"));
cl_git_pass(git_vector_insert(&filelist, "L/1"));
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
/* In this test we DO NOT force a case setting on the index. */
default_icase = ((git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0);
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
/* All indexfilelist iterator tests are "autoexpand with no tree entries" */
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 8, NULL, 8, NULL);
git_iterator_free(i);
i_opts.start = "c";
i_opts.end = NULL;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
/* (c D e k/1 k/a L ==> 6) vs (c e k/1 k/a ==> 4) */
expect = ((default_icase) ? 6 : 4);
expect_iterator_items(i, expect, NULL, expect, NULL);
git_iterator_free(i);
i_opts.start = NULL;
i_opts.end = "e";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
/* (a B c D e ==> 5) vs (B D L/1 a c e ==> 6) */
expect = ((default_icase) ? 5 : 6);
expect_iterator_items(i, expect, NULL, expect, NULL);
git_iterator_free(i);
git_index_free(index);
git_vector_free(&filelist);
}
void test_repo_iterator__indexfilelist_2(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
git_vector filelist = GIT_VECTOR_INIT;
int default_icase, expect;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "0"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k/1"));
cl_git_pass(git_vector_insert(&filelist, "k/a"));
/* In this test we DO NOT force a case setting on the index. */
default_icase = ((git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0);
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.start = "b";
i_opts.end = "k/D";
/* (c D e k/1 k/a ==> 5) vs (c e k/1 ==> 3) */
expect = default_icase ? 5 : 3;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expect, NULL, expect, NULL);
git_iterator_free(i);
git_index_free(index);
git_vector_free(&filelist);
}
void test_repo_iterator__indexfilelist_3(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
git_vector filelist = GIT_VECTOR_INIT;
int default_icase, expect;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "0"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k/"));
cl_git_pass(git_vector_insert(&filelist, "k.a"));
cl_git_pass(git_vector_insert(&filelist, "k.b"));
cl_git_pass(git_vector_insert(&filelist, "kZZZZZZZ"));
/* In this test we DO NOT force a case setting on the index. */
default_icase = ((git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0);
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.start = "b";
i_opts.end = "k/D";
/* (c D e k/1 k/a k/B k/c k/D) vs (c e k/1 k/B k/D) */
expect = default_icase ? 8 : 5;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expect, NULL, expect, NULL);
git_iterator_free(i);
git_index_free(index);
git_vector_free(&filelist);
}
void test_repo_iterator__indexfilelist_4(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
git_vector filelist = GIT_VECTOR_INIT;
int default_icase, expect;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "0"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k"));
cl_git_pass(git_vector_insert(&filelist, "k.a"));
cl_git_pass(git_vector_insert(&filelist, "k.b"));
cl_git_pass(git_vector_insert(&filelist, "kZZZZZZZ"));
/* In this test we DO NOT force a case setting on the index. */
default_icase = ((git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0);
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
for (n = 0; n < 100000; n++) {
git_buf_clear(&parent);
git_buf_printf(&parent, "%s/refs/heads/foo/%d/subdir",
git_repository_path(g_repo), n);
cl_assert(!git_buf_oom(&parent));
i_opts.start = "b";
i_opts.end = "k/D";
cl_git_pass(git_futils_mkdir(parent.ptr, 0775, GIT_MKDIR_PATH));
}
/* (c D e k/1 k/a k/B k/c k/D) vs (c e k/1 k/B k/D) */
expect = default_icase ? 8 : 5;
cl_git_pass(git_iterator_for_filesystem(&i, "testrepo/.git/refs", NULL));
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expect, NULL, expect, NULL);
/* should only have 13 items, since we're not asking for trees to be
* returned. the goal of this test is simply to not crash.
*/
expect_iterator_items(i, 13, NULL, 13, NULL);
git_iterator_free(i);
git_index_free(index);
git_vector_free(&filelist);
git_buf_free(&parent);
}
void test_repo_iterator__indexfilelist_icase(void)
void test_iterator_workdir__skips_unreadable_dirs(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
int caps;
git_vector filelist;
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "a"));
cl_git_pass(git_vector_insert(&filelist, "B"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k/1"));
cl_git_pass(git_vector_insert(&filelist, "k/a"));
cl_git_pass(git_vector_insert(&filelist, "L/1"));
g_repo = cl_git_sandbox_init("icase");
const git_index_entry *e;
cl_git_pass(git_repository_index(&index, g_repo));
caps = git_index_caps(index);
if (!cl_is_chmod_supported())
return;
/* force case sensitivity */
cl_git_pass(git_index_set_caps(index, caps & ~GIT_INDEXCAP_IGNORE_CASE));
g_repo = cl_git_sandbox_init("empty_standard_repo");
/* All indexfilelist iterator tests are "autoexpand with no tree entries" */
cl_must_pass(p_mkdir("empty_standard_repo/r", 0777));
cl_git_mkfile("empty_standard_repo/r/a", "hello");
cl_must_pass(p_mkdir("empty_standard_repo/r/b", 0777));
cl_git_mkfile("empty_standard_repo/r/b/problem", "not me");
cl_must_pass(p_chmod("empty_standard_repo/r/b", 0000));
cl_must_pass(p_mkdir("empty_standard_repo/r/c", 0777));
cl_git_mkfile("empty_standard_repo/r/c/foo", "aloha");
cl_git_mkfile("empty_standard_repo/r/d", "final");
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
cl_git_pass(git_iterator_for_filesystem(
&i, "empty_standard_repo/r", NULL));
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 3, NULL, 3, NULL);
git_iterator_free(i);
cl_git_pass(git_iterator_advance(&e, i)); /* a */
cl_assert_equal_s("a", e->path);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 1, NULL, 1, NULL);
git_iterator_free(i);
cl_git_pass(git_iterator_advance(&e, i)); /* c/foo */
cl_assert_equal_s("c/foo", e->path);
/* force case insensitivity */
cl_git_pass(git_index_set_caps(index, caps | GIT_INDEXCAP_IGNORE_CASE));
cl_git_pass(git_iterator_advance(&e, i)); /* d */
cl_assert_equal_s("d", e->path);
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 5, NULL, 5, NULL);
git_iterator_free(i);
cl_must_pass(p_chmod("empty_standard_repo/r/b", 0777));
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 2, NULL, 2, NULL);
cl_assert_equal_i(GIT_ITEROVER, git_iterator_advance(&e, i));
git_iterator_free(i);
cl_git_pass(git_index_set_caps(index, caps));
git_index_free(index);
git_vector_free(&filelist);
}
void test_repo_iterator__indexfilelist_with_directory(void)
void test_iterator_workdir__skips_fifos_and_special_files(void)
{
#ifndef GIT_WIN32
git_iterator *i;
const git_index_entry *e;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
git_tree *tree;
git_index *index;
g_repo = cl_git_sandbox_init("testrepo2");
git_repository_head_tree(&tree, g_repo);
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "subdir"));
cl_must_pass(p_mkdir("empty_standard_repo/dir", 0777));
cl_git_mkfile("empty_standard_repo/file", "not me");
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
cl_assert(!mkfifo("empty_standard_repo/fifo", 0777));
cl_assert(!access("empty_standard_repo/fifo", F_OK));
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES |
GIT_ITERATOR_DONT_AUTOEXPAND;
cl_git_pass(git_iterator_for_filesystem(
&i, "empty_standard_repo", &i_opts));
cl_git_pass(git_iterator_advance(&e, i)); /* .git */
cl_assert(S_ISDIR(e->mode));
cl_git_pass(git_iterator_advance(&e, i)); /* dir */
cl_assert(S_ISDIR(e->mode));
/* skips fifo */
cl_git_pass(git_iterator_advance(&e, i)); /* file */
cl_assert(S_ISREG(e->mode));
cl_assert_equal_i(GIT_ITEROVER, git_iterator_advance(&e, i));
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 4, NULL, 4, NULL);
git_iterator_free(i);
git_index_free(index);
git_vector_free(&filelist);
#endif
}
void test_repo_iterator__workdir_pathlist(void)
void test_iterator_workdir__pathlist(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
......@@ -1417,9 +758,7 @@ void test_repo_iterator__workdir_pathlist(void)
g_repo = cl_git_sandbox_init("icase");
/* Test iterators with default case sensitivity, without returning
* tree entries (but autoexpanding.
*/
/* Test iterators without returning tree entries (but autoexpanding.) */
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
......@@ -1569,7 +908,7 @@ void test_repo_iterator__workdir_pathlist(void)
git_vector_free(&filelist);
}
void test_repo_iterator__workdir_pathlist_with_dirs(void)
void test_iterator_workdir__pathlist_with_dirs(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
......@@ -1693,7 +1032,7 @@ static void create_paths(const char *root, int depth)
}
}
void test_repo_iterator__workdir_pathlist_for_deeply_nested_item(void)
void test_iterator_workdir__pathlist_for_deeply_nested_item(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
......@@ -1825,7 +1164,7 @@ void test_repo_iterator__workdir_pathlist_for_deeply_nested_item(void)
git_vector_free(&filelist);
}
void test_repo_iterator__workdir_bounded_submodules(void)
void test_iterator_workdir__bounded_submodules(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
......@@ -1921,7 +1260,7 @@ static void expect_advance_over(
cl_assert_equal_i(expected_status, status);
}
void test_repo_iterator__workdir_advance_over(void)
void test_iterator_workdir__advance_over(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
......@@ -1981,7 +1320,7 @@ void test_repo_iterator__workdir_advance_over(void)
git_iterator_free(i);
}
void test_repo_iterator__workdir_advance_over_with_pathlist(void)
void test_iterator_workdir__advance_over_with_pathlist(void)
{
git_vector pathlist = GIT_VECTOR_INIT;
git_iterator *i;
......@@ -2059,7 +1398,7 @@ static void expect_advance_into(
cl_assert(!error || error == GIT_ITEROVER);
}
void test_repo_iterator__workdir_advance_into(void)
void test_iterator_workdir__advance_into(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
......@@ -2100,7 +1439,7 @@ void test_repo_iterator__workdir_advance_into(void)
git_iterator_free(i);
}
void test_repo_iterator__workdir_filelist_with_directory(void)
void test_iterator_workdir__pathlist_with_directory(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
......@@ -2121,207 +1460,3 @@ void test_repo_iterator__workdir_filelist_with_directory(void)
git_vector_free(&filelist);
}
void test_repo_iterator__treefilelist(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
git_tree *tree;
bool default_icase;
int expect;
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "a"));
cl_git_pass(git_vector_insert(&filelist, "B"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k.a"));
cl_git_pass(git_vector_insert(&filelist, "k.b"));
cl_git_pass(git_vector_insert(&filelist, "k/1"));
cl_git_pass(git_vector_insert(&filelist, "k/a"));
cl_git_pass(git_vector_insert(&filelist, "kZZZZZZZ"));
cl_git_pass(git_vector_insert(&filelist, "L/1"));
g_repo = cl_git_sandbox_init("icase");
git_repository_head_tree(&tree, g_repo);
/* All indexfilelist iterator tests are "autoexpand with no tree entries" */
/* In this test we DO NOT force a case on the iterators and verify default behavior. */
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 8, NULL, 8, NULL);
git_iterator_free(i);
i_opts.start = "c";
i_opts.end = NULL;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
default_icase = git_iterator_ignore_case(i);
/* (c D e k/1 k/a L ==> 6) vs (c e k/1 k/a ==> 4) */
expect = ((default_icase) ? 6 : 4);
expect_iterator_items(i, expect, NULL, expect, NULL);
git_iterator_free(i);
i_opts.start = NULL;
i_opts.end = "e";
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
default_icase = git_iterator_ignore_case(i);
/* (a B c D e ==> 5) vs (B D L/1 a c e ==> 6) */
expect = ((default_icase) ? 5 : 6);
expect_iterator_items(i, expect, NULL, expect, NULL);
git_iterator_free(i);
git_vector_free(&filelist);
git_tree_free(tree);
}
void test_repo_iterator__treefilelist_icase(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
git_tree *tree;
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "a"));
cl_git_pass(git_vector_insert(&filelist, "B"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k.a"));
cl_git_pass(git_vector_insert(&filelist, "k.b"));
cl_git_pass(git_vector_insert(&filelist, "k/1"));
cl_git_pass(git_vector_insert(&filelist, "k/a"));
cl_git_pass(git_vector_insert(&filelist, "kZZZZ"));
cl_git_pass(git_vector_insert(&filelist, "L/1"));
g_repo = cl_git_sandbox_init("icase");
git_repository_head_tree(&tree, g_repo);
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 3, NULL, 3, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 1, NULL, 1, NULL);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 5, NULL, 5, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 2, NULL, 2, NULL);
git_iterator_free(i);
git_vector_free(&filelist);
git_tree_free(tree);
}
void test_repo_iterator__tree_filelist_with_directory(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
git_tree *tree;
g_repo = cl_git_sandbox_init("testrepo2");
git_repository_head_tree(&tree, g_repo);
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "subdir"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 4, NULL, 4, NULL);
git_iterator_free(i);
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "subdir/"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 4, NULL, 4, NULL);
git_iterator_free(i);
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "subdir/subdir2"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 2, NULL, 2, NULL);
git_iterator_free(i);
git_vector_free(&filelist);
}
void test_repo_iterator__tree_filelist_with_directory_include_tree_nodes(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
git_tree *tree;
g_repo = cl_git_sandbox_init("testrepo2");
git_repository_head_tree(&tree, g_repo);
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "subdir"));
i_opts.flags |= GIT_ITERATOR_INCLUDE_TREES;
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 6, NULL, 6, NULL);
git_iterator_free(i);
git_vector_free(&filelist);
}
void test_repo_iterator__tree_filelist_no_match(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
git_tree *tree;
const git_index_entry *entry;
g_repo = cl_git_sandbox_init("testrepo2");
git_repository_head_tree(&tree, g_repo);
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "nonexistent/"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
cl_assert_equal_i(GIT_ITEROVER, git_iterator_current(&entry, i));
git_vector_free(&filelist);
}
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