iterator: test workdir pathlist with deep paths In the workdir iterator we do some tricky things to step down into directories to look for things that are in our pathlist. Make sure that we don't confuse between folders that we're definitely going to return everything in and folders that we're only stepping down into to keep looking for matches.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
diff --git a/tests/repo/iterator.c b/tests/repo/iterator.c
index c498679..9b87475 100644
--- a/tests/repo/iterator.c
+++ b/tests/repo/iterator.c
@@ -1641,6 +1641,165 @@ void test_repo_iterator__workdir_pathlist_with_dirs(void)
git_vector_free(&filelist);
}
+static void create_paths(const char *root, int depth)
+{
+ git_buf fullpath = GIT_BUF_INIT;
+ size_t root_len;
+ int i;
+
+ cl_git_pass(git_buf_puts(&fullpath, root));
+ cl_git_pass(git_buf_putc(&fullpath, '/'));
+
+ root_len = fullpath.size;
+
+ for (i = 0; i < 8; i++) {
+ bool file = (depth == 0 || (i % 2) == 0);
+ git_buf_truncate(&fullpath, root_len);
+ cl_git_pass(git_buf_printf(&fullpath, "item%d", i));
+
+ if (file) {
+ cl_git_rewritefile(fullpath.ptr, "This is a file!\n");
+ } else {
+ cl_must_pass(p_mkdir(fullpath.ptr, 0777));
+
+ if (depth > 0)
+ create_paths(fullpath.ptr, (depth - 1));
+ }
+ }
+}
+
+void test_repo_iterator__workdir_pathlist_for_deeply_nested_item(void)
+{
+ git_iterator *i;
+ git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
+ git_vector filelist;
+
+ cl_git_pass(git_vector_init(&filelist, 5, NULL));
+
+ g_repo = cl_git_sandbox_init("icase");
+ create_paths(git_repository_workdir(g_repo), 3);
+
+ /* Ensure that we find the single path we're interested in, and we find
+ * it efficiently, and don't stat the entire world to get there.
+ */
+ {
+ const char *expected[] = { "item1/item3/item5/item7" };
+ size_t expected_len = 1;
+
+ git_vector_clear(&filelist);
+ cl_git_pass(git_vector_insert(&filelist, "item1/item3/item5/item7"));
+
+ i_opts.pathlist.strings = (char **)filelist.contents;
+ i_opts.pathlist.count = filelist.length;
+ i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
+
+ cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
+ expect_iterator_items(i, expected_len, expected, expected_len, expected);
+ cl_assert_equal_i(4, i->stat_calls);
+ git_iterator_free(i);
+ }
+
+ /* Ensure that we find the single path we're interested in, and we find
+ * it efficiently, and don't stat the entire world to get there.
+ */
+ {
+ const char *expected[] = {
+ "item1/item3/item5/item0", "item1/item3/item5/item1",
+ "item1/item3/item5/item2", "item1/item3/item5/item3",
+ "item1/item3/item5/item4", "item1/item3/item5/item5",
+ "item1/item3/item5/item6", "item1/item3/item5/item7",
+ };
+ size_t expected_len = 8;
+
+ git_vector_clear(&filelist);
+ cl_git_pass(git_vector_insert(&filelist, "item1/item3/item5/"));
+
+ i_opts.pathlist.strings = (char **)filelist.contents;
+ i_opts.pathlist.count = filelist.length;
+ i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
+
+ cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
+ expect_iterator_items(i, expected_len, expected, expected_len, expected);
+ cl_assert_equal_i(11, i->stat_calls);
+ git_iterator_free(i);
+ }
+
+ /* Ensure that we find the single path we're interested in, and we find
+ * it efficiently, and don't stat the entire world to get there.
+ */
+ {
+ const char *expected[] = {
+ "item1/item3/item0",
+ "item1/item3/item1/item0", "item1/item3/item1/item1",
+ "item1/item3/item1/item2", "item1/item3/item1/item3",
+ "item1/item3/item1/item4", "item1/item3/item1/item5",
+ "item1/item3/item1/item6", "item1/item3/item1/item7",
+ "item1/item3/item2",
+ "item1/item3/item3/item0", "item1/item3/item3/item1",
+ "item1/item3/item3/item2", "item1/item3/item3/item3",
+ "item1/item3/item3/item4", "item1/item3/item3/item5",
+ "item1/item3/item3/item6", "item1/item3/item3/item7",
+ "item1/item3/item4",
+ "item1/item3/item5/item0", "item1/item3/item5/item1",
+ "item1/item3/item5/item2", "item1/item3/item5/item3",
+ "item1/item3/item5/item4", "item1/item3/item5/item5",
+ "item1/item3/item5/item6", "item1/item3/item5/item7",
+ "item1/item3/item6",
+ "item1/item3/item7/item0", "item1/item3/item7/item1",
+ "item1/item3/item7/item2", "item1/item3/item7/item3",
+ "item1/item3/item7/item4", "item1/item3/item7/item5",
+ "item1/item3/item7/item6", "item1/item3/item7/item7",
+ };
+ size_t expected_len = 36;
+
+ git_vector_clear(&filelist);
+ cl_git_pass(git_vector_insert(&filelist, "item1/item3/"));
+
+ i_opts.pathlist.strings = (char **)filelist.contents;
+ i_opts.pathlist.count = filelist.length;
+ i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
+
+ cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
+ expect_iterator_items(i, expected_len, expected, expected_len, expected);
+ cl_assert_equal_i(42, i->stat_calls);
+ git_iterator_free(i);
+ }
+
+ /* Ensure that we find the single path we're interested in, and we find
+ * it efficiently, and don't stat the entire world to get there.
+ */
+ {
+ const char *expected[] = {
+ "item0", "item1/item2", "item5/item7/item4", "item6",
+ "item7/item3/item1/item6" };
+ size_t expected_len = 5;
+
+ git_vector_clear(&filelist);
+ cl_git_pass(git_vector_insert(&filelist, "item7/item3/item1/item6"));
+ cl_git_pass(git_vector_insert(&filelist, "item6"));
+ cl_git_pass(git_vector_insert(&filelist, "item5/item7/item4"));
+ cl_git_pass(git_vector_insert(&filelist, "item1/item2"));
+ cl_git_pass(git_vector_insert(&filelist, "item0"));
+
+ /* also add some things that don't exist or don't match the right type */
+ cl_git_pass(git_vector_insert(&filelist, "item2/"));
+ cl_git_pass(git_vector_insert(&filelist, "itemN"));
+ cl_git_pass(git_vector_insert(&filelist, "item1/itemA"));
+ cl_git_pass(git_vector_insert(&filelist, "item5/item3/item4/"));
+
+ i_opts.pathlist.strings = (char **)filelist.contents;
+ i_opts.pathlist.count = filelist.length;
+ i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
+
+ cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
+ expect_iterator_items(i, expected_len, expected, expected_len, expected);
+ cl_assert_equal_i(14, i->stat_calls);
+ git_iterator_free(i);
+ }
+
+ git_vector_free(&filelist);
+}
+
void test_repo_iterator__workdir_bounded_submodules(void)
{
git_iterator *i;