summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/buffer.h11
-rw-r--r--src/checkout.c48
-rw-r--r--src/diff.c66
-rw-r--r--src/hashsig.c21
-rw-r--r--src/index.c51
-rw-r--r--src/index.h3
-rw-r--r--src/iterator.c1156
-rw-r--r--src/iterator.h153
-rw-r--r--src/notes.c6
-rw-r--r--src/posix.h3
-rw-r--r--src/submodule.c12
-rw-r--r--src/tsort.c8
-rw-r--r--src/unix/posix.h1
-rw-r--r--src/util.c52
-rw-r--r--src/util.h10
-rw-r--r--tests-clar/diff/iterator.c78
-rw-r--r--tests-clar/repo/iterator.c747
-rw-r--r--tests-clar/resources/icase/.gitted/HEAD1
-rw-r--r--tests-clar/resources/icase/.gitted/config7
-rw-r--r--tests-clar/resources/icase/.gitted/description1
-rw-r--r--tests-clar/resources/icase/.gitted/indexbin0 -> 1392 bytes
-rw-r--r--tests-clar/resources/icase/.gitted/info/exclude6
-rw-r--r--tests-clar/resources/icase/.gitted/logs/HEAD1
-rw-r--r--tests-clar/resources/icase/.gitted/logs/refs/heads/master1
-rw-r--r--tests-clar/resources/icase/.gitted/objects/3e/257c57f136a1cb8f2b8e9a2e5bc8ec0258bdcebin0 -> 114 bytes
-rw-r--r--tests-clar/resources/icase/.gitted/objects/4d/d6027d083575c7431396dc2a3174afeb393c93bin0 -> 61 bytes
-rw-r--r--tests-clar/resources/icase/.gitted/objects/62/e0af52c199ec731fe4ad230041cd3286192d49bin0 -> 19 bytes
-rw-r--r--tests-clar/resources/icase/.gitted/objects/76/d6e1d231b1085fcce151427e9899335de74be63
-rw-r--r--tests-clar/resources/icase/.gitted/objects/d4/4e18fb93b7107b5cd1b95d601591d77869a1b6bin0 -> 21 bytes
-rw-r--r--tests-clar/resources/icase/.gitted/refs/heads/master1
-rw-r--r--tests-clar/resources/icase/B1
-rw-r--r--tests-clar/resources/icase/D1
-rw-r--r--tests-clar/resources/icase/F1
-rw-r--r--tests-clar/resources/icase/H1
-rw-r--r--tests-clar/resources/icase/J1
-rw-r--r--tests-clar/resources/icase/L/11
-rw-r--r--tests-clar/resources/icase/L/B1
-rw-r--r--tests-clar/resources/icase/L/D1
-rw-r--r--tests-clar/resources/icase/L/a1
-rw-r--r--tests-clar/resources/icase/L/c1
-rw-r--r--tests-clar/resources/icase/a1
-rw-r--r--tests-clar/resources/icase/c1
-rw-r--r--tests-clar/resources/icase/e1
-rw-r--r--tests-clar/resources/icase/g1
-rw-r--r--tests-clar/resources/icase/i1
-rw-r--r--tests-clar/resources/icase/k/11
-rw-r--r--tests-clar/resources/icase/k/B1
-rw-r--r--tests-clar/resources/icase/k/D1
-rw-r--r--tests-clar/resources/icase/k/a1
-rw-r--r--tests-clar/resources/icase/k/c1
-rw-r--r--tests-clar/status/worktree.c3
51 files changed, 1704 insertions, 766 deletions
diff --git a/src/buffer.h b/src/buffer.h
index 6e73895b4..5402f3827 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -119,7 +119,7 @@ void git_buf_copy_cstr(char *data, size_t datasize, const git_buf *buf);
#define git_buf_PUTS(buf, str) git_buf_put(buf, str, sizeof(str) - 1)
-GIT_INLINE(ssize_t) git_buf_rfind_next(git_buf *buf, char ch)
+GIT_INLINE(ssize_t) git_buf_rfind_next(const git_buf *buf, char ch)
{
ssize_t idx = (ssize_t)buf->size - 1;
while (idx >= 0 && buf->ptr[idx] == ch) idx--;
@@ -127,18 +127,17 @@ GIT_INLINE(ssize_t) git_buf_rfind_next(git_buf *buf, char ch)
return idx;
}
-GIT_INLINE(ssize_t) git_buf_rfind(git_buf *buf, char ch)
+GIT_INLINE(ssize_t) git_buf_rfind(const git_buf *buf, char ch)
{
ssize_t idx = (ssize_t)buf->size - 1;
while (idx >= 0 && buf->ptr[idx] != ch) idx--;
return idx;
}
-GIT_INLINE(ssize_t) git_buf_find(git_buf *buf, char ch)
+GIT_INLINE(ssize_t) git_buf_find(const git_buf *buf, char ch)
{
- size_t idx = 0;
- while (idx < buf->size && buf->ptr[idx] != ch) idx++;
- return (idx == buf->size) ? -1 : (ssize_t)idx;
+ void *found = memchr(buf->ptr, ch, buf->size);
+ return found ? (ssize_t)((const char *)found - buf->ptr) : -1;
}
/* Remove whitespace from the end of the buffer */
diff --git a/src/checkout.c b/src/checkout.c
index 19ac913d3..68ebbe31d 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -456,7 +456,7 @@ static int checkout_action(
while (1) {
if (!wd)
return checkout_action_no_wd(data, delta);
-
+
cmp = strcomp(wd->path, delta->old_file.path);
/* 1. wd before delta ("a/a" before "a/b")
@@ -473,9 +473,9 @@ static int checkout_action(
if (cmp == 0) {
if (wd->mode == GIT_FILEMODE_TREE) {
/* case 2 - entry prefixed by workdir tree */
- if (git_iterator_advance_into_directory(workdir, &wd) < 0)
+ if (git_iterator_advance_into(&wd, workdir) < 0)
goto fail;
-
+
*wditem_ptr = wd;
continue;
}
@@ -484,14 +484,14 @@ static int checkout_action(
if (delta->old_file.path[strlen(wd->path)] == '/') {
act = checkout_action_with_wd_blocker(data, delta, wd);
*wditem_ptr =
- git_iterator_advance(workdir, &wd) ? NULL : wd;
+ git_iterator_advance(&wd, workdir) ? NULL : wd;
return act;
}
}
/* case 1 - handle wd item (if it matches pathspec) */
if (checkout_action_wd_only(data, workdir, wd, pathspec) < 0 ||
- git_iterator_advance(workdir, &wd) < 0)
+ git_iterator_advance(&wd, workdir) < 0)
goto fail;
*wditem_ptr = wd;
@@ -501,7 +501,7 @@ static int checkout_action(
if (cmp == 0) {
/* case 4 */
act = checkout_action_with_wd(data, delta, wd);
- *wditem_ptr = git_iterator_advance(workdir, &wd) ? NULL : wd;
+ *wditem_ptr = git_iterator_advance(&wd, workdir) ? NULL : wd;
return act;
}
@@ -514,7 +514,7 @@ static int checkout_action(
if (delta->status == GIT_DELTA_TYPECHANGE) {
if (delta->old_file.mode == GIT_FILEMODE_TREE) {
act = checkout_action_with_wd(data, delta, wd);
- if (git_iterator_advance_into_directory(workdir, &wd) < 0)
+ if (git_iterator_advance_into(&wd, workdir) < 0)
wd = NULL;
*wditem_ptr = wd;
return act;
@@ -525,7 +525,7 @@ static int checkout_action(
delta->old_file.mode == GIT_FILEMODE_COMMIT)
{
act = checkout_action_with_wd(data, delta, wd);
- if (git_iterator_advance(workdir, &wd) < 0)
+ if (git_iterator_advance(&wd, workdir) < 0)
wd = NULL;
*wditem_ptr = wd;
return act;
@@ -554,7 +554,7 @@ static int checkout_remaining_wd_items(
while (wd && !error) {
if (!(error = checkout_action_wd_only(data, workdir, wd, spec)))
- error = git_iterator_advance(workdir, &wd);
+ error = git_iterator_advance(&wd, workdir);
}
return error;
@@ -578,7 +578,7 @@ static int checkout_get_actions(
git_pathspec_init(&pathspec, &data->opts.paths, &pathpool) < 0)
return -1;
- if ((error = git_iterator_current(workdir, &wditem)) < 0)
+ if ((error = git_iterator_current(&wditem, workdir)) < 0)
goto fail;
deltas = &data->diff->deltas;
@@ -1134,16 +1134,17 @@ static int checkout_data_init(
if ((error = git_config_refresh(cfg)) < 0)
goto cleanup;
- if (git_iterator_inner_type(target) == GIT_ITERATOR_TYPE_INDEX) {
- /* if we are iterating over the index, don't reload */
- data->index = git_iterator_index_get_index(target);
+ /* if we are checking out the index, don't reload,
+ * otherwise get index and force reload
+ */
+ if ((data->index = git_iterator_get_index(target)) != NULL) {
GIT_REFCOUNT_INC(data->index);
} else {
/* otherwise, grab and reload the index */
if ((error = git_repository_index(&data->index, data->repo)) < 0 ||
(error = git_index_read(data->index)) < 0)
goto cleanup;
-
+
/* clear the REUC when doing a tree or commit checkout */
git_index_reuc_clear(data->index);
}
@@ -1241,16 +1242,15 @@ int git_checkout_iterator(
GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE;
if ((error = git_iterator_reset(target, data.pfx, data.pfx)) < 0 ||
- (error = git_iterator_for_workdir_range(
- &workdir, data.repo, iterflags, data.pfx, data.pfx)) < 0 ||
- (error = git_iterator_for_tree_range(
+ (error = git_iterator_for_workdir(
+ &workdir, data.repo, iterflags | GIT_ITERATOR_DONT_AUTOEXPAND,
+ data.pfx, data.pfx)) < 0 ||
+ (error = git_iterator_for_tree(
&baseline, data.opts.baseline, iterflags, data.pfx, data.pfx)) < 0)
goto cleanup;
- /* Handle case insensitivity for baseline if necessary */
- if (git_iterator_ignore_case(workdir) != git_iterator_ignore_case(baseline))
- if ((error = git_iterator_spoolandsort_push(baseline, true)) < 0)
- goto cleanup;
+ /* Should not have case insensitivity mismatch */
+ assert(git_iterator_ignore_case(workdir) == git_iterator_ignore_case(baseline));
/* Generate baseline-to-target diff which will include an entry for
* every possible update that might need to be made.
@@ -1321,7 +1321,7 @@ int git_checkout_index(
return error;
GIT_REFCOUNT_INC(index);
- if (!(error = git_iterator_for_index(&index_i, index)))
+ if (!(error = git_iterator_for_index(&index_i, index, 0, NULL, NULL)))
error = git_checkout_iterator(index_i, opts);
git_iterator_free(index_i);
@@ -1348,7 +1348,7 @@ int git_checkout_tree(
return -1;
}
- if (!(error = git_iterator_for_tree(&tree_i, tree)))
+ if (!(error = git_iterator_for_tree(&tree_i, tree, 0, NULL, NULL)))
error = git_checkout_iterator(tree_i, opts);
git_iterator_free(tree_i);
@@ -1369,7 +1369,7 @@ int git_checkout_head(
return error;
if (!(error = checkout_lookup_head_tree(&head, repo)) &&
- !(error = git_iterator_for_tree(&head_i, head)))
+ !(error = git_iterator_for_tree(&head_i, head, 0, NULL, NULL)))
error = git_checkout_iterator(head_i, opts);
git_iterator_free(head_i);
diff --git a/src/diff.c b/src/diff.c
index ca08f4233..fc37d139d 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -623,18 +623,13 @@ int git_diff__from_iterators(
goto fail;
if (diff->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) {
- /* If either iterator does not have ignore_case set, then we will
- * spool its data, sort it icase, and use that for the merge join
- * with the other iterator which was icase sorted. This call is
- * a no-op on an iterator that already matches "ignore_case".
- */
- if (git_iterator_spoolandsort_push(old_iter, true) < 0 ||
- git_iterator_spoolandsort_push(new_iter, true) < 0)
+ if (git_iterator_set_ignore_case(old_iter, true) < 0 ||
+ git_iterator_set_ignore_case(new_iter, true) < 0)
goto fail;
}
- if (git_iterator_current(old_iter, &oitem) < 0 ||
- git_iterator_current(new_iter, &nitem) < 0)
+ if (git_iterator_current(&oitem, old_iter) < 0 ||
+ git_iterator_current(&nitem, new_iter) < 0)
goto fail;
/* run iterators building diffs */
@@ -666,12 +661,12 @@ int git_diff__from_iterators(
if (S_ISDIR(nitem->mode) &&
!(diff->opts.flags & GIT_DIFF_RECURSE_UNTRACKED_DIRS))
{
- if (git_iterator_advance(new_iter, &nitem) < 0)
+ if (git_iterator_advance(&nitem, new_iter) < 0)
goto fail;
}
}
- if (git_iterator_advance(old_iter, &oitem) < 0)
+ if (git_iterator_advance(&oitem, old_iter) < 0)
goto fail;
}
@@ -699,7 +694,7 @@ int git_diff__from_iterators(
/* do not advance into directories that contain a .git file */
if (!contains_oitem && recurse_untracked) {
git_buf *full = NULL;
- if (git_iterator_current_workdir_path(new_iter, &full) < 0)
+ if (git_iterator_current_workdir_path(&full, new_iter) < 0)
goto fail;
if (git_path_contains_dir(full, DOT_GIT))
recurse_untracked = false;
@@ -713,9 +708,19 @@ int git_diff__from_iterators(
git_iterator_current_is_ignored(new_iter))
git_buf_sets(&ignore_prefix, nitem->path);
- if (git_iterator_advance_into_directory(new_iter, &nitem) < 0)
- goto fail;
+ /* advance into directory */
+ error = git_iterator_advance_into(&nitem, new_iter);
+
+ /* if directory is empty, can't advance into it, so skip */
+ if (error == GIT_ENOTFOUND) {
+ giterr_clear();
+ error = git_iterator_advance(&nitem, new_iter);
+
+ git_buf_clear(&ignore_prefix);
+ }
+ if (error < 0)
+ goto fail;
continue;
}
}
@@ -736,7 +741,7 @@ int git_diff__from_iterators(
* skip the file.
*/
else if (delta_type == GIT_DELTA_IGNORED) {
- if (git_iterator_advance(new_iter, &nitem) < 0)
+ if (git_iterator_advance(&nitem, new_iter) < 0)
goto fail;
continue; /* ignored parent directory, so skip completely */
}
@@ -765,7 +770,7 @@ int git_diff__from_iterators(
}
}
- if (git_iterator_advance(new_iter, &nitem) < 0)
+ if (git_iterator_advance(&nitem, new_iter) < 0)
goto fail;
}
@@ -775,11 +780,10 @@ int git_diff__from_iterators(
else {
assert(oitem && nitem && cmp == 0);
- if (maybe_modified(
- old_iter, oitem, new_iter, nitem, diff) < 0 ||
- git_iterator_advance(old_iter, &oitem) < 0 ||
- git_iterator_advance(new_iter, &nitem) < 0)
- goto fail;
+ if (maybe_modified(old_iter, oitem, new_iter, nitem, diff) < 0 ||
+ git_iterator_advance(&oitem, old_iter) < 0 ||
+ git_iterator_advance(&nitem, new_iter) < 0)
+ goto fail;
}
}
@@ -800,7 +804,7 @@ fail:
git_iterator *a = NULL, *b = NULL; \
char *pfx = opts ? git_pathspec_prefix(&opts->pathspec) : NULL; \
GITERR_CHECK_VERSION(opts, GIT_DIFF_OPTIONS_VERSION, "git_diff_options"); \
- if (!(error = MAKE_FIRST) && !(error = MAKE_SECOND)) \
+ if (!(error = MAKE_FIRST) && !(error = MAKE_SECOND)) \
error = git_diff__from_iterators(diff, repo, a, b, opts); \
git__free(pfx); git_iterator_free(a); git_iterator_free(b); \
} while (0)
@@ -817,8 +821,8 @@ int git_diff_tree_to_tree(
assert(diff && repo);
DIFF_FROM_ITERATORS(
- git_iterator_for_tree_range(&a, old_tree, 0, pfx, pfx),
- git_iterator_for_tree_range(&b, new_tree, 0, pfx, pfx)
+ git_iterator_for_tree(&a, old_tree, 0, pfx, pfx),
+ git_iterator_for_tree(&b, new_tree, 0, pfx, pfx)
);
return error;
@@ -839,8 +843,8 @@ int git_diff_tree_to_index(
return error;
DIFF_FROM_ITERATORS(
- git_iterator_for_tree_range(&a, old_tree, 0, pfx, pfx),
- git_iterator_for_index_range(&b, index, 0, pfx, pfx)
+ git_iterator_for_tree(&a, old_tree, 0, pfx, pfx),
+ git_iterator_for_index(&b, index, 0, pfx, pfx)
);
return error;
@@ -860,8 +864,9 @@ int git_diff_index_to_workdir(
return error;
DIFF_FROM_ITERATORS(
- git_iterator_for_index_range(&a, index, 0, pfx, pfx),
- git_iterator_for_workdir_range(&b, repo, 0, pfx, pfx)
+ git_iterator_for_index(&a, index, 0, pfx, pfx),
+ git_iterator_for_workdir(
+ &b, repo, GIT_ITERATOR_DONT_AUTOEXPAND, pfx, pfx)
);
return error;
@@ -879,8 +884,9 @@ int git_diff_tree_to_workdir(
assert(diff && repo);
DIFF_FROM_ITERATORS(
- git_iterator_for_tree_range(&a, old_tree, 0, pfx, pfx),
- git_iterator_for_workdir_range(&b, repo, 0, pfx, pfx)
+ git_iterator_for_tree(&a, old_tree, 0, pfx, pfx),
+ git_iterator_for_workdir(
+ &b, repo, GIT_ITERATOR_DONT_AUTOEXPAND, pfx, pfx)
);
return error;
diff --git a/src/hashsig.c b/src/hashsig.c
index e9c5164a4..3a75aaaed 100644
--- a/src/hashsig.c
+++ b/src/hashsig.c
@@ -6,6 +6,7 @@
*/
#include "hashsig.h"
#include "fileops.h"
+#include "util.h"
typedef uint32_t hashsig_t;
typedef uint64_t hashsig_state;
@@ -19,7 +20,7 @@ typedef uint64_t hashsig_state;
#define HASHSIG_HEAP_SIZE ((1 << 7) - 1)
-typedef int (GIT_STDLIB_CALL *hashsig_cmp)(const void *a, const void *b);
+typedef int (*hashsig_cmp)(const void *a, const void *b, void *);
typedef struct {
int size, asize;
@@ -53,15 +54,17 @@ static void hashsig_heap_init(hashsig_heap *h, hashsig_cmp cmp)
h->cmp = cmp;
}
-static int GIT_STDLIB_CALL hashsig_cmp_max(const void *a, const void *b)
+static int hashsig_cmp_max(const void *a, const void *b, void *payload)
{
hashsig_t av = *(const hashsig_t *)a, bv = *(const hashsig_t *)b;
+ GIT_UNUSED(payload);
return (av < bv) ? -1 : (av > bv) ? 1 : 0;
}
-static int GIT_STDLIB_CALL hashsig_cmp_min(const void *a, const void *b)
+static int hashsig_cmp_min(const void *a, const void *b, void *payload)
{
hashsig_t av = *(const hashsig_t *)a, bv = *(const hashsig_t *)b;
+ GIT_UNUSED(payload);
return (av > bv) ? -1 : (av < bv) ? 1 : 0;
}
@@ -69,7 +72,7 @@ static void hashsig_heap_up(hashsig_heap *h, int el)
{
int parent_el = HEAP_PARENT_OF(el);
- while (el > 0 && h->cmp(&h->values[parent_el], &h->values[el]) > 0) {
+ while (el > 0 && h->cmp(&h->values[parent_el], &h->values[el], NULL) > 0) {
hashsig_t t = h->values[el];
h->values[el] = h->values[parent_el];
h->values[parent_el] = t;
@@ -92,10 +95,10 @@ static void hashsig_heap_down(hashsig_heap *h, int el)
lv = h->values[lel];
rv = h->values[rel];
- if (h->cmp(&v, &lv) < 0 && h->cmp(&v, &rv) < 0)
+ if (h->cmp(&v, &lv, NULL) < 0 && h->cmp(&v, &rv, NULL) < 0)
break;
- swapel = (h->cmp(&lv, &rv) < 0) ? lel : rel;
+ swapel = (h->cmp(&lv, &rv, NULL) < 0) ? lel : rel;
h->values[el] = h->values[swapel];
h->values[swapel] = v;
@@ -107,13 +110,13 @@ static void hashsig_heap_down(hashsig_heap *h, int el)
static void hashsig_heap_sort(hashsig_heap *h)
{
/* only need to do this at the end for signature comparison */
- qsort(h->values, h->size, sizeof(hashsig_t), h->cmp);
+ git__qsort_r(h->values, h->size, sizeof(hashsig_t), h->cmp, NULL);
}
static void hashsig_heap_insert(hashsig_heap *h, hashsig_t val)
{
/* if heap is full, pop top if new element should replace it */
- if (h->size == h->asize && h->cmp(&val, &h->values[0]) > 0) {
+ if (h->size == h->asize && h->cmp(&val, &h->values[0], NULL) > 0) {
h->size--;
h->values[0] = h->values[h->size];
hashsig_heap_down(h, 0);
@@ -343,7 +346,7 @@ static int hashsig_heap_compare(const hashsig_heap *a, const hashsig_heap *b)
/* hash heaps are sorted - just look for overlap vs total */
for (i = 0, j = 0; i < a->size && j < b->size; ) {
- cmp = a->cmp(&a->values[i], &b->values[j]);
+ cmp = a->cmp(&a->values[i], &b->values[j], NULL);
if (cmp < 0)
++i;
diff --git a/src/index.c b/src/index.c
index 4deafd77f..1ca3b16b2 100644
--- a/src/index.c
+++ b/src/index.c
@@ -1679,54 +1679,3 @@ git_repository *git_index_owner(const git_index *index)
{
return INDEX_OWNER(index);
}
-
-int git_index_read_tree_match(
- git_index *index, git_tree *tree, git_strarray *strspec)
-{
-#if 0
- git_iterator *iter = NULL;
- const git_index_entry *entry;
- char *pfx = NULL;
- git_vector pathspec = GIT_VECTOR_INIT;
- git_pool pathpool = GIT_POOL_INIT_STRINGPOOL;
-#endif
-
- if (!git_pathspec_is_interesting(strspec))
- return git_index_read_tree(index, tree);
-
- return git_index_read_tree(index, tree);
-
-#if 0
- /* The following loads the matches into the index, but doesn't
- * erase obsoleted entries (e.g. you load a blob at "a/b" which
- * should obsolete a blob at "a/b/c/d" since b is no longer a tree)
- */
-
- if (git_pathspec_init(&pathspec, strspec, &pathpool) < 0)
- return -1;
-
- pfx = git_pathspec_prefix(strspec);
-
- if ((error = git_iterator_for_tree_range(&iter, tree, pfx, pfx)) < 0 ||
- (error = git_iterator_current(iter, &entry)) < 0)
- goto cleanup;
-
- while (entry != NULL) {
- if (git_pathspec_match_path(
- &pathspec, entry->path, false, false, NULL) &&
- (error = git_index_add(index, entry)) < 0)
- goto cleanup;
-
- if ((error = git_iterator_advance(iter, &entry)) < 0)
- goto cleanup;
- }
-
-cleanup:
- git_iterator_free(iter);
- git_pathspec_free(&pathspec);
- git_pool_clear(&pathpool);
- git__free(pfx);
-
- return error;
-#endif
-}
diff --git a/src/index.h b/src/index.h
index 2beaa6375..9498907b6 100644
--- a/src/index.h
+++ b/src/index.h
@@ -50,7 +50,4 @@ extern int git_index_entry__cmp_icase(const void *a, const void *b);
extern void git_index__set_ignore_case(git_index *index, bool ignore_case);
-extern int git_index_read_tree_match(
- git_index *index, git_tree *tree, git_strarray *strspec);
-
#endif
diff --git a/src/iterator.c b/src/iterator.c
index 8ad639d6b..e6e0ea481 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -14,26 +14,45 @@
#define ITERATOR_SET_CB(P,NAME_LC) do { \
(P)->cb.current = NAME_LC ## _iterator__current; \
- (P)->cb.at_end = NAME_LC ## _iterator__at_end; \
(P)->cb.advance = NAME_LC ## _iterator__advance; \
+ (P)->cb.advance_into = NAME_LC ## _iterator__advance_into; \
(P)->cb.seek = NAME_LC ## _iterator__seek; \
(P)->cb.reset = NAME_LC ## _iterator__reset; \
+ (P)->cb.at_end = NAME_LC ## _iterator__at_end; \
(P)->cb.free = NAME_LC ## _iterator__free; \
} while (0)
-#define ITERATOR_BASE_INIT(P,NAME_LC,NAME_UC) do { \
+#define ITERATOR_CASE_FLAGS \
+ (GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_DONT_IGNORE_CASE)
+
+#define ITERATOR_BASE_INIT(P,NAME_LC,NAME_UC,REPO) do { \
(P) = git__calloc(1, sizeof(NAME_LC ## _iterator)); \
GITERR_CHECK_ALLOC(P); \
(P)->base.type = GIT_ITERATOR_TYPE_ ## NAME_UC; \
- (P)->base.cb = &(P)->cb; \
+ (P)->base.cb = &(P)->cb; \
ITERATOR_SET_CB(P,NAME_LC); \
+ (P)->base.repo = (REPO); \
(P)->base.start = start ? git__strdup(start) : NULL; \
(P)->base.end = end ? git__strdup(end) : NULL; \
if ((start && !(P)->base.start) || (end && !(P)->base.end)) { \
git__free(P); return -1; } \
(P)->base.prefixcomp = git__prefixcmp; \
+ (P)->base.flags = flags & ~ITERATOR_CASE_FLAGS; \
+ if ((P)->base.flags & GIT_ITERATOR_DONT_AUTOEXPAND) \
+ (P)->base.flags |= GIT_ITERATOR_INCLUDE_TREES; \
} while (0)
+#define iterator__flag(I,F) ((((git_iterator *)(I))->flags & GIT_ITERATOR_ ## F) != 0)
+#define iterator__ignore_case(I) iterator__flag(I,IGNORE_CASE)
+#define iterator__include_trees(I) iterator__flag(I,INCLUDE_TREES)
+#define iterator__dont_autoexpand(I) iterator__flag(I,DONT_AUTOEXPAND)
+#define iterator__do_autoexpand(I) !iterator__flag(I,DONT_AUTOEXPAND)
+
+#define iterator__end(I) ((git_iterator *)(I))->end
+#define iterator__past_end(I,PATH) \
+ (iterator__end(I) && ((git_iterator *)(I))->prefixcomp((PATH),iterator__end(I)) > 0)
+
+
static int iterator__reset_range(
git_iterator *iter, const char *start, const char *end)
{
@@ -54,7 +73,7 @@ static int iterator__reset_range(
return 0;
}
-static int iterator_update_ignore_case(
+static int iterator__update_ignore_case(
git_iterator *iter,
git_iterator_flag_t flags)
{
@@ -76,42 +95,46 @@ static int iterator_update_ignore_case(
else if (ignore_case == 0)
iter->flags = (iter->flags & ~GIT_ITERATOR_IGNORE_CASE);
- iter->prefixcomp = ((iter->flags & GIT_ITERATOR_IGNORE_CASE) != 0) ?
+ iter->prefixcomp = iterator__ignore_case(iter) ?
git__prefixcmp_icase : git__prefixcmp;
return error;
}
-static int empty_iterator__no_item(
- git_iterator *iter, const git_index_entry **entry)
+GIT_INLINE(void) iterator__clear_entry(const git_index_entry **entry)
+{
+ if (entry) *entry = NULL;
+}
+
+
+static int empty_iterator__noop(const git_index_entry **e, git_iterator *i)
{
- GIT_UNUSED(iter);
- *entry = NULL;
+ GIT_UNUSED(i);
+ iterator__clear_entry(e);
return 0;
}
-static int empty_iterator__at_end(git_iterator *iter)
+static int empty_iterator__seek(git_iterator *i, const char *p)
{
- GIT_UNUSED(iter);
- return 1;
+ GIT_UNUSED(i); GIT_UNUSED(p);
+ return -1;
}
-static int empty_iterator__reset(
- git_iterator *iter, const char *start, const char *end)
+static int empty_iterator__reset(git_iterator *i, const char *s, const char *e)
{
- GIT_UNUSED(iter); GIT_UNUSED(start); GIT_UNUSED(end);
+ GIT_UNUSED(i); GIT_UNUSED(s); GIT_UNUSED(e);
return 0;
}
-static int empty_iterator__seek(git_iterator *iter, const char *prefix)
+static int empty_iterator__at_end(git_iterator *i)
{
- GIT_UNUSED(iter); GIT_UNUSED(prefix);
- return -1;
+ GIT_UNUSED(i);
+ return 1;
}
-static void empty_iterator__free(git_iterator *iter)
+static void empty_iterator__free(git_iterator *i)
{
- GIT_UNUSED(iter);
+ GIT_UNUSED(i);
}
typedef struct {
@@ -119,56 +142,82 @@ typedef struct {
git_iterator_callbacks cb;
} empty_iterator;
-int git_iterator_for_nothing(git_iterator **iter, git_iterator_flag_t flags)
+int git_iterator_for_nothing(
+ git_iterator **iter,
+ git_iterator_flag_t flags,
+ const char *start,
+ const char *end)
{
empty_iterator *i = git__calloc(1, sizeof(empty_iterator));
GITERR_CHECK_ALLOC(i);
- i->base.type = GIT_ITERATOR_TYPE_EMPTY;
- i->base.cb = &i->cb;
- i->base.flags = flags;
- i->cb.current = empty_iterator__no_item;
- i->cb.at_end = empty_iterator__at_end;
- i->cb.advance = empty_iterator__no_item;
- i->cb.seek = empty_iterator__seek;
- i->cb.reset = empty_iterator__reset;
- i->cb.free = empty_iterator__free;
+#define empty_iterator__current empty_iterator__noop
+#define empty_iterator__advance empty_iterator__noop
+#define empty_iterator__advance_into empty_iterator__noop
- *iter = (git_iterator *)i;
+ ITERATOR_BASE_INIT(i, empty, EMPTY, NULL);
+ if ((flags & GIT_ITERATOR_IGNORE_CASE) != 0)
+ i->base.flags |= GIT_ITERATOR_IGNORE_CASE;
+
+ *iter = (git_iterator *)i;
return 0;
}
+typedef struct {
+ size_t parent_entry_index; /* index in parent entries array */
+ size_t parent_tree_index; /* index in parent entry tree */
+ git_tree *tree; /* this tree if this is tree (only valid while current) */
+} tree_iterator_entry;
+
typedef struct tree_iterator_frame tree_iterator_frame;
struct tree_iterator_frame {
- tree_iterator_frame *next, *prev;
- git_tree *tree;
- char *start;
+ tree_iterator_frame *parent, *child;
+
+ size_t n_entries; /* items in this frame */
+ size_t current; /* start of currently active range in frame */
+ size_t next; /* start of next range in frame */
+
+ const char *start;
size_t startlen;
- size_t index;
- void **icase_map;
- void *icase_data[GIT_FLEX_ARRAY];
+
+ tree_iterator_entry entries[GIT_FLEX_ARRAY];
};
typedef struct {
git_iterator base;
git_iterator_callbacks cb;
- tree_iterator_frame *stack, *tail;
+ tree_iterator_frame *head, *top;
git_index_entry entry;
git_buf path;
+ int path_ambiguities;
bool path_has_filename;
+ int (*strncomp)(const char *a, const char *b, size_t sz);
} tree_iterator;
-GIT_INLINE(const git_tree_entry *)tree_iterator__tree_entry(tree_iterator *ti)
+static const git_tree_entry *tree_iterator__tree_entry(
+ tree_iterator_frame *tf, const tree_iterator_entry *entry)
{
- tree_iterator_frame *tf = ti->stack;
+ git_tree *tree = tf->parent->entries[entry->parent_entry_index].tree;
+ if (!tree)
+ return NULL;
+ return git_tree_entry_byindex(tree, entry->parent_tree_index);
+}
- if (tf->index >= git_tree_entrycount(tf->tree))
+static const git_tree_entry *tree_iterator__tree_entry_by_index(
+ tree_iterator_frame *tf, size_t i)
+{
+ git_tree *tree;
+
+ if (i >= tf->n_entries)
+ return NULL;
+
+ tree = tf->parent->entries[tf->entries[i].parent_entry_index].tree;
+ if (!tree)
return NULL;
- return git_tree_entry_byindex(
- tf->tree, tf->icase_map ? (size_t)tf->icase_map[tf->index] : tf->index);
+ return git_tree_entry_byindex(tree, tf->entries[i].parent_tree_index);
}
static char *tree_iterator__current_filename(
@@ -177,274 +226,379 @@ static char *tree_iterator__current_filename(
if (!ti->path_has_filename) {
if (git_buf_joinpath(&ti->path, ti->path.ptr, te->filename) < 0)
return NULL;
+
+ if (git_tree_entry__is_tree(te) && git_buf_putc(&ti->path, '/') < 0)
+ return NULL;
+
ti->path_has_filename = true;
}
return ti->path.ptr;
}
-static void tree_iterator__free_frame(tree_iterator_frame *tf)
+static void tree_iterator__rewrite_filename(tree_iterator *ti)
{
- if (!tf)
- return;
+ tree_iterator_frame *scan = ti->head;
+ size_t current = scan->current;
+ ssize_t strpos = ti->path.size;
+ const git_tree_entry *te;
- git_tree_free(tf->tree);
- tf->tree = NULL;
+ if (strpos && ti->path.ptr[strpos - 1] == '/')
+ strpos--;
- git__free(tf);
+ while (scan && scan->parent) {
+ tree_iterator_entry *entry = &scan->entries[current];
+
+ if (!(te = tree_iterator__tree_entry(scan, entry)))
+ break;
+
+ strpos -= te->filename_len;
+ memcpy(&ti->path.ptr[strpos], te->filename, te->filename_len);
+ strpos -= 1; /* separator */
+
+ current = entry->parent_entry_index;
+ scan = scan->parent;
+ }
}
-static bool tree_iterator__pop_frame(tree_iterator *ti)
+static int tree_iterator__tree_entry_cmp(
+ const git_tree_entry *a,
+ const git_tree_entry *b,
+ int (*strncomp)(const char *, const char *, size_t))
{
- tree_iterator_frame *tf = ti->stack;
+ size_t common = min(a->filename_len, b->filename_len);
+ int cmp = strncomp(a->filename, b->filename, common);
- /* don't free the initial tree/frame */
- if (!tf->next)
- return false;
+ if (!cmp) {
+ char a_next = a->filename[common], b_next = b->filename[common];
- ti->stack = tf->next;
- ti->stack->prev = NULL;
+ if (!a_next && a->attr == GIT_FILEMODE_TREE)
+ a_next = '/';
+ if (!b_next && b->attr == GIT_FILEMODE_TREE)
+ b_next = '/';
- tree_iterator__free_frame(tf);
+ cmp = (int)a_next - (int)b_next;
+ }
- return true;
+ return cmp;
}
-static int tree_iterator__to_end(tree_iterator *ti)
+static int tree_iterator__entry_cmp(const void *a, const void *b, void *p)
{
- while (tree_iterator__pop_frame(ti)) /* pop all */;
- ti->stack->index = git_tree_entrycount(ti->stack->tree);
- return 0;
+ const tree_iterator_entry *ae = a, *be = b;
+ const git_tree_entry *ate = tree_iterator__tree_entry(p, ae);
+ const git_tree_entry *bte = tree_iterator__tree_entry(p, be);
+ int cmp = tree_iterator__tree_entry_cmp(ate, bte, git__strncasecmp);
+
+ /* stabilize sort order among equivalent names */
+ if (!cmp) {
+ cmp = (ae->parent_entry_index < be->parent_entry_index) ? -1 :
+ (ae->parent_entry_index > be->parent_entry_index) ? 1 : 0;
+ if (!cmp)
+ cmp = (ae->parent_tree_index < be->parent_tree_index) ? -1 :
+ (ae->parent_tree_index > be->parent_tree_index) ? 1 : 0;
+ }
+
+ return cmp;
}
-static int tree_iterator__current(
- git_iterator *self, const git_index_entry **entry)
+static int tree_iterator__set_next(tree_iterator *ti, tree_iterator_frame *tf)
{
- tree_iterator *ti = (tree_iterator *)self;
- const git_tree_entry *te = tree_iterator__tree_entry(ti);
+ /* find next and load trees for current range */
+ int error = 0;
+ const git_tree_entry *te, *last = NULL;
- if (entry)
- *entry = NULL;
+ tf->next = tf->current;
- if (te == NULL)
- return 0;
+ while (tf->next < tf->n_entries) {
+ if (!(te = tree_iterator__tree_entry_by_index(tf, tf->next)) ||
+ (last && tree_iterator__tree_entry_cmp(last, te, ti->strncomp)))
+ break;
- ti->entry.mode = te->attr;
- git_oid_cpy(&ti->entry.oid, &te->oid);
+ if (git_tree_entry__is_tree(te) &&
+ (error = git_tree_lookup(
+ &tf->entries[tf->next].tree, ti->base.repo, &te->oid)) < 0)
+ break;
- ti->entry.path = tree_iterator__current_filename(ti, te);
- if (ti->entry.path == NULL)
- return -1;
+ tf->next++;
+ last = te;
+ }
- if (ti->base.end && ti->base.prefixcomp(ti->entry.path, ti->base.end) > 0)
- return tree_iterator__to_end(ti);
+ if (tf->next > tf->current + 1)
+ ti->path_ambiguities++;
- if (entry)
- *entry = &ti->entry;
+ if (last && !tree_iterator__current_filename(ti, last))
+ return -1;
- return 0;
+ return error;
}
-static int tree_iterator__at_end(git_iterator *self)
+GIT_INLINE(bool) tree_iterator__at_tree(tree_iterator *ti)
{
- return (tree_iterator__tree_entry((tree_iterator *)self) == NULL);
+ return (ti->head->current < ti->head->n_entries &&
+ ti->head->entries[ti->head->current].tree != NULL);
}
-static int tree_iterator__icase_map_cmp(const void *a, const void *b, void *data)
+static int tree_iterator__push_frame(tree_iterator *ti)
{
- git_tree *tree = data;
- const git_tree_entry *te1 = git_tree_entry_byindex(tree, (size_t)a);
- const git_tree_entry *te2 = git_tree_entry_byindex(tree, (size_t)b);
+ int error = 0;
+ tree_iterator_frame *tf = ti->head, *new_tf = NULL;
+ size_t i, n_entries = 0, sz = sizeof(tree_iterator_frame);
+ const git_tree_entry *te;
- return te1 ? (te2 ? git_tree_entry_icmp(te1, te2) : 1) : -1;
-}
+ /* if current item in head is not a tree, do nothing */
+ if (tf->current >= tf->n_entries || !tf->entries[tf->current].tree)
+ return 0;
-static int tree_iterator__frame_start_icmp(const void *key, const void *el)
-{
- const tree_iterator_frame *tf = (const tree_iterator_frame *)key;
- const git_tree_entry *te = git_tree_entry_byindex(tf->tree, (size_t)el);
- size_t minlen = min(tf->startlen, te->filename_len);
+ /* build frame - sum tree entries from parent range */
+ for (i = tf->current; i < tf->next; ++i)
+ n_entries += git_tree_entrycount(tf->entries[i].tree);
+ sz += n_entries * sizeof(tree_iterator_entry);
+ new_tf = git__calloc(sz, sizeof(char));
+ GITERR_CHECK_ALLOC(new_tf);
+
+ /* populate frame and entries */
+ new_tf->parent = tf;
+ new_tf->n_entries = n_entries;
+
+ for (i = tf->current, n_entries = 0; i < tf->next; ++i) {
+ git_tree *tree = tf->entries[i].tree;
+ size_t j, max_j = git_tree_entrycount(tree);
+
+ for (j = 0; j < max_j; ++j) {
+ new_tf->entries[n_entries].parent_entry_index = i;
+ new_tf->entries[n_entries].parent_tree_index = j;
+ n_entries++;
+ }
+ }
- return git__strncasecmp(tf->start, te->filename, minlen);
-}
+ /* if ignore_case, sort entries case insensitively */
+ if (iterator__ignore_case(ti))
+ git__qsort_r(
+ new_tf->entries, new_tf->n_entries, sizeof(tree_iterator_entry),
+ tree_iterator__entry_cmp, new_tf);
+
+ /* pick new_tf->current based on "start" (or start at zero) */
+ if (tf->startlen > 0) {
+ /* find first item >= start */
+ for (i = 0; i < new_tf->n_entries; ++i) {
+ if (!(te = tree_iterator__tree_entry_by_index(new_tf, i)))
+ break;
+ sz = min(tf->startlen, te->filename_len);
+ if (ti->strncomp(tf->start, te->filename, sz) <= 0 &&
+ (tf->startlen <= te->filename_len ||
+ tf->start[te->filename_len] == '/'))
+ break;
+ }
+ new_tf->current = i;
-static void tree_iterator__frame_seek_start(tree_iterator_frame *tf)
-{
- if (!tf->start)
- tf->index = 0;
- else if (!tf->icase_map)
- tf->index = git_tree__prefix_position(tf->tree, tf->start);
- else {
- if (!git__bsearch(
- tf->icase_map, git_tree_entrycount(tf->tree),
- tf, tree_iterator__frame_start_icmp, &tf->index))
- {
- while (tf->index > 0) {
- /* move back while previous entry is still prefixed */
- if (tree_iterator__frame_start_icmp(
- tf, (const void *)(tf->index - 1)))
- break;
- tf->index--;
- }
+ if ((new_tf->start = strchr(tf->start, '/')) != NULL) {
+ new_tf->start++;
+ new_tf->startlen = strlen(new_tf->start);
}
}
+
+ ti->path_has_filename = false;
+
+ /* find next and load trees for current range */
+ if ((error = tree_iterator__set_next(ti, new_tf)) < 0)
+ return error;
+
+ tf->child = new_tf;
+ ti->head = new_tf;
+
+ if (!iterator__include_trees(ti) && tree_iterator__at_tree(ti))
+ return tree_iterator__push_frame(ti);
+
+ return 0;
}
-static tree_iterator_frame *tree_iterator__alloc_frame(
- tree_iterator *ti, git_tree *tree, char *start)
+GIT_INLINE(void) tree_iterator__free_tree(tree_iterator_entry *entry)
{
- size_t i, max_i = git_tree_entrycount(tree);
- tree_iterator_frame *tf =
- git__calloc(1, sizeof(tree_iterator_frame) + max_i * sizeof(void *));
- if (!tf)
- return NULL;
+ if (entry->tree) {
+ git_tree_free(entry->tree);
+ entry->tree = NULL;
+ }
+}
- tf->tree = tree;
+static bool tree_iterator__move_to_next(
+ tree_iterator *ti, tree_iterator_frame *tf)
+{
+ if (tf->next > tf->current + 1)
+ ti->path_ambiguities--;
- if (start && *start) {
- tf->start = start;
- tf->startlen = strlen(start);
+ for (; tf->current < tf->next; tf->current++) {
+ if (tf->parent)
+ tree_iterator__free_tree(&tf->entries[tf->current]);
}
- if (!max_i)
- return tf;
+ return (tf->current < tf->n_entries);
+}
- if ((ti->base.flags & GIT_ITERATOR_IGNORE_CASE) != 0) {
- tf->icase_map = tf->icase_data;
+static bool tree_iterator__pop_frame(tree_iterator *ti)
+{
+ tree_iterator_frame *tf = ti->head;
- for (i = 0; i < max_i; ++i)
- tf->icase_map[i] = (void *)i;
+ if (!tf->parent)
+ return false;
- git__tsort_r(
- tf->icase_map, max_i, tree_iterator__icase_map_cmp, tf->tree);
- }
+ tree_iterator__move_to_next(ti, tf);
- tree_iterator__frame_seek_start(tf);
+ ti->head = tf->parent;
+ ti->head->child = NULL;
+ git__free(tf);
+
+ git_buf_rtruncate_at_char(&ti->path, '/');
- return tf;
+ return true;
}
-static int tree_iterator__expand_tree(tree_iterator *ti)
+static int tree_iterator__current(
+ const git_index_entry **entry, git_iterator *self)
{
- int error;
- git_tree *subtree;
- const git_tree_entry *te = tree_iterator__tree_entry(ti);
- tree_iterator_frame *tf;
- char *relpath;
-
- while (te != NULL && git_tree_entry__is_tree(te)) {
- if (git_buf_joinpath(&ti->path, ti->path.ptr, te->filename) < 0)
- return -1;
+ tree_iterator *ti = (tree_iterator *)self;
+ tree_iterator_frame *tf = ti->head;
+ const git_tree_entry *te;
- /* check that we have not passed the range end */
- if (ti->base.end != NULL &&
- ti->base.prefixcomp(ti->path.ptr, ti->base.end) > 0)
- return tree_iterator__to_end(ti);
+ iterator__clear_entry(entry);
- if ((error = git_tree_lookup(&subtree, ti->base.repo, &te->oid)) < 0)
- return error;
-
- relpath = NULL;
+ if (!(te = tree_iterator__tree_entry_by_index(tf, tf->current)))
+ return 0;
- /* apply range start to new frame if relevant */
- if (ti->stack->start &&
- ti->base.prefixcomp(ti->stack->start, te->filename) == 0)
- {
- if (ti->stack->start[te->filename_len] == '/')
- relpath = ti->stack->start + te->filename_len + 1;
- }
+ ti->entry.mode = te->attr;
+ git_oid_cpy(&ti->entry.oid, &te->oid);
- if ((tf = tree_iterator__alloc_frame(ti, subtree, relpath)) == NULL)
- return -1;
+ ti->entry.path = tree_iterator__current_filename(ti, te);
+ if (ti->entry.path == NULL)
+ return -1;
- tf->next = ti->stack;
- ti->stack = tf;
- tf->next->prev = tf;
+ if (ti->path_ambiguities > 0)
+ tree_iterator__rewrite_filename(ti);
- te = tree_iterator__tree_entry(ti);
+ if (iterator__past_end(ti, ti->entry.path)) {
+ while (tree_iterator__pop_frame(ti)) /* pop to top */;
+ ti->head->current = ti->head->n_entries;
+ return 0;
}
+ if (entry)
+ *entry = &ti->entry;
+
return 0;
}
-static int tree_iterator__advance(
- git_iterator *self, const git_index_entry **entry)
+static int tree_iterator__advance_into(
+ const git_index_entry **entry, git_iterator *self)
{
int error = 0;
tree_iterator *ti = (tree_iterator *)self;
- const git_tree_entry *te = NULL;
- if (entry != NULL)
- *entry = NULL;
+ iterator__clear_entry(entry);
- if (ti->path_has_filename) {
- git_buf_rtruncate_at_char(&ti->path, '/');
- ti->path_has_filename = false;
- }
+ if (tree_iterator__at_tree(ti) &&
+ !(error = tree_iterator__push_frame(ti)))
+ error = tree_iterator__current(entry, self);
- while (1) {
- ++ti->stack->index;
+ return error;
+}
- if ((te = tree_iterator__tree_entry(ti)) != NULL)
- break;
+static int tree_iterator__advance(
+ const git_index_entry **entry, git_iterator *self)
+{
+ int error;
+ tree_iterator *ti = (tree_iterator *)self;
+ tree_iterator_frame *tf = ti->head;
+
+ iterator__clear_entry(entry);
+
+ if (tf->current > tf->n_entries)
+ return 0;
- if (!tree_iterator__pop_frame(ti))
- break; /* no frames left to pop */
+ if (iterator__do_autoexpand(ti) && iterator__include_trees(ti) &&
+ tree_iterator__at_tree(ti))
+ return tree_iterator__advance_into(entry, self);
+ if (ti->path_has_filename) {
git_buf_rtruncate_at_char(&ti->path, '/');
+ ti->path_has_filename = false;
}
- if (te && git_tree_entry__is_tree(te))
- error = tree_iterator__expand_tree(ti);
+ /* scan forward and up, advancing in frame or popping frame when done */
+ while (!tree_iterator__move_to_next(ti, tf) && tree_iterator__pop_frame(ti))
+ tf = ti->head;
- if (!error)
- error = tree_iterator__current(self, entry);
+ /* find next and load trees */
+ if ((error = tree_iterator__set_next(ti, tf)) < 0)
+ return error;
- return error;
+ /* deal with include_trees / auto_expand as needed */
+ if (!iterator__include_trees(ti) && tree_iterator__at_tree(ti))
+ return tree_iterator__advance_into(entry, self);
+
+ return tree_iterator__current(entry, self);
}
static int tree_iterator__seek(git_iterator *self, const char *prefix)
{
- GIT_UNUSED(self);
- GIT_UNUSED(prefix);
- /* pop stack until matches prefix */
- /* seek item in current frame matching prefix */
- /* push stack which matches prefix */
+ GIT_UNUSED(self); GIT_UNUSED(prefix);
return -1;
}
-static void tree_iterator__free(git_iterator *self)
+static int tree_iterator__reset(
+ git_iterator *self, const char *start, const char *end)
{
tree_iterator *ti = (tree_iterator *)self;
- while (tree_iterator__pop_frame(ti)) /* pop all */;
+ while (tree_iterator__pop_frame(ti)) /* pop to top */;
+ ti->top->current = 0;
- tree_iterator__free_frame(ti->stack);
- ti->stack = ti->tail = NULL;
+ if (iterator__reset_range(self, start, end) < 0)
+ return -1;
+ git_buf_clear(&ti->path);
+ ti->path_ambiguities = 0;
- git_buf_free(&ti->path);
+ return tree_iterator__push_frame(ti); /* re-expand top tree */
}
-static int tree_iterator__reset(
- git_iterator *self, const char *start, const char *end)
+static int tree_iterator__at_end(git_iterator *self)
{
tree_iterator *ti = (tree_iterator *)self;
+ return (ti->head->current >= ti->head->n_entries);
+}
- while (tree_iterator__pop_frame(ti)) /* pop all */;
+static void tree_iterator__free(git_iterator *self)
+{
+ tree_iterator *ti = (tree_iterator *)self;
- if (iterator__reset_range(self, start, end) < 0)
- return -1;
+ while (tree_iterator__pop_frame(ti)) /* pop to top */;
- /* reset start position */
- tree_iterator__frame_seek_start(ti->stack);
+ if (ti->head) {
+ tree_iterator__free_tree(&ti->head->entries[0]);
+ git__free(ti->head);
+ }
+ ti->head = ti->top = NULL;
- git_buf_clear(&ti->path);
- ti->path_has_filename = false;
+ git_buf_free(&ti->path);
+}
+
+static int tree_iterator__create_top_frame(tree_iterator *ti, git_tree *tree)
+{
+ size_t sz = sizeof(tree_iterator_frame) + sizeof(tree_iterator_entry);
+ tree_iterator_frame *top = git__calloc(sz, sizeof(char));
+ GITERR_CHECK_ALLOC(top);
+
+ top->n_entries = 1;
+ top->next = 1;
+ top->start = ti->base.start;
+ top->startlen = top->start ? strlen(top->start) : 0;
+ top->entries[0].tree = tree;
+
+ ti->head = ti->top = top;
- return tree_iterator__expand_tree(ti);
+ return 0;
}
-int git_iterator_for_tree_range(
+int git_iterator_for_tree(
git_iterator **iter,
git_tree *tree,
git_iterator_flag_t flags,
@@ -455,21 +609,19 @@ int git_iterator_for_tree_range(
tree_iterator *ti;
if (tree == NULL)
- return git_iterator_for_nothing(iter, flags);
+ return git_iterator_for_nothing(iter, flags, start, end);
if ((error = git_tree__dup(&tree, tree)) < 0)
return error;
- ITERATOR_BASE_INIT(ti, tree, TREE);
-
- ti->base.repo = git_tree_owner(tree);
+ ITERATOR_BASE_INIT(ti, tree, TREE, git_tree_owner(tree));
- if ((error = iterator_update_ignore_case((git_iterator *)ti, flags)) < 0)
+ if ((error = iterator__update_ignore_case((git_iterator *)ti, flags)) < 0)
goto fail;
+ ti->strncomp = iterator__ignore_case(ti) ? git__strncasecmp : git__strncmp;
- ti->stack = ti->tail = tree_iterator__alloc_frame(ti, tree, ti->base.start);
-
- if ((error = tree_iterator__expand_tree(ti)) < 0)
+ if ((error = tree_iterator__create_top_frame(ti, tree)) < 0 ||
+ (error = tree_iterator__push_frame(ti)) < 0) /* expand top right now */
goto fail;
*iter = (git_iterator *)ti;
@@ -486,14 +638,94 @@ typedef struct {
git_iterator_callbacks cb;
git_index *index;
size_t current;
+ /* when not in autoexpand mode, use these to represent "tree" state */
+ git_buf partial;
+ size_t partial_pos;
+ char restore_terminator;
+ git_index_entry tree_entry;
} index_iterator;
+static const git_index_entry *index_iterator__index_entry(index_iterator *ii)
+{
+ const git_index_entry *ie = git_index_get_byindex(ii->index, ii->current);
+
+ if (ie != NULL && iterator__past_end(ii, ie->path)) {
+ ii->current = git_index_entrycount(ii->index);
+ ie = NULL;
+ }
+
+ return ie;
+}
+
+static const git_index_entry *index_iterator__skip_conflicts(index_iterator *ii)
+{
+ const git_index_entry *ie;
+
+ while ((ie = index_iterator__index_entry(ii)) != NULL &&
+ git_index_entry_stage(ie) != 0)
+ ii->current++;
+
+ return ie;
+}
+
+static void index_iterator__next_prefix_tree(index_iterator *ii)
+{
+ const char *slash;
+
+ if (!iterator__include_trees(ii))
+ return;
+
+ slash = strchr(&ii->partial.ptr[ii->partial_pos], '/');
+
+ if (slash != NULL) {
+ ii->partial_pos = (slash - ii->partial.ptr) + 1;
+ ii->restore_terminator = ii->partial.ptr[ii->partial_pos];
+ ii->partial.ptr[ii->partial_pos] = '\0';
+ } else {
+ ii->partial_pos = ii->partial.size;
+ }
+
+ if (index_iterator__index_entry(ii) == NULL)
+ ii->partial_pos = ii->partial.size;
+}
+
+static int index_iterator__first_prefix_tree(index_iterator *ii)
+{
+ const git_index_entry *ie = index_iterator__skip_conflicts(ii);
+ const char *scan, *prior, *slash;
+
+ if (!ie || !iterator__include_trees(ii))
+ return 0;
+
+ /* find longest common prefix with prior index entry */
+ for (scan = slash = ie->path, prior = ii->partial.ptr;
+ *scan && *scan == *prior; ++scan, ++prior)
+ if (*scan == '/')
+ slash = scan;
+
+ if (git_buf_sets(&ii->partial, ie->path) < 0)
+ return -1;
+
+ ii->partial_pos = (slash - ie->path) + 1;
+ index_iterator__next_prefix_tree(ii);
+
+ return 0;
+}
+
+#define index_iterator__at_tree(I) \
+ (iterator__include_trees(I) && (I)->partial_pos < (I)->partial.size)
+
static int index_iterator__current(
- git_iterator *self, const git_index_entry **entry)
+ const git_index_entry **entry, git_iterator *self)
{
index_iterator *ii = (index_iterator *)self;
const git_index_entry *ie = git_index_get_byindex(ii->index, ii->current);
+ if (ie != NULL && index_iterator__at_tree(ii)) {
+ ii->tree_entry.path = ii->partial.ptr;
+ ie = &ii->tree_entry;
+ }
+
if (entry)
*entry = ie;
@@ -506,47 +738,59 @@ static int index_iterator__at_end(git_iterator *self)
return (ii->current >= git_index_entrycount(ii->index));
}
-static void index_iterator__skip_conflicts(
- index_iterator *ii)
+static int index_iterator__advance(
+ const git_index_entry **entry, git_iterator *self)
{
+ index_iterator *ii = (index_iterator *)self;
size_t entrycount = git_index_entrycount(ii->index);
const git_index_entry *ie;
- while (ii->current < entrycount) {
- ie = git_index_get_byindex(ii->index, ii->current);
+ if (index_iterator__at_tree(ii)) {
+ if (iterator__do_autoexpand(ii)) {
+ ii->partial.ptr[ii->partial_pos] = ii->restore_terminator;
+ index_iterator__next_prefix_tree(ii);
+ } else {
+ /* advance to sibling tree (i.e. find entry with new prefix) */
+ while (ii->current < entrycount) {
+ ii->current++;
+
+ if (!(ie = git_index_get_byindex(ii->index, ii->current)) ||
+ ii->base.prefixcomp(ie->path, ii->partial.ptr) != 0)
+ break;
+ }
- if (ie == NULL ||
- (ii->base.end != NULL &&
- ii->base.prefixcomp(ie->path, ii->base.end) > 0)) {
- ii->current = entrycount;
- break;
+ if (index_iterator__first_prefix_tree(ii) < 0)
+ return -1;
}
+ } else {
+ if (ii->current < entrycount)
+ ii->current++;
- if (git_index_entry_stage(ie) == 0)
- break;
-
- ii->current++;
+ if (index_iterator__first_prefix_tree(ii) < 0)
+ return -1;
}
+
+ return index_iterator__current(entry, self);
}
-static int index_iterator__advance(
- git_iterator *self, const git_index_entry **entry)
+static int index_iterator__advance_into(
+ const git_index_entry **entry, git_iterator *self)
{
index_iterator *ii = (index_iterator *)self;
+ const git_index_entry *ie = git_index_get_byindex(ii->index, ii->current);
- if (ii->current < git_index_entrycount(ii->index))
- ii->current++;
-
- index_iterator__skip_conflicts(ii);
+ if (ie != NULL && index_iterator__at_tree(ii)) {
+ if (ii->restore_terminator)
+ ii->partial.ptr[ii->partial_pos] = ii->restore_terminator;
+ index_iterator__next_prefix_tree(ii);
+ }
- return index_iterator__current(self, entry);
+ return index_iterator__current(entry, self);
}
static int index_iterator__seek(git_iterator *self, const char *prefix)
{
- GIT_UNUSED(self);
- GIT_UNUSED(prefix);
- /* find last item before prefix */
+ GIT_UNUSED(self); GIT_UNUSED(prefix);
return -1;
}
@@ -554,11 +798,31 @@ static int index_iterator__reset(
git_iterator *self, const char *start, const char *end)
{
index_iterator *ii = (index_iterator *)self;
+ const git_index_entry *ie;
+
if (iterator__reset_range(self, start, end) < 0)
return -1;
+
ii->current = ii->base.start ?
git_index__prefix_position(ii->index, ii->base.start) : 0;
- index_iterator__skip_conflicts(ii);
+
+ if ((ie = index_iterator__skip_conflicts(ii)) == NULL)
+ return 0;
+
+ if (git_buf_sets(&ii->partial, ie->path) < 0)
+ return -1;
+
+ ii->partial_pos = 0;
+
+ if (ii->base.start) {
+ size_t startlen = strlen(ii->base.start);
+
+ ii->partial_pos = (startlen > ii->partial.size) ?
+ ii->partial.size : startlen;
+ }
+
+ index_iterator__next_prefix_tree(ii);
+
return 0;
}
@@ -567,9 +831,11 @@ static void index_iterator__free(git_iterator *self)
index_iterator *ii = (index_iterator *)self;
git_index_free(ii->index);
ii->index = NULL;
+
+ git_buf_free(&ii->partial);
}
-int git_iterator_for_index_range(
+int git_iterator_for_index(
git_iterator **iter,
git_index *index,
git_iterator_flag_t flags,
@@ -578,18 +844,19 @@ int git_iterator_for_index_range(
{
index_iterator *ii;
- GIT_UNUSED(flags);
-
- ITERATOR_BASE_INIT(ii, index, INDEX);
+ ITERATOR_BASE_INIT(ii, index, INDEX, git_index_owner(index));
- ii->base.repo = git_index_owner(index);
if (index->ignore_case) {
ii->base.flags |= GIT_ITERATOR_IGNORE_CASE;
ii->base.prefixcomp = git__prefixcmp_icase;
}
+
ii->index = index;
GIT_REFCOUNT_INC(index);
+ git_buf_init(&ii->partial, 0);
+ ii->tree_entry.mode = GIT_FILEMODE_TREE;
+
index_iterator__reset((git_iterator *)ii, NULL, NULL);
*iter = (git_iterator *)ii;
@@ -598,6 +865,8 @@ int git_iterator_for_index_range(
}
+#define WORKDIR_MAX_DEPTH 100
+
typedef struct workdir_iterator_frame workdir_iterator_frame;
struct workdir_iterator_frame {
workdir_iterator_frame *next;
@@ -615,6 +884,7 @@ typedef struct {
git_buf path;
size_t root_len;
int is_ignored;
+ int depth;
} workdir_iterator;
GIT_INLINE(bool) path_is_dotgit(const git_path_with_stat *ps)
@@ -643,7 +913,7 @@ static workdir_iterator_frame *workdir_iterator__alloc_frame(
{
workdir_iterator_frame *wf = git__calloc(1, sizeof(workdir_iterator_frame));
git_vector_cmp entry_compare = CASESELECT(
- (wi->base.flags & GIT_ITERATOR_IGNORE_CASE) != 0,
+ iterator__ignore_case(wi),
git_path_with_stat_cmp_icase, git_path_with_stat_cmp);
if (wf == NULL)
@@ -701,12 +971,18 @@ static void workdir_iterator__seek_frame_start(
static int workdir_iterator__expand_dir(workdir_iterator *wi)
{
int error;
- workdir_iterator_frame *wf = workdir_iterator__alloc_frame(wi);
+ workdir_iterator_frame *wf;
+
+ if (++(wi->depth) > WORKDIR_MAX_DEPTH) {
+ giterr_set(GITERR_REPOSITORY, "Working directory is too deep");
+ return -1;
+ }
+
+ wf = workdir_iterator__alloc_frame(wi);
GITERR_CHECK_ALLOC(wf);
error = git_path_dirload_with_stat(
- wi->path.ptr, wi->root_len,
- (wi->base.flags & GIT_ITERATOR_IGNORE_CASE) != 0,
+ wi->path.ptr, wi->root_len, iterator__ignore_case(wi),
wi->base.start, wi->base.end, &wf->entries);
if (error < 0 || wf->entries.length == 0) {
@@ -729,10 +1005,11 @@ static int workdir_iterator__expand_dir(workdir_iterator *wi)
}
static int workdir_iterator__current(
- git_iterator *self, const git_index_entry **entry)
+ const git_index_entry **entry, git_iterator *self)
{
workdir_iterator *wi = (workdir_iterator *)self;
- *entry = (wi->entry.path == NULL) ? NULL : &wi->entry;
+ if (entry)
+ *entry = (wi->entry.path == NULL) ? NULL : &wi->entry;
return 0;
}
@@ -741,21 +1018,56 @@ static int workdir_iterator__at_end(git_iterator *self)
return (((workdir_iterator *)self)->entry.path == NULL);
}
+static int workdir_iterator__advance_into(
+ const git_index_entry **entry, git_iterator *iter)
+{
+ int error = 0;
+ workdir_iterator *wi = (workdir_iterator *)iter;
+
+ iterator__clear_entry(entry);
+
+ /* workdir iterator will allow you to explicitly advance into a
+ * commit/submodule (as well as a tree) to avoid some cases where an
+ * entry is mislabeled as a submodule in the working directory
+ */
+ if (wi->entry.path != NULL &&
+ (wi->entry.mode == GIT_FILEMODE_TREE ||
+ wi->entry.mode == GIT_FILEMODE_COMMIT))
+ /* returns GIT_ENOTFOUND if the directory is empty */
+ error = workdir_iterator__expand_dir(wi);
+
+ if (!error && entry)
+ error = workdir_iterator__current(entry, iter);
+
+ return error;
+}
+
static int workdir_iterator__advance(
- git_iterator *self, const git_index_entry **entry)
+ const git_index_entry **entry, git_iterator *self)
{
- int error;
+ int error = 0;
workdir_iterator *wi = (workdir_iterator *)self;
workdir_iterator_frame *wf;
git_path_with_stat *next;
+ /* given include_trees & autoexpand, we might have to go into a tree */
+ if (iterator__do_autoexpand(wi) &&
+ wi->entry.path != NULL &&
+ wi->entry.mode == GIT_FILEMODE_TREE)
+ {
+ error = workdir_iterator__advance_into(entry, self);
+
+ /* continue silently past empty directories if autoexpanding */
+ if (error != GIT_ENOTFOUND)
+ return error;
+ giterr_clear();
+ error = 0;
+ }
+
if (entry != NULL)
*entry = NULL;
- if (wi->entry.path == NULL)
- return 0;
-
- while (1) {
+ while (wi->entry.path != NULL) {
wf = wi->stack;
next = git_vector_get(&wf->entries, ++wf->index);
@@ -781,7 +1093,7 @@ static int workdir_iterator__advance(
error = workdir_iterator__update_entry(wi);
if (!error && entry != NULL)
- error = workdir_iterator__current(self, entry);
+ error = workdir_iterator__current(entry, self);
return error;
}
@@ -832,6 +1144,7 @@ static void workdir_iterator__free(git_iterator *self)
static int workdir_iterator__update_entry(workdir_iterator *wi)
{
+ int error = 0;
git_path_with_stat *ps =
git_vector_get(&wi->stack->entries, wi->stack->index);
@@ -841,19 +1154,18 @@ static int workdir_iterator__update_entry(workdir_iterator *wi)
if (!ps)
return 0;
+ /* skip over .git entries */
+ if (path_is_dotgit(ps))
+ return workdir_iterator__advance(NULL, (git_iterator *)wi);
+
if (git_buf_put(&wi->path, ps->path, ps->path_len) < 0)
return -1;
- if (wi->base.end &&
- wi->base.prefixcomp(wi->path.ptr + wi->root_len, wi->base.end) > 0)
+ if (iterator__past_end(wi, wi->path.ptr + wi->root_len))
return 0;
wi->entry.path = ps->path;
- /* skip over .git entries */
- if (path_is_dotgit(ps))
- return workdir_iterator__advance((git_iterator *)wi, NULL);
-
wi->is_ignored = -1;
git_index_entry__init_from_stat(&wi->entry, &ps->st);
@@ -867,26 +1179,32 @@ static int workdir_iterator__update_entry(workdir_iterator *wi)
return 0;
}
+ /* if this isn't a tree, then we're done */
+ if (wi->entry.mode != GIT_FILEMODE_TREE)
+ return 0;
+
/* detect submodules */
- if (S_ISDIR(wi->entry.mode)) {
- int res = git_submodule_lookup(NULL, wi->base.repo, wi->entry.path);
- bool is_submodule = (res == 0);
- if (res == GIT_ENOTFOUND)
- giterr_clear();
-
- /* if submodule, mark as GITLINK and remove trailing slash */
- if (is_submodule) {
- size_t len = strlen(wi->entry.path);
- assert(wi->entry.path[len - 1] == '/');
- wi->entry.path[len - 1] = '\0';
- wi->entry.mode = S_IFGITLINK;
- }
+
+ error = git_submodule_lookup(NULL, wi->base.repo, wi->entry.path);
+ if (error == GIT_ENOTFOUND)
+ giterr_clear();
+
+ /* if submodule, mark as GITLINK and remove trailing slash */
+ if (!error) {
+ size_t len = strlen(wi->entry.path);
+ assert(wi->entry.path[len - 1] == '/');
+ wi->entry.path[len - 1] = '\0';
+ wi->entry.mode = S_IFGITLINK;
+ return 0;
}
- return 0;
+ if (iterator__include_trees(wi))
+ return 0;
+
+ return workdir_iterator__advance_into(NULL, (git_iterator *)wi);
}
-int git_iterator_for_workdir_range(
+int git_iterator_for_workdir(
git_iterator **iter,
git_repository *repo,
git_iterator_flag_t flags,
@@ -899,13 +1217,12 @@ int git_iterator_for_workdir_range(
assert(iter && repo);
if ((error = git_repository__ensure_not_bare(
- repo, "scan working directory")) < 0)
+ repo, "scan working directory")) < 0)
return error;
- ITERATOR_BASE_INIT(wi, workdir, WORKDIR);
- wi->base.repo = repo;
+ ITERATOR_BASE_INIT(wi, workdir, WORKDIR, repo);
- if ((error = iterator_update_ignore_case((git_iterator *)wi, flags)) < 0)
+ if ((error = iterator__update_ignore_case((git_iterator *)wi, flags)) < 0)
goto fail;
if (git_buf_sets(&wi->path, git_repository_workdir(repo)) < 0 ||
@@ -917,7 +1234,7 @@ int git_iterator_for_workdir_range(
}
wi->root_len = wi->path.size;
- wi->entrycmp = (wi->base.flags & GIT_ITERATOR_IGNORE_CASE) != 0 ?
+ wi->entrycmp = iterator__ignore_case(wi) ?
workdir_iterator__entry_cmp_icase : workdir_iterator__entry_cmp_case;
if ((error = workdir_iterator__expand_dir(wi)) < 0) {
@@ -935,161 +1252,6 @@ fail:
}
-typedef struct {
- /* replacement callbacks */
- git_iterator_callbacks cb;
- /* original iterator values */
- git_iterator_callbacks *orig;
- git_iterator_type_t orig_type;
- /* spoolandsort data */
- git_vector entries;
- git_pool entry_pool;
- git_pool string_pool;
- size_t position;
-} spoolandsort_callbacks;
-
-static int spoolandsort_iterator__current(
- git_iterator *self, const git_index_entry **entry)
-{
- spoolandsort_callbacks *scb = (spoolandsort_callbacks *)self->cb;
-
- *entry = (const git_index_entry *)
- git_vector_get(&scb->entries, scb->position);
-
- return 0;
-}
-
-static int spoolandsort_iterator__at_end(git_iterator *self)
-{
- spoolandsort_callbacks *scb = (spoolandsort_callbacks *)self->cb;
-
- return 0 == scb->entries.length || scb->entries.length - 1 <= scb->position;
-}
-
-static int spoolandsort_iterator__advance(
- git_iterator *self, const git_index_entry **entry)
-{
- spoolandsort_callbacks *scb = (spoolandsort_callbacks *)self->cb;
-
- *entry = (const git_index_entry *)
- git_vector_get(&scb->entries, ++scb->position);
-
- return 0;
-}
-
-static int spoolandsort_iterator__seek(git_iterator *self, const char *prefix)
-{
- GIT_UNUSED(self);
- GIT_UNUSED(prefix);
-
- return -1;
-}
-
-static int spoolandsort_iterator__reset(
- git_iterator *self, const char *start, const char *end)
-{
- spoolandsort_callbacks *scb = (spoolandsort_callbacks *)self->cb;
-
- GIT_UNUSED(start); GIT_UNUSED(end);
-
- scb->position = 0;
-
- return 0;
-}
-
-static void spoolandsort_iterator__free_callbacks(spoolandsort_callbacks *scb)
-{
- git_pool_clear(&scb->string_pool);
- git_pool_clear(&scb->entry_pool);
- git_vector_free(&scb->entries);
- git__free(scb);
-}
-
-void git_iterator_spoolandsort_pop(git_iterator *self)
-{
- spoolandsort_callbacks *scb = (spoolandsort_callbacks *)self->cb;
-
- if (self->type != GIT_ITERATOR_TYPE_SPOOLANDSORT)
- return;
-
- self->cb = scb->orig;
- self->type = scb->orig_type;
- self->flags ^= GIT_ITERATOR_IGNORE_CASE;
-
- spoolandsort_iterator__free_callbacks(scb);
-}
-
-static void spoolandsort_iterator__free(git_iterator *self)
-{
- git_iterator_spoolandsort_pop(self);
- self->cb->free(self);
-}
-
-int git_iterator_spoolandsort_push(git_iterator *iter, bool ignore_case)
-{
- const git_index_entry *item;
- spoolandsort_callbacks *scb;
- int (*entrycomp)(const void *a, const void *b);
-
- if (((iter->flags & GIT_ITERATOR_IGNORE_CASE) != 0) == (ignore_case != 0))
- return 0;
-
- if (iter->type == GIT_ITERATOR_TYPE_EMPTY) {
- iter->flags = (iter->flags ^ GIT_ITERATOR_IGNORE_CASE);
- return 0;
- }
-
- scb = git__calloc(1, sizeof(spoolandsort_callbacks));
- GITERR_CHECK_ALLOC(scb);
-
- ITERATOR_SET_CB(scb,spoolandsort);
-
- scb->orig = iter->cb;
- scb->orig_type = iter->type;
- scb->position = 0;
-
- entrycomp = ignore_case ? git_index_entry__cmp_icase : git_index_entry__cmp;
-
- if (git_vector_init(&scb->entries, 16, entrycomp) < 0 ||
- git_pool_init(&scb->entry_pool, sizeof(git_index_entry), 0) < 0 ||
- git_pool_init(&scb->string_pool, 1, 0) < 0 ||
- git_iterator_current(iter, &item) < 0)
- goto fail;
-
- while (item) {
- git_index_entry *clone = git_pool_malloc(&scb->entry_pool, 1);
- if (!clone)
- goto fail;
-
- memcpy(clone, item, sizeof(git_index_entry));
-
- if (item->path) {
- clone->path = git_pool_strdup(&scb->string_pool, item->path);
- if (!clone->path)
- goto fail;
- }
-
- if (git_vector_insert(&scb->entries, clone) < 0)
- goto fail;
-
- if (git_iterator_advance(iter, &item) < 0)
- goto fail;
- }
-
- git_vector_sort(&scb->entries);
-
- iter->cb = (git_iterator_callbacks *)scb;
- iter->type = GIT_ITERATOR_TYPE_SPOOLANDSORT;
- iter->flags ^= GIT_ITERATOR_IGNORE_CASE;
-
- return 0;
-
-fail:
- spoolandsort_iterator__free_callbacks(scb);
- return -1;
-}
-
-
void git_iterator_free(git_iterator *iter)
{
if (iter == NULL)
@@ -1105,110 +1267,94 @@ void git_iterator_free(git_iterator *iter)
git__free(iter);
}
-git_index *git_iterator_index_get_index(git_iterator *iter)
+int git_iterator_set_ignore_case(git_iterator *iter, bool ignore_case)
{
- if (iter->type == GIT_ITERATOR_TYPE_INDEX)
- return ((index_iterator *)iter)->index;
+ bool desire_ignore_case = (ignore_case != 0);
- if (iter->type == GIT_ITERATOR_TYPE_SPOOLANDSORT &&
- ((spoolandsort_callbacks *)iter->cb)->orig_type == GIT_ITERATOR_TYPE_INDEX)
- return ((index_iterator *)iter)->index;
+ if (iterator__ignore_case(iter) == desire_ignore_case)
+ return 0;
- return NULL;
+ if (iter->type == GIT_ITERATOR_TYPE_EMPTY) {
+ if (desire_ignore_case)
+ iter->flags |= GIT_ITERATOR_IGNORE_CASE;
+ else
+ iter->flags &= ~GIT_ITERATOR_IGNORE_CASE;
+ } else {
+ giterr_set(GITERR_INVALID,
+ "Cannot currently set ignore case on non-empty iterators");
+ return -1;
+ }
+
+ return 0;
}
-git_iterator_type_t git_iterator_inner_type(git_iterator *iter)
+git_index *git_iterator_get_index(git_iterator *iter)
{
- if (iter->type == GIT_ITERATOR_TYPE_SPOOLANDSORT)
- return ((spoolandsort_callbacks *)iter->cb)->orig_type;
-
- return iter->type;
+ if (iter->type == GIT_ITERATOR_TYPE_INDEX)
+ return ((index_iterator *)iter)->index;
+ return NULL;
}
int git_iterator_current_tree_entry(
- git_iterator *iter, const git_tree_entry **tree_entry)
+ const git_tree_entry **tree_entry, git_iterator *iter)
{
- *tree_entry = (iter->type != GIT_ITERATOR_TYPE_TREE) ? NULL :
- tree_iterator__tree_entry((tree_iterator *)iter);
+ if (iter->type != GIT_ITERATOR_TYPE_TREE)
+ *tree_entry = NULL;
+ else {
+ tree_iterator_frame *tf = ((tree_iterator *)iter)->head;
+ *tree_entry = tree_iterator__tree_entry_by_index(tf, tf->current);
+ }
+
return 0;
}
int git_iterator_current_parent_tree(
+ const git_tree **tree_ptr,
git_iterator *iter,
- const char *parent_path,
- const git_tree **tree_ptr)
+ const char *parent_path)
{
tree_iterator *ti = (tree_iterator *)iter;
tree_iterator_frame *tf;
const char *scan = parent_path;
- int (*strncomp)(const char *a, const char *b, size_t sz);
+ const git_tree_entry *te;
- if (iter->type != GIT_ITERATOR_TYPE_TREE || ti->stack == NULL)
- goto notfound;
+ *tree_ptr = NULL;
- strncomp = ((iter->flags & GIT_ITERATOR_IGNORE_CASE) != 0) ?
- git__strncasecmp : git__strncmp;
+ if (iter->type != GIT_ITERATOR_TYPE_TREE)
+ return 0;
- for (tf = ti->tail; tf != NULL; tf = tf->prev) {
- const git_tree_entry *te;
+ tf = ti->top;
- if (!*scan) {
- *tree_ptr = tf->tree;
+ while (*scan) {
+ /* get entry of this parent that child is currently on */
+ if (!(tf = tf->child) ||
+ !(te = tree_iterator__tree_entry_by_index(tf, tf->current)) ||
+ ti->strncomp(scan, te->filename, te->filename_len) != 0)
return 0;
- }
-
- te = git_tree_entry_byindex(tf->tree,
- tf->icase_map ? (size_t)tf->icase_map[tf->index] : tf->index);
-
- if (strncomp(scan, te->filename, te->filename_len) != 0)
- goto notfound;
scan += te->filename_len;
-
- if (*scan) {
- if (*scan != '/')
- goto notfound;
+ if (*scan == '/')
scan++;
- }
}
-notfound:
- *tree_ptr = NULL;
+ *tree_ptr = tf->entries[tf->current].tree;
return 0;
}
-int git_iterator_current_is_ignored(git_iterator *iter)
+bool git_iterator_current_is_ignored(git_iterator *iter)
{
workdir_iterator *wi = (workdir_iterator *)iter;
if (iter->type != GIT_ITERATOR_TYPE_WORKDIR)
- return 0;
+ return false;
if (wi->is_ignored != -1)
- return wi->is_ignored;
+ return (bool)(wi->is_ignored != 0);
if (git_ignore__lookup(&wi->ignores, wi->entry.path, &wi->is_ignored) < 0)
- wi->is_ignored = 1;
+ wi->is_ignored = true;
- return wi->is_ignored;
-}
-
-int git_iterator_advance_into_directory(
- git_iterator *iter, const git_index_entry **entry)
-{
- workdir_iterator *wi = (workdir_iterator *)iter;
-
- if (iter->type == GIT_ITERATOR_TYPE_WORKDIR &&
- wi->entry.path &&
- (wi->entry.mode == GIT_FILEMODE_TREE ||
- wi->entry.mode == GIT_FILEMODE_COMMIT))
- {
- if (workdir_iterator__expand_dir(wi) < 0)
- /* if error loading or if empty, skip the directory. */
- return workdir_iterator__advance(iter, entry);
- }
-
- return entry ? git_iterator_current(iter, entry) : 0;
+ return (bool)wi->is_ignored;
}
int git_iterator_cmp(git_iterator *iter, const char *path_prefix)
@@ -1216,8 +1362,7 @@ int git_iterator_cmp(git_iterator *iter, const char *path_prefix)
const git_index_entry *entry;
/* a "done" iterator is after every prefix */
- if (git_iterator_current(iter, &entry) < 0 ||
- entry == NULL)
+ if (git_iterator_current(&entry, iter) < 0 || entry == NULL)
return 1;
/* a NULL prefix is after any valid iterator */
@@ -1227,7 +1372,7 @@ int git_iterator_cmp(git_iterator *iter, const char *path_prefix)
return iter->prefixcomp(entry->path, path_prefix);
}
-int git_iterator_current_workdir_path(git_iterator *iter, git_buf **path)
+int git_iterator_current_workdir_path(git_buf **path, git_iterator *iter)
{
workdir_iterator *wi = (workdir_iterator *)iter;
@@ -1238,4 +1383,3 @@ int git_iterator_current_workdir_path(git_iterator *iter, git_buf **path)
return 0;
}
-
diff --git a/src/iterator.h b/src/iterator.h
index a9bccfca8..4a4e6a9d8 100644
--- a/src/iterator.h
+++ b/src/iterator.h
@@ -12,11 +12,6 @@
#include "vector.h"
#include "buffer.h"
-#define ITERATOR_PREFIXCMP(ITER, STR, PREFIX) \
- (((ITER).flags & GIT_ITERATOR_IGNORE_CASE) != 0 ? \
- git__prefixcmp_icase((STR), (PREFIX)) : \
- git__prefixcmp((STR), (PREFIX)))
-
typedef struct git_iterator git_iterator;
typedef enum {
@@ -24,20 +19,26 @@ typedef enum {
GIT_ITERATOR_TYPE_TREE = 1,
GIT_ITERATOR_TYPE_INDEX = 2,
GIT_ITERATOR_TYPE_WORKDIR = 3,
- GIT_ITERATOR_TYPE_SPOOLANDSORT = 4
} git_iterator_type_t;
typedef enum {
- GIT_ITERATOR_IGNORE_CASE = (1 << 0), /* ignore_case */
- GIT_ITERATOR_DONT_IGNORE_CASE = (1 << 1), /* force ignore_case off */
+ /** ignore case for entry sort order */
+ GIT_ITERATOR_IGNORE_CASE = (1 << 0),
+ /** force case sensitivity for entry sort order */
+ GIT_ITERATOR_DONT_IGNORE_CASE = (1 << 1),
+ /** return tree items in addition to blob items */
+ GIT_ITERATOR_INCLUDE_TREES = (1 << 2),
+ /** don't flatten trees, requiring advance_into (implies INCLUDE_TREES) */
+ GIT_ITERATOR_DONT_AUTOEXPAND = (1 << 3),
} git_iterator_flag_t;
typedef struct {
- int (*current)(git_iterator *, const git_index_entry **);
- int (*at_end)(git_iterator *);
- int (*advance)(git_iterator *, const git_index_entry **);
+ int (*current)(const git_index_entry **, git_iterator *);
+ int (*advance)(const git_index_entry **, git_iterator *);
+ int (*advance_into)(const git_index_entry **, git_iterator *);
int (*seek)(git_iterator *, const char *prefix);
int (*reset)(git_iterator *, const char *start, const char *end);
+ int (*at_end)(git_iterator *);
void (*free)(git_iterator *);
} git_iterator_callbacks;
@@ -52,86 +53,92 @@ struct git_iterator {
};
extern int git_iterator_for_nothing(
- git_iterator **out, git_iterator_flag_t flags);
+ git_iterator **out,
+ git_iterator_flag_t flags,
+ const char *start,
+ const char *end);
/* tree iterators will match the ignore_case value from the index of the
* repository, unless you override with a non-zero flag value
*/
-extern int git_iterator_for_tree_range(
+extern int git_iterator_for_tree(
git_iterator **out,
git_tree *tree,
git_iterator_flag_t flags,
const char *start,
const char *end);
-GIT_INLINE(int) git_iterator_for_tree(git_iterator **out, git_tree *tree)
-{
- return git_iterator_for_tree_range(out, tree, 0, NULL, NULL);
-}
-
/* index iterators will take the ignore_case value from the index; the
* ignore_case flags are not used
*/
-extern int git_iterator_for_index_range(
+extern int git_iterator_for_index(
git_iterator **out,
git_index *index,
git_iterator_flag_t flags,
const char *start,
const char *end);
-GIT_INLINE(int) git_iterator_for_index(git_iterator **out, git_index *index)
-{
- return git_iterator_for_index_range(out, index, 0, NULL, NULL);
-}
-
/* workdir iterators will match the ignore_case value from the index of the
* repository, unless you override with a non-zero flag value
*/
-extern int git_iterator_for_workdir_range(
+extern int git_iterator_for_workdir(
git_iterator **out,
git_repository *repo,
git_iterator_flag_t flags,
const char *start,
const char *end);
-GIT_INLINE(int) git_iterator_for_workdir(git_iterator **out, git_repository *repo)
-{
- return git_iterator_for_workdir_range(out, repo, 0, NULL, NULL);
-}
-
extern void git_iterator_free(git_iterator *iter);
-/* Spool all iterator values, resort with alternative ignore_case value
- * and replace callbacks with spoolandsort alternates.
- */
-extern int git_iterator_spoolandsort_push(git_iterator *iter, bool ignore_case);
-
-/* Restore original callbacks - not required in most circumstances */
-extern void git_iterator_spoolandsort_pop(git_iterator *iter);
-
-/* Entry is not guaranteed to be fully populated. For a tree iterator,
- * we will only populate the mode, oid and path, for example. For a workdir
- * iterator, we will not populate the oid.
+/* Return a git_index_entry structure for the current value the iterator
+ * is looking at or NULL if the iterator is at the end.
+ *
+ * The entry may noy be fully populated. Tree iterators will only have a
+ * value mode, OID, and path. Workdir iterators will not have an OID (but
+ * you can use `git_iterator_current_oid()` to calculate it on demand).
*
* You do not need to free the entry. It is still "owned" by the iterator.
- * Once you call `git_iterator_advance`, then content of the old entry is
- * no longer guaranteed to be valid.
+ * Once you call `git_iterator_advance()` then the old entry is no longer
+ * guaranteed to be valid - it may be freed or just overwritten in place.
*/
GIT_INLINE(int) git_iterator_current(
- git_iterator *iter, const git_index_entry **entry)
+ const git_index_entry **entry, git_iterator *iter)
{
- return iter->cb->current(iter, entry);
+ return iter->cb->current(entry, iter);
}
-GIT_INLINE(int) git_iterator_at_end(git_iterator *iter)
+/**
+ * Advance to the next item for the iterator.
+ *
+ * If GIT_ITERATOR_INCLUDE_TREES is set, this may be a tree item. If
+ * GIT_ITERATOR_DONT_AUTOEXPAND is set, calling this again when on a tree
+ * item will skip over all the items under that tree.
+ */
+GIT_INLINE(int) git_iterator_advance(
+ const git_index_entry **entry, git_iterator *iter)
{
- return iter->cb->at_end(iter);
+ return iter->cb->advance(entry, iter);
}
-GIT_INLINE(int) git_iterator_advance(
- git_iterator *iter, const git_index_entry **entry)
+/**
+ * Iterate into a tree item (when GIT_ITERATOR_DONT_AUTOEXPAND is set).
+ *
+ * git_iterator_advance() steps through all items being iterated over
+ * (either with or without trees, depending on GIT_ITERATOR_INCLUDE_TREES),
+ * but if GIT_ITERATOR_DONT_AUTOEXPAND is set, it will skip to the next
+ * sibling of a tree instead of going to the first child of the tree. In
+ * that case, use this function to advance to the first child of the tree.
+ *
+ * If the current item is not a tree, this is a no-op.
+ *
+ * For working directory iterators only, a tree (i.e. directory) can be
+ * empty. In that case, this function returns GIT_ENOTFOUND and does not
+ * advance. That can't happen for tree and index iterators.
+ */
+GIT_INLINE(int) git_iterator_advance_into(
+ const git_index_entry **entry, git_iterator *iter)
{
- return iter->cb->advance(iter, entry);
+ return iter->cb->advance_into(entry, iter);
}
GIT_INLINE(int) git_iterator_seek(
@@ -146,6 +153,11 @@ GIT_INLINE(int) git_iterator_reset(
return iter->cb->reset(iter, start, end);
}
+GIT_INLINE(int) git_iterator_at_end(git_iterator *iter)
+{
+ return iter->cb->at_end(iter);
+}
+
GIT_INLINE(git_iterator_type_t) git_iterator_type(git_iterator *iter)
{
return iter->type;
@@ -166,47 +178,28 @@ GIT_INLINE(bool) git_iterator_ignore_case(git_iterator *iter)
return ((iter->flags & GIT_ITERATOR_IGNORE_CASE) != 0);
}
+extern int git_iterator_set_ignore_case(git_iterator *iter, bool ignore_case);
+
extern int git_iterator_current_tree_entry(
- git_iterator *iter, const git_tree_entry **tree_entry);
+ const git_tree_entry **entry_out, git_iterator *iter);
extern int git_iterator_current_parent_tree(
- git_iterator *iter, const char *parent_path, const git_tree **tree_ptr);
+ const git_tree **tree_out, git_iterator *iter, const char *parent_path);
-extern int git_iterator_current_is_ignored(git_iterator *iter);
-
-/**
- * Iterate into a workdir directory.
- *
- * Workdir iterators do not automatically descend into directories (so that
- * when comparing two iterator entries you can detect a newly created
- * directory in the workdir). As a result, you may get S_ISDIR items from
- * a workdir iterator. If you wish to iterate over the contents of the
- * directories you encounter, then call this function when you encounter
- * a directory.
- *
- * If there are no files in the directory, this will end up acting like a
- * regular advance and will skip past the directory, so you should be
- * prepared for that case.
- *
- * On non-workdir iterators or if not pointing at a directory, this is a
- * no-op and will not advance the iterator.
- */
-extern int git_iterator_advance_into_directory(
- git_iterator *iter, const git_index_entry **entry);
+extern bool git_iterator_current_is_ignored(git_iterator *iter);
extern int git_iterator_cmp(
git_iterator *iter, const char *path_prefix);
/**
- * Get the full path of the current item from a workdir iterator.
- * This will return NULL for a non-workdir iterator.
+ * Get full path of the current item from a workdir iterator. This will
+ * return NULL for a non-workdir iterator. The git_buf is still owned by
+ * the iterator; this is exposed just for efficiency.
*/
extern int git_iterator_current_workdir_path(
- git_iterator *iter, git_buf **path);
-
-
-extern git_index *git_iterator_index_get_index(git_iterator *iter);
+ git_buf **path, git_iterator *iter);
-extern git_iterator_type_t git_iterator_inner_type(git_iterator *iter);
+/* Return index pointer if index iterator, else NULL */
+extern git_index *git_iterator_get_index(git_iterator *iter);
#endif
diff --git a/src/notes.c b/src/notes.c
index a1a47d989..ef48ac88e 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -625,7 +625,7 @@ int git_note_iterator_new(
if (error < 0)
goto cleanup;
- if ((error = git_iterator_for_tree(it, tree)) < 0)
+ if ((error = git_iterator_for_tree(it, tree, 0, NULL, NULL)) < 0)
git_iterator_free(*it);
cleanup:
@@ -643,7 +643,7 @@ int git_note_next(
int error;
const git_index_entry *item;
- if ((error = git_iterator_current(it, &item)) < 0)
+ if ((error = git_iterator_current(&item, it)) < 0)
goto exit;
if (item != NULL) {
@@ -651,7 +651,7 @@ int git_note_next(
error = process_entry_path(item->path, annotated_id);
if (error >= 0)
- error = git_iterator_advance(it, NULL);
+ error = git_iterator_advance(NULL, it);
} else {
error = GIT_ITEROVER;
}
diff --git a/src/posix.h b/src/posix.h
index 9dd0c94d3..719c8a04c 100644
--- a/src/posix.h
+++ b/src/posix.h
@@ -32,14 +32,13 @@ typedef int git_file;
* Standard POSIX Methods
*
* All the methods starting with the `p_` prefix are
- * direct ports of the standard POSIX methods.
+ * direct ports of the standard POSIX methods.
*
* Some of the methods are slightly wrapped to provide
* saner defaults. Some of these methods are emulated
* in Windows platforns.
*
* Use your manpages to check the docs on these.
- * Straightforward
*/
extern int p_read(git_file fd, void *buf, size_t cnt);
diff --git a/src/submodule.c b/src/submodule.c
index 359306498..c02061376 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -1135,10 +1135,10 @@ static int load_submodule_config_from_index(
const git_index_entry *entry;
if ((error = git_repository_index__weakptr(&index, repo)) < 0 ||
- (error = git_iterator_for_index(&i, index)) < 0)
+ (error = git_iterator_for_index(&i, index, 0, NULL, NULL)) < 0)
return error;
- error = git_iterator_current(i, &entry);
+ error = git_iterator_current(&entry, i);
while (!error && entry != NULL) {
@@ -1154,7 +1154,7 @@ static int load_submodule_config_from_index(
git_oid_cpy(gitmodules_oid, &entry->oid);
}
- error = git_iterator_advance(i, &entry);
+ error = git_iterator_advance(&entry, i);
}
git_iterator_free(i);
@@ -1173,12 +1173,12 @@ static int load_submodule_config_from_head(
if ((error = git_repository_head_tree(&head, repo)) < 0)
return error;
- if ((error = git_iterator_for_tree(&i, head)) < 0) {
+ if ((error = git_iterator_for_tree(&i, head, 0, NULL, NULL)) < 0) {
git_tree_free(head);
return error;
}
- error = git_iterator_current(i, &entry);
+ error = git_iterator_current(&entry, i);
while (!error && entry != NULL) {
@@ -1195,7 +1195,7 @@ static int load_submodule_config_from_head(
git_oid_cpy(gitmodules_oid, &entry->oid);
}
- error = git_iterator_advance(i, &entry);
+ error = git_iterator_advance(&entry, i);
}
git_iterator_free(i);
diff --git a/src/tsort.c b/src/tsort.c
index 97473be91..4885e435b 100644
--- a/src/tsort.c
+++ b/src/tsort.c
@@ -24,7 +24,7 @@
#endif
static int binsearch(
- void **dst, const void *x, size_t size, git__tsort_r_cmp cmp, void *payload)
+ void **dst, const void *x, size_t size, git__sort_r_cmp cmp, void *payload)
{
int l, c, r;
void *lx, *cx;
@@ -71,7 +71,7 @@ static int binsearch(
/* Binary insertion sort, but knowing that the first "start" entries are sorted. Used in timsort. */
static void bisort(
- void **dst, size_t start, size_t size, git__tsort_r_cmp cmp, void *payload)
+ void **dst, size_t start, size_t size, git__sort_r_cmp cmp, void *payload)
{
size_t i;
void *x;
@@ -102,7 +102,7 @@ struct tsort_run {
struct tsort_store {
size_t alloc;
- git__tsort_r_cmp cmp;
+ git__sort_r_cmp cmp;
void *payload;
void **storage;
};
@@ -334,7 +334,7 @@ static ssize_t collapse(void **dst, struct tsort_run *stack, ssize_t stack_curr,
while (0)
void git__tsort_r(
- void **dst, size_t size, git__tsort_r_cmp cmp, void *payload)
+ void **dst, size_t size, git__sort_r_cmp cmp, void *payload)
{
struct tsort_store _store, *store = &_store;
struct tsort_run run_stack[128];
diff --git a/src/unix/posix.h b/src/unix/posix.h
index c738b531d..f4886c5d1 100644
--- a/src/unix/posix.h
+++ b/src/unix/posix.h
@@ -8,6 +8,7 @@
#define INCLUDE_posix__w32_h__
#include <stdio.h>
+#include <sys/param.h>
#define p_lstat(p,b) lstat(p,b)
#define p_readlink(a, b, c) readlink(a, b, c)
diff --git a/src/util.c b/src/util.c
index 059108ece..102bbaeb3 100644
--- a/src/util.c
+++ b/src/util.c
@@ -607,3 +607,55 @@ size_t git__unescape(char *str)
return (pos - str);
}
+
+#if defined(GIT_WIN32) || defined(BSD)
+typedef struct {
+ git__sort_r_cmp cmp;
+ void *payload;
+} git__qsort_r_glue;
+
+static int GIT_STDLIB_CALL git__qsort_r_glue_cmp(
+ void *payload, const void *a, const void *b)
+{
+ git__qsort_r_glue *glue = payload;
+ return glue->cmp(a, b, glue->payload);
+}
+#endif
+
+void git__qsort_r(
+ void *els, size_t nel, size_t elsize, git__sort_r_cmp cmp, void *payload)
+{
+#if defined(__MINGW32__)
+ git__insertsort_r(els, nel, elsize, NULL, cmp, payload);
+#elif defined(GIT_WIN32)
+ git__qsort_r_glue glue = { cmp, payload };
+ qsort_s(els, nel, elsize, git__qsort_r_glue_cmp, &glue);
+#elif defined(BSD)
+ git__qsort_r_glue glue = { cmp, payload };
+ qsort_r(els, nel, elsize, &glue, git__qsort_r_glue_cmp);
+#else
+ qsort_r(els, nel, elsize, cmp, payload);
+#endif
+}
+
+void git__insertsort_r(
+ void *els, size_t nel, size_t elsize, void *swapel,
+ git__sort_r_cmp cmp, void *payload)
+{
+ uint8_t *base = els, *end = els + nel * elsize;
+ uint8_t *i, *j;
+ bool freeswap = !swapel;
+
+ if (freeswap)
+ swapel = git__malloc(elsize);
+
+ for (i = base + elsize; i < end; i += elsize)
+ for (j = i; j > base && cmp(j, j - elsize, payload) < 0; j -= elsize) {
+ memcpy(swapel, j, elsize);
+ memcpy(j, j - elsize, elsize);
+ memcpy(j - elsize, swapel, elsize);
+ }
+
+ if (freeswap)
+ git__free(swapel);
+}
diff --git a/src/util.h b/src/util.h
index 9dbcb6a4f..c0f271997 100644
--- a/src/util.h
+++ b/src/util.h
@@ -146,11 +146,17 @@ typedef int (*git__tsort_cmp)(const void *a, const void *b);
extern void git__tsort(void **dst, size_t size, git__tsort_cmp cmp);
-typedef int (*git__tsort_r_cmp)(const void *a, const void *b, void *payload);
+typedef int (*git__sort_r_cmp)(const void *a, const void *b, void *payload);
extern void git__tsort_r(
- void **dst, size_t size, git__tsort_r_cmp cmp, void *payload);
+ void **dst, size_t size, git__sort_r_cmp cmp, void *payload);
+extern void git__qsort_r(
+ void *els, size_t nel, size_t elsize, git__sort_r_cmp cmp, void *payload);
+
+extern void git__insertsort_r(
+ void *els, size_t nel, size_t elsize, void *swapel,
+ git__sort_r_cmp cmp, void *payload);
/**
* @param position If non-NULL, this will be set to the position where the
diff --git a/tests-clar/diff/iterator.c b/tests-clar/diff/iterator.c
index efdadbf1f..f1efdfbba 100644
--- a/tests-clar/diff/iterator.c
+++ b/tests-clar/diff/iterator.c
@@ -35,26 +35,26 @@ static void tree_iterator_test(
git_repository *repo = cl_git_sandbox_init(sandbox);
cl_assert(t = resolve_commit_oid_to_tree(repo, treeish));
- cl_git_pass(git_iterator_for_tree_range(
+ cl_git_pass(git_iterator_for_tree(
&i, t, GIT_ITERATOR_DONT_IGNORE_CASE, start, end));
/* test loop */
- cl_git_pass(git_iterator_current(i, &entry));
+ cl_git_pass(git_iterator_current(&entry, i));
while (entry != NULL) {
if (expected_values != NULL)
cl_assert_equal_s(expected_values[count], entry->path);
count++;
- cl_git_pass(git_iterator_advance(i, &entry));
+ cl_git_pass(git_iterator_advance(&entry, i));
}
/* test reset */
cl_git_pass(git_iterator_reset(i, NULL, NULL));
- cl_git_pass(git_iterator_current(i, &entry));
+ cl_git_pass(git_iterator_current(&entry, i));
while (entry != NULL) {
if (expected_values != NULL)
cl_assert_equal_s(expected_values[count_post_reset], entry->path);
count_post_reset++;
- cl_git_pass(git_iterator_advance(i, &entry));
+ cl_git_pass(git_iterator_advance(&entry, i));
}
git_iterator_free(i);
@@ -261,30 +261,30 @@ static void check_tree_entry(
const git_tree *tree;
git_buf path = GIT_BUF_INIT;
- cl_git_pass(git_iterator_current_tree_entry(i, &te));
+ cl_git_pass(git_iterator_current_tree_entry(&te, i));
cl_assert(te);
cl_assert(git_oid_streq(&te->oid, oid) == 0);
- cl_git_pass(git_iterator_current(i, &ie));
+ cl_git_pass(git_iterator_current(&ie, i));
cl_git_pass(git_buf_sets(&path, ie->path));
if (oid_p) {
git_buf_rtruncate_at_char(&path, '/');
- cl_git_pass(git_iterator_current_parent_tree(i, path.ptr, &tree));
+ cl_git_pass(git_iterator_current_parent_tree(&tree, i, path.ptr));
cl_assert(tree);
cl_assert(git_oid_streq(git_tree_id(tree), oid_p) == 0);
}
if (oid_pp) {
git_buf_rtruncate_at_char(&path, '/');
- cl_git_pass(git_iterator_current_parent_tree(i, path.ptr, &tree));
+ cl_git_pass(git_iterator_current_parent_tree(&tree, i, path.ptr));
cl_assert(tree);
cl_assert(git_oid_streq(git_tree_id(tree), oid_pp) == 0);
}
if (oid_ppp) {
git_buf_rtruncate_at_char(&path, '/');
- cl_git_pass(git_iterator_current_parent_tree(i, path.ptr, &tree));
+ cl_git_pass(git_iterator_current_parent_tree(&tree, i, path.ptr));
cl_assert(tree);
cl_assert(git_oid_streq(git_tree_id(tree), oid_ppp) == 0);
}
@@ -305,9 +305,9 @@ void test_diff_iterator__tree_special_functions(void)
repo, "24fa9a9fc4e202313e24b648087495441dab432b");
cl_assert(t != NULL);
- cl_git_pass(git_iterator_for_tree_range(
+ cl_git_pass(git_iterator_for_tree(
&i, t, GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL));
- cl_git_pass(git_iterator_current(i, &entry));
+ cl_git_pass(git_iterator_current(&entry, i));
while (entry != NULL) {
if (strcmp(entry->path, "sub/file") == 0) {
@@ -339,7 +339,7 @@ void test_diff_iterator__tree_special_functions(void)
rootoid, NULL);
}
- cl_git_pass(git_iterator_advance(i, &entry));
+ cl_git_pass(git_iterator_advance(&entry, i));
}
cl_assert_equal_i(4, cases);
@@ -364,8 +364,8 @@ static void index_iterator_test(
git_repository *repo = cl_git_sandbox_init(sandbox);
cl_git_pass(git_repository_index(&index, repo));
- cl_git_pass(git_iterator_for_index_range(&i, index, 0, start, end));
- cl_git_pass(git_iterator_current(i, &entry));
+ cl_git_pass(git_iterator_for_index(&i, index, 0, start, end));
+ cl_git_pass(git_iterator_current(&entry, i));
while (entry != NULL) {
if (expected_names != NULL)
@@ -378,7 +378,7 @@ static void index_iterator_test(
}
count++;
- cl_git_pass(git_iterator_advance(i, &entry));
+ cl_git_pass(git_iterator_advance(&entry, i));
}
git_iterator_free(i);
@@ -538,14 +538,15 @@ static void workdir_iterator_test(
int count = 0, count_all = 0, count_all_post_reset = 0;
git_repository *repo = cl_git_sandbox_init(sandbox);
- cl_git_pass(git_iterator_for_workdir_range(&i, repo, 0, start, end));
- cl_git_pass(git_iterator_current(i, &entry));
+ cl_git_pass(git_iterator_for_workdir(
+ &i, repo, GIT_ITERATOR_DONT_AUTOEXPAND, start, end));
+ cl_git_pass(git_iterator_current(&entry, i));
while (entry != NULL) {
int ignored = git_iterator_current_is_ignored(i);
if (S_ISDIR(entry->mode)) {
- cl_git_pass(git_iterator_advance_into_directory(i, &entry));
+ cl_git_pass(git_iterator_advance_into(&entry, i));
continue;
}
@@ -559,22 +560,22 @@ static void workdir_iterator_test(
count++;
count_all++;
- cl_git_pass(git_iterator_advance(i, &entry));
+ cl_git_pass(git_iterator_advance(&entry, i));
}
cl_git_pass(git_iterator_reset(i, NULL, NULL));
- cl_git_pass(git_iterator_current(i, &entry));
+ cl_git_pass(git_iterator_current(&entry, i));
while (entry != NULL) {
if (S_ISDIR(entry->mode)) {
- cl_git_pass(git_iterator_advance_into_directory(i, &entry));
+ cl_git_pass(git_iterator_advance_into(&entry, i));
continue;
}
if (expected_names != NULL)
cl_assert_equal_s(
expected_names[count_all_post_reset], entry->path);
count_all_post_reset++;
- cl_git_pass(git_iterator_advance(i, &entry));
+ cl_git_pass(git_iterator_advance(&entry, i));
}
git_iterator_free(i);
@@ -735,9 +736,9 @@ void test_diff_iterator__workdir_builtin_ignores(void)
cl_git_pass(p_mkdir("attr/sub/sub/.git", 0777));
cl_git_mkfile("attr/sub/.git", "whatever");
- cl_git_pass(
- git_iterator_for_workdir_range(&i, repo, 0, "dir", "sub/sub/file"));
- cl_git_pass(git_iterator_current(i, &entry));
+ cl_git_pass(git_iterator_for_workdir(
+ &i, repo, GIT_ITERATOR_DONT_AUTOEXPAND, "dir", "sub/sub/file"));
+ cl_git_pass(git_iterator_current(&entry, i));
for (idx = 0; entry != NULL; ++idx) {
int ignored = git_iterator_current_is_ignored(i);
@@ -746,9 +747,9 @@ void test_diff_iterator__workdir_builtin_ignores(void)
cl_assert_(ignored == expected[idx].ignored, expected[idx].path);
if (!ignored && S_ISDIR(entry->mode))
- cl_git_pass(git_iterator_advance_into_directory(i, &entry));
+ cl_git_pass(git_iterator_advance_into(&entry, i));
else
- cl_git_pass(git_iterator_advance(i, &entry));
+ cl_git_pass(git_iterator_advance(&entry, i));
}
cl_assert(expected[idx].path == NULL);
@@ -764,17 +765,14 @@ static void check_wd_first_through_third_range(
int idx;
static const char *expected[] = { "FIRST", "second", "THIRD", NULL };
- cl_git_pass(git_iterator_for_workdir_range(
+ cl_git_pass(git_iterator_for_workdir(
&i, repo, GIT_ITERATOR_IGNORE_CASE, start, end));
- cl_git_pass(git_iterator_current(i, &entry));
+ cl_git_pass(git_iterator_current(&entry, i));
for (idx = 0; entry != NULL; ++idx) {
cl_assert_equal_s(expected[idx], entry->path);
- if (S_ISDIR(entry->mode))
- cl_git_pass(git_iterator_advance_into_directory(i, &entry));
- else
- cl_git_pass(git_iterator_advance(i, &entry));
+ cl_git_pass(git_iterator_advance(&entry, i));
}
cl_assert(expected[idx] == NULL);
@@ -817,16 +815,16 @@ static void check_tree_range(
cl_git_pass(git_repository_head_tree(&head, repo));
- cl_git_pass(git_iterator_for_tree_range(
+ cl_git_pass(git_iterator_for_tree(
&i, head,
ignore_case ? GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE,
start, end));
- cl_git_pass(git_iterator_current(i, &entry));
+ cl_git_pass(git_iterator_current(&entry, i));
for (count = 0; entry != NULL; ) {
++count;
- cl_git_pass(git_iterator_advance(i, &entry));
+ cl_git_pass(git_iterator_advance(&entry, i));
}
cl_assert_equal_i(expected_count, count);
@@ -882,15 +880,15 @@ static void check_index_range(
if (ignore_case != is_ignoring_case)
cl_git_pass(git_index_set_caps(index, caps ^ GIT_INDEXCAP_IGNORE_CASE));
- cl_git_pass(git_iterator_for_index_range(&i, index, 0, start, end));
+ cl_git_pass(git_iterator_for_index(&i, index, 0, start, end));
cl_assert(git_iterator_ignore_case(i) == ignore_case);
- cl_git_pass(git_iterator_current(i, &entry));
+ cl_git_pass(git_iterator_current(&entry, i));
for (count = 0; entry != NULL; ) {
++count;
- cl_git_pass(git_iterator_advance(i, &entry));
+ cl_git_pass(git_iterator_advance(&entry, i));
}
cl_assert_equal_i(expected_count, count);
diff --git a/tests-clar/repo/iterator.c b/tests-clar/repo/iterator.c
new file mode 100644
index 000000000..00123196b
--- /dev/null
+++ b/tests-clar/repo/iterator.c
@@ -0,0 +1,747 @@
+#include "clar_libgit2.h"
+#include "iterator.h"
+#include "repository.h"
+#include <stdarg.h>
+
+static git_repository *g_repo;
+
+void test_repo_iterator__initialize(void)
+{
+}
+
+void test_repo_iterator__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+ g_repo = NULL;
+}
+
+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;
+ 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; }
+
+ 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_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);
+ }
+
+ cl_git_pass(git_iterator_advance(&entry, i));
+
+ if (++count > expected_flat)
+ break;
+ }
+
+ cl_assert_equal_i(expected_flat, count);
+
+ cl_git_pass(git_iterator_reset(i, NULL, NULL));
+
+ 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)
+ cl_git_pass(git_iterator_advance_into(&entry, i));
+ else
+ cl_git_pass(git_iterator_advance(&entry, i));
+
+ if (++count > expected_total)
+ break;
+ }
+
+ 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_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, index, 0, NULL, NULL));
+ expect_iterator_items(i, 20, NULL, 20, NULL);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ expect_iterator_items(i, 22, NULL, 22, NULL);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_DONT_AUTOEXPAND, NULL, NULL));
+ expect_iterator_items(i, 12, NULL, 22, NULL);
+ git_iterator_free(i);
+
+ git_index_free(index);
+}
+
+void test_repo_iterator__index_icase(void)
+{
+ git_iterator *i;
+ git_index *index;
+ unsigned 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 */
+ cl_git_pass(git_iterator_for_index(&i, index, 0, "c", "k/D"));
+ expect_iterator_items(i, 7, NULL, 7, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_index(&i, index, 0, "k", "k/Z"));
+ expect_iterator_items(i, 3, NULL, 3, NULL);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_INCLUDE_TREES, "c", "k/D"));
+ expect_iterator_items(i, 8, NULL, 8, NULL);
+ git_iterator_free(i);
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_INCLUDE_TREES, "k", "k/Z"));
+ expect_iterator_items(i, 4, NULL, 4, NULL);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_DONT_AUTOEXPAND, "c", "k/D"));
+ expect_iterator_items(i, 5, NULL, 8, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_DONT_AUTOEXPAND, "k", "k/Z"));
+ 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 */
+ cl_git_pass(git_iterator_for_index(&i, index, 0, "c", "k/D"));
+ expect_iterator_items(i, 13, NULL, 13, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_index(&i, index, 0, "k", "k/Z"));
+ expect_iterator_items(i, 5, NULL, 5, NULL);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_INCLUDE_TREES, "c", "k/D"));
+ expect_iterator_items(i, 14, NULL, 14, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_INCLUDE_TREES, "k", "k/Z"));
+ expect_iterator_items(i, 6, NULL, 6, NULL);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_DONT_AUTOEXPAND, "c", "k/D"));
+ expect_iterator_items(i, 9, NULL, 14, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_index(
+ &i, index, GIT_ITERATOR_DONT_AUTOEXPAND, "k", "k/Z"));
+ 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_repo_iterator__tree(void)
+{
+ git_iterator *i;
+ 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, 0, NULL, NULL));
+ expect_iterator_items(i, 20, NULL, 20, NULL);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ expect_iterator_items(i, 22, NULL, 22, NULL);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, GIT_ITERATOR_DONT_AUTOEXPAND, NULL, NULL));
+ expect_iterator_items(i, 12, NULL, 22, NULL);
+ git_iterator_free(i);
+
+ git_tree_free(head);
+}
+
+void test_repo_iterator__tree_icase(void)
+{
+ git_iterator *i;
+ git_tree *head;
+ git_iterator_flag_t flag;
+
+ g_repo = cl_git_sandbox_init("icase");
+
+ cl_git_pass(git_repository_head_tree(&head, g_repo));
+
+ flag = GIT_ITERATOR_DONT_IGNORE_CASE;
+
+ /* auto expand with no tree entries */
+ cl_git_pass(git_iterator_for_tree(&i, head, flag, "c", "k/D"));
+ expect_iterator_items(i, 7, NULL, 7, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(&i, head, flag, "k", "k/Z"));
+ expect_iterator_items(i, 3, NULL, 3, NULL);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, flag | GIT_ITERATOR_INCLUDE_TREES, "c", "k/D"));
+ expect_iterator_items(i, 8, NULL, 8, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, flag | GIT_ITERATOR_INCLUDE_TREES, "k", "k/Z"));
+ expect_iterator_items(i, 4, NULL, 4, NULL);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, flag | GIT_ITERATOR_DONT_AUTOEXPAND, "c", "k/D"));
+ expect_iterator_items(i, 5, NULL, 8, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, flag | GIT_ITERATOR_DONT_AUTOEXPAND, "k", "k/Z"));
+ expect_iterator_items(i, 1, NULL, 4, NULL);
+ git_iterator_free(i);
+
+ flag = GIT_ITERATOR_IGNORE_CASE;
+
+ /* auto expand with no tree entries */
+ cl_git_pass(git_iterator_for_tree(&i, head, flag, "c", "k/D"));
+ expect_iterator_items(i, 13, NULL, 13, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(&i, head, flag, "k", "k/Z"));
+ expect_iterator_items(i, 5, NULL, 5, NULL);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, flag | GIT_ITERATOR_INCLUDE_TREES, "c", "k/D"));
+ expect_iterator_items(i, 14, NULL, 14, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, flag | GIT_ITERATOR_INCLUDE_TREES, "k", "k/Z"));
+ expect_iterator_items(i, 6, NULL, 6, NULL);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, flag | GIT_ITERATOR_DONT_AUTOEXPAND, "c", "k/D"));
+ expect_iterator_items(i, 9, NULL, 14, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, flag | GIT_ITERATOR_DONT_AUTOEXPAND, "k", "k/Z"));
+ expect_iterator_items(i, 1, NULL, 6, NULL);
+ git_iterator_free(i);
+}
+
+void test_repo_iterator__tree_more(void)
+{
+ git_iterator *i;
+ 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, 0, NULL, NULL));
+ expect_iterator_items(i, 12, expect_basic, 12, expect_basic);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ expect_iterator_items(i, 13, expect_trees, 13, expect_trees);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_tree(
+ &i, head, GIT_ITERATOR_DONT_AUTOEXPAND, NULL, NULL));
+ expect_iterator_items(i, 10, expect_noauto, 13, expect_trees);
+ git_iterator_free(i);
+
+ git_tree_free(head);
+}
+
+/* "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_buf name = GIT_BUF_INIT;
+ va_list arglist;
+
+ cl_git_pass(git_treebuilder_create(&builder, 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, repo, builder));
+
+ git_treebuilder_free(builder);
+ git_buf_free(&name);
+}
+
+void test_repo_iterator__tree_case_conflicts_0(void)
+{
+ const char *blob_sha = "d44e18fb93b7107b5cd1b95d601591d77869a1b6";
+ git_tree *tree;
+ git_oid blob_id, biga_id, littlea_id, tree_id;
+ git_iterator *i;
+ 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" };
+
+ g_repo = cl_git_sandbox_init("icase");
+
+ cl_git_pass(git_oid_fromstr(&blob_id, blob_sha)); /* lookup blob */
+
+ /* 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);
+
+ cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL));
+ expect_iterator_items(i, 4, expect_cs, 4, expect_cs);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_IGNORE_CASE, NULL, NULL));
+ expect_iterator_items(i, 4, expect_ci, 4, expect_ci);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_DONT_IGNORE_CASE |
+ GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ expect_iterator_items(i, 6, expect_cs_trees, 6, expect_cs_trees);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_IGNORE_CASE |
+ GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ expect_iterator_items(i, 5, expect_ci_trees, 5, expect_ci_trees);
+ git_iterator_free(i);
+
+ git_tree_free(tree);
+}
+
+void test_repo_iterator__tree_case_conflicts_1(void)
+{
+ const char *blob_sha = "d44e18fb93b7107b5cd1b95d601591d77869a1b6";
+ git_tree *tree;
+ git_oid blob_id, Ab_id, biga_id, littlea_id, tree_id;
+ git_iterator *i;
+ 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("icase");
+
+ 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));
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL));
+ expect_iterator_items(i, 6, expect_cs, 6, expect_cs);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_IGNORE_CASE, NULL, NULL));
+ expect_iterator_items(i, 4, expect_ci, 4, expect_ci);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_DONT_IGNORE_CASE |
+ GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ expect_iterator_items(i, 9, expect_cs_trees, 9, expect_cs_trees);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_IGNORE_CASE |
+ GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ 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)
+{
+ 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;
+ 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));
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL));
+ expect_iterator_items(i, 32, expect_cs, 32, expect_cs);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_IGNORE_CASE, NULL, NULL));
+ expect_iterator_items(i, 17, expect_ci, 17, expect_ci);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_tree(
+ &i, tree, GIT_ITERATOR_IGNORE_CASE |
+ GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ expect_iterator_items(i, 21, expect_ci_trees, 21, expect_ci_trees);
+ git_iterator_free(i);
+
+ git_tree_free(tree);
+}
+
+void test_repo_iterator__workdir(void)
+{
+ git_iterator *i;
+
+ g_repo = cl_git_sandbox_init("icase");
+
+ /* auto expand with no tree entries */
+ cl_git_pass(git_iterator_for_workdir(&i, g_repo, 0, NULL, NULL));
+ expect_iterator_items(i, 20, NULL, 20, NULL);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+ expect_iterator_items(i, 22, NULL, 22, NULL);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, GIT_ITERATOR_DONT_AUTOEXPAND, NULL, NULL));
+ expect_iterator_items(i, 12, NULL, 22, NULL);
+ git_iterator_free(i);
+}
+
+void test_repo_iterator__workdir_icase(void)
+{
+ git_iterator *i;
+ git_iterator_flag_t flag;
+
+ g_repo = cl_git_sandbox_init("icase");
+
+ flag = GIT_ITERATOR_DONT_IGNORE_CASE;
+
+ /* auto expand with no tree entries */
+ cl_git_pass(git_iterator_for_workdir(&i, g_repo, flag, "c", "k/D"));
+ expect_iterator_items(i, 7, NULL, 7, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_workdir(&i, g_repo, flag, "k", "k/Z"));
+ expect_iterator_items(i, 3, NULL, 3, NULL);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, flag | GIT_ITERATOR_INCLUDE_TREES, "c", "k/D"));
+ expect_iterator_items(i, 8, NULL, 8, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, flag | GIT_ITERATOR_INCLUDE_TREES, "k", "k/Z"));
+ expect_iterator_items(i, 4, NULL, 4, NULL);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, flag | GIT_ITERATOR_DONT_AUTOEXPAND, "c", "k/D"));
+ expect_iterator_items(i, 5, NULL, 8, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, flag | GIT_ITERATOR_DONT_AUTOEXPAND, "k", "k/Z"));
+ expect_iterator_items(i, 1, NULL, 4, NULL);
+ git_iterator_free(i);
+
+ flag = GIT_ITERATOR_IGNORE_CASE;
+
+ /* auto expand with no tree entries */
+ cl_git_pass(git_iterator_for_workdir(&i, g_repo, flag, "c", "k/D"));
+ expect_iterator_items(i, 13, NULL, 13, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_workdir(&i, g_repo, flag, "k", "k/Z"));
+ expect_iterator_items(i, 5, NULL, 5, NULL);
+ git_iterator_free(i);
+
+ /* auto expand with tree entries */
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, flag | GIT_ITERATOR_INCLUDE_TREES, "c", "k/D"));
+ expect_iterator_items(i, 14, NULL, 14, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, flag | GIT_ITERATOR_INCLUDE_TREES, "k", "k/Z"));
+ expect_iterator_items(i, 6, NULL, 6, NULL);
+ git_iterator_free(i);
+
+ /* no auto expand (implies trees included) */
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, flag | GIT_ITERATOR_DONT_AUTOEXPAND, "c", "k/D"));
+ expect_iterator_items(i, 9, NULL, 14, NULL);
+ git_iterator_free(i);
+
+ cl_git_pass(git_iterator_for_workdir(
+ &i, g_repo, flag | GIT_ITERATOR_DONT_AUTOEXPAND, "k", "k/Z"));
+ expect_iterator_items(i, 1, NULL, 6, NULL);
+ git_iterator_free(i);
+}
diff --git a/tests-clar/resources/icase/.gitted/HEAD b/tests-clar/resources/icase/.gitted/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/icase/.gitted/config b/tests-clar/resources/icase/.gitted/config
new file mode 100644
index 000000000..bb4d11c1f
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/config
@@ -0,0 +1,7 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+ precomposeunicode = false
diff --git a/tests-clar/resources/icase/.gitted/description b/tests-clar/resources/icase/.gitted/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/icase/.gitted/index b/tests-clar/resources/icase/.gitted/index
new file mode 100644
index 000000000..f8288ec13
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/index
Binary files differ
diff --git a/tests-clar/resources/icase/.gitted/info/exclude b/tests-clar/resources/icase/.gitted/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/info/exclude
@@ -0,0 +1,6 @@
+# git ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
diff --git a/tests-clar/resources/icase/.gitted/logs/HEAD b/tests-clar/resources/icase/.gitted/logs/HEAD
new file mode 100644
index 000000000..3b16bd163
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/logs/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 76d6e1d231b1085fcce151427e9899335de74be6 Russell Belfer <rb@github.com> 1359157123 -0800 commit (initial): initial commit
diff --git a/tests-clar/resources/icase/.gitted/logs/refs/heads/master b/tests-clar/resources/icase/.gitted/logs/refs/heads/master
new file mode 100644
index 000000000..3b16bd163
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/logs/refs/heads/master
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 76d6e1d231b1085fcce151427e9899335de74be6 Russell Belfer <rb@github.com> 1359157123 -0800 commit (initial): initial commit
diff --git a/tests-clar/resources/icase/.gitted/objects/3e/257c57f136a1cb8f2b8e9a2e5bc8ec0258bdce b/tests-clar/resources/icase/.gitted/objects/3e/257c57f136a1cb8f2b8e9a2e5bc8ec0258bdce
new file mode 100644
index 000000000..10691c788
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/objects/3e/257c57f136a1cb8f2b8e9a2e5bc8ec0258bdce
Binary files differ
diff --git a/tests-clar/resources/icase/.gitted/objects/4d/d6027d083575c7431396dc2a3174afeb393c93 b/tests-clar/resources/icase/.gitted/objects/4d/d6027d083575c7431396dc2a3174afeb393c93
new file mode 100644
index 000000000..8ca70df17
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/objects/4d/d6027d083575c7431396dc2a3174afeb393c93
Binary files differ
diff --git a/tests-clar/resources/icase/.gitted/objects/62/e0af52c199ec731fe4ad230041cd3286192d49 b/tests-clar/resources/icase/.gitted/objects/62/e0af52c199ec731fe4ad230041cd3286192d49
new file mode 100644
index 000000000..e264aeab3
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/objects/62/e0af52c199ec731fe4ad230041cd3286192d49
Binary files differ
diff --git a/tests-clar/resources/icase/.gitted/objects/76/d6e1d231b1085fcce151427e9899335de74be6 b/tests-clar/resources/icase/.gitted/objects/76/d6e1d231b1085fcce151427e9899335de74be6
new file mode 100644
index 000000000..24a4b3ee3
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/objects/76/d6e1d231b1085fcce151427e9899335de74be6
@@ -0,0 +1,3 @@
+x 1ENӀc XdƉ&/usԛ8}2 SH,
+am1ЋEѷ9CJ$ nܷA
+bଃjO_SO9%)9 \ No newline at end of file
diff --git a/tests-clar/resources/icase/.gitted/objects/d4/4e18fb93b7107b5cd1b95d601591d77869a1b6 b/tests-clar/resources/icase/.gitted/objects/d4/4e18fb93b7107b5cd1b95d601591d77869a1b6
new file mode 100644
index 000000000..32d8c499f
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/objects/d4/4e18fb93b7107b5cd1b95d601591d77869a1b6
Binary files differ
diff --git a/tests-clar/resources/icase/.gitted/refs/heads/master b/tests-clar/resources/icase/.gitted/refs/heads/master
new file mode 100644
index 000000000..37410ec2a
--- /dev/null
+++ b/tests-clar/resources/icase/.gitted/refs/heads/master
@@ -0,0 +1 @@
+76d6e1d231b1085fcce151427e9899335de74be6
diff --git a/tests-clar/resources/icase/B b/tests-clar/resources/icase/B
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/B
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/D b/tests-clar/resources/icase/D
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/D
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/F b/tests-clar/resources/icase/F
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/F
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/H b/tests-clar/resources/icase/H
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/H
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/J b/tests-clar/resources/icase/J
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/J
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/L/1 b/tests-clar/resources/icase/L/1
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/L/1
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/icase/L/B b/tests-clar/resources/icase/L/B
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/L/B
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/icase/L/D b/tests-clar/resources/icase/L/D
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/L/D
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/icase/L/a b/tests-clar/resources/icase/L/a
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/L/a
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/icase/L/c b/tests-clar/resources/icase/L/c
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/L/c
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/icase/a b/tests-clar/resources/icase/a
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/a
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/c b/tests-clar/resources/icase/c
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/c
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/e b/tests-clar/resources/icase/e
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/e
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/g b/tests-clar/resources/icase/g
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/g
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/i b/tests-clar/resources/icase/i
new file mode 100644
index 000000000..d44e18fb9
--- /dev/null
+++ b/tests-clar/resources/icase/i
@@ -0,0 +1 @@
+start
diff --git a/tests-clar/resources/icase/k/1 b/tests-clar/resources/icase/k/1
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/k/1
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/icase/k/B b/tests-clar/resources/icase/k/B
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/k/B
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/icase/k/D b/tests-clar/resources/icase/k/D
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/k/D
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/icase/k/a b/tests-clar/resources/icase/k/a
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/k/a
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/resources/icase/k/c b/tests-clar/resources/icase/k/c
new file mode 100644
index 000000000..62e0af52c
--- /dev/null
+++ b/tests-clar/resources/icase/k/c
@@ -0,0 +1 @@
+sub
diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c
index e1fc8dff8..b5449f6f1 100644
--- a/tests-clar/status/worktree.c
+++ b/tests-clar/status/worktree.c
@@ -274,6 +274,7 @@ void test_status_worktree__issue_592(void)
repo = cl_git_sandbox_init("issue_592");
cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "l.txt"));
cl_git_pass(p_unlink(git_buf_cstr(&path)));
+ cl_assert(!git_path_exists("issue_592/l.txt"));
cl_git_pass(git_status_foreach(repo, cb_status__check_592, "l.txt"));
@@ -288,6 +289,7 @@ void test_status_worktree__issue_592_2(void)
repo = cl_git_sandbox_init("issue_592");
cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "c/a.txt"));
cl_git_pass(p_unlink(git_buf_cstr(&path)));
+ cl_assert(!git_path_exists("issue_592/c/a.txt"));
cl_git_pass(git_status_foreach(repo, cb_status__check_592, "c/a.txt"));
@@ -303,6 +305,7 @@ void test_status_worktree__issue_592_3(void)
cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "c"));
cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_assert(!git_path_exists("issue_592/c/a.txt"));
cl_git_pass(git_status_foreach(repo, cb_status__check_592, "c/a.txt"));