Commit ed1c6446 by Edward Thomson Committed by Edward Thomson

iterator: use an options struct instead of args

parent 126932eb
...@@ -2471,11 +2471,12 @@ int git_checkout_iterator( ...@@ -2471,11 +2471,12 @@ int git_checkout_iterator(
{ {
int error = 0; int error = 0;
git_iterator *baseline = NULL, *workdir = NULL; git_iterator *baseline = NULL, *workdir = NULL;
git_iterator_options baseline_opts = GIT_ITERATOR_OPTIONS_INIT,
workdir_opts = GIT_ITERATOR_OPTIONS_INIT;
checkout_data data = {0}; checkout_data data = {0};
git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT; git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT;
uint32_t *actions = NULL; uint32_t *actions = NULL;
size_t *counts = NULL; size_t *counts = NULL;
git_iterator_flag_t iterflags = 0;
/* initialize structures and options */ /* initialize structures and options */
error = checkout_data_init(&data, target, opts); error = checkout_data_init(&data, target, opts);
...@@ -2499,25 +2500,30 @@ int git_checkout_iterator( ...@@ -2499,25 +2500,30 @@ int git_checkout_iterator(
/* set up iterators */ /* set up iterators */
iterflags = git_iterator_ignore_case(target) ? workdir_opts.flags = git_iterator_ignore_case(target) ?
GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE; GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE;
workdir_opts.flags |= GIT_ITERATOR_DONT_AUTOEXPAND;
workdir_opts.start = data.pfx;
workdir_opts.end = data.pfx;
if ((error = git_iterator_reset(target, data.pfx, data.pfx)) < 0 || if ((error = git_iterator_reset(target, data.pfx, data.pfx)) < 0 ||
(error = git_iterator_for_workdir_ext( (error = git_iterator_for_workdir_ext(
&workdir, data.repo, data.opts.target_directory, index, NULL, &workdir, data.repo, data.opts.target_directory, index, NULL,
iterflags | GIT_ITERATOR_DONT_AUTOEXPAND, &workdir_opts)) < 0)
data.pfx, data.pfx)) < 0)
goto cleanup; goto cleanup;
baseline_opts.flags = git_iterator_ignore_case(target) ?
GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE;
baseline_opts.start = data.pfx;
baseline_opts.end = data.pfx;
if (data.opts.baseline_index) { if (data.opts.baseline_index) {
if ((error = git_iterator_for_index( if ((error = git_iterator_for_index(
&baseline, data.opts.baseline_index, &baseline, data.opts.baseline_index, &baseline_opts)) < 0)
iterflags, data.pfx, data.pfx)) < 0)
goto cleanup; goto cleanup;
} else { } else {
if ((error = git_iterator_for_tree( if ((error = git_iterator_for_tree(
&baseline, data.opts.baseline, &baseline, data.opts.baseline, &baseline_opts)) < 0)
iterflags, data.pfx, data.pfx)) < 0)
goto cleanup; goto cleanup;
} }
...@@ -2625,7 +2631,7 @@ int git_checkout_index( ...@@ -2625,7 +2631,7 @@ int git_checkout_index(
return error; return error;
GIT_REFCOUNT_INC(index); GIT_REFCOUNT_INC(index);
if (!(error = git_iterator_for_index(&index_i, index, 0, NULL, NULL))) if (!(error = git_iterator_for_index(&index_i, index, NULL)))
error = git_checkout_iterator(index_i, index, opts); error = git_checkout_iterator(index_i, index, opts);
if (owned) if (owned)
...@@ -2681,7 +2687,7 @@ int git_checkout_tree( ...@@ -2681,7 +2687,7 @@ int git_checkout_tree(
if ((error = git_repository_index(&index, repo)) < 0) if ((error = git_repository_index(&index, repo)) < 0)
return error; return error;
if (!(error = git_iterator_for_tree(&tree_i, tree, 0, NULL, NULL))) if (!(error = git_iterator_for_tree(&tree_i, tree, NULL)))
error = git_checkout_iterator(tree_i, index, opts); error = git_checkout_iterator(tree_i, index, opts);
git_iterator_free(tree_i); git_iterator_free(tree_i);
......
...@@ -1264,9 +1264,17 @@ cleanup: ...@@ -1264,9 +1264,17 @@ cleanup:
return error; return error;
} }
#define DIFF_FROM_ITERATORS(MAKE_FIRST, MAKE_SECOND) do { \ #define DIFF_FROM_ITERATORS(MAKE_FIRST, FLAGS_FIRST, MAKE_SECOND, FLAGS_SECOND) do { \
git_iterator *a = NULL, *b = NULL; \ git_iterator *a = NULL, *b = NULL; \
char *pfx = opts ? git_pathspec_prefix(&opts->pathspec) : NULL; \ char *pfx = opts ? git_pathspec_prefix(&opts->pathspec) : NULL; \
git_iterator_options a_opts = GIT_ITERATOR_OPTIONS_INIT, \
b_opts = GIT_ITERATOR_OPTIONS_INIT; \
a_opts.flags = FLAGS_FIRST; \
a_opts.start = pfx; \
a_opts.end = pfx; \
b_opts.flags = FLAGS_SECOND; \
b_opts.start = pfx; \
b_opts.end = pfx; \
GITERR_CHECK_VERSION(opts, GIT_DIFF_OPTIONS_VERSION, "git_diff_options"); \ 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); \ error = git_diff__from_iterators(diff, repo, a, b, opts); \
...@@ -1280,8 +1288,8 @@ int git_diff_tree_to_tree( ...@@ -1280,8 +1288,8 @@ int git_diff_tree_to_tree(
git_tree *new_tree, git_tree *new_tree,
const git_diff_options *opts) const git_diff_options *opts)
{ {
int error = 0;
git_iterator_flag_t iflag = GIT_ITERATOR_DONT_IGNORE_CASE; git_iterator_flag_t iflag = GIT_ITERATOR_DONT_IGNORE_CASE;
int error = 0;
assert(diff && repo); assert(diff && repo);
...@@ -1293,8 +1301,8 @@ int git_diff_tree_to_tree( ...@@ -1293,8 +1301,8 @@ int git_diff_tree_to_tree(
iflag = GIT_ITERATOR_IGNORE_CASE; iflag = GIT_ITERATOR_IGNORE_CASE;
DIFF_FROM_ITERATORS( DIFF_FROM_ITERATORS(
git_iterator_for_tree(&a, old_tree, iflag, pfx, pfx), git_iterator_for_tree(&a, old_tree, &a_opts), iflag,
git_iterator_for_tree(&b, new_tree, iflag, pfx, pfx) git_iterator_for_tree(&b, new_tree, &b_opts), iflag
); );
return error; return error;
...@@ -1318,10 +1326,10 @@ int git_diff_tree_to_index( ...@@ -1318,10 +1326,10 @@ int git_diff_tree_to_index(
git_index *index, git_index *index,
const git_diff_options *opts) const git_diff_options *opts)
{ {
int error = 0;
bool index_ignore_case = false;
git_iterator_flag_t iflag = GIT_ITERATOR_DONT_IGNORE_CASE | git_iterator_flag_t iflag = GIT_ITERATOR_DONT_IGNORE_CASE |
GIT_ITERATOR_INCLUDE_CONFLICTS; GIT_ITERATOR_INCLUDE_CONFLICTS;
bool index_ignore_case = false;
int error = 0;
assert(diff && repo); assert(diff && repo);
...@@ -1331,8 +1339,8 @@ int git_diff_tree_to_index( ...@@ -1331,8 +1339,8 @@ int git_diff_tree_to_index(
index_ignore_case = index->ignore_case; index_ignore_case = index->ignore_case;
DIFF_FROM_ITERATORS( DIFF_FROM_ITERATORS(
git_iterator_for_tree(&a, old_tree, iflag, pfx, pfx), git_iterator_for_tree(&a, old_tree, &a_opts), iflag,
git_iterator_for_index(&b, index, iflag, pfx, pfx) git_iterator_for_index(&b, index, &b_opts), iflag
); );
/* if index is in case-insensitive order, re-sort deltas to match */ /* if index is in case-insensitive order, re-sort deltas to match */
...@@ -1356,10 +1364,11 @@ int git_diff_index_to_workdir( ...@@ -1356,10 +1364,11 @@ int git_diff_index_to_workdir(
return error; return error;
DIFF_FROM_ITERATORS( DIFF_FROM_ITERATORS(
git_iterator_for_index( git_iterator_for_index(&a, index, &a_opts),
&a, index, GIT_ITERATOR_INCLUDE_CONFLICTS, pfx, pfx), GIT_ITERATOR_INCLUDE_CONFLICTS,
git_iterator_for_workdir(
&b, repo, index, NULL, GIT_ITERATOR_DONT_AUTOEXPAND, pfx, pfx) git_iterator_for_workdir(&b, repo, index, NULL, &b_opts),
GIT_ITERATOR_DONT_AUTOEXPAND
); );
if (!error && DIFF_FLAG_IS_SET(*diff, GIT_DIFF_UPDATE_INDEX) && (*diff)->index_updated) if (!error && DIFF_FLAG_IS_SET(*diff, GIT_DIFF_UPDATE_INDEX) && (*diff)->index_updated)
...@@ -1383,9 +1392,8 @@ int git_diff_tree_to_workdir( ...@@ -1383,9 +1392,8 @@ int git_diff_tree_to_workdir(
return error; return error;
DIFF_FROM_ITERATORS( DIFF_FROM_ITERATORS(
git_iterator_for_tree(&a, old_tree, 0, pfx, pfx), git_iterator_for_tree(&a, old_tree, &a_opts), 0,
git_iterator_for_workdir( git_iterator_for_workdir(&b, repo, index, old_tree, &b_opts), GIT_ITERATOR_DONT_AUTOEXPAND
&b, repo, index, old_tree, GIT_ITERATOR_DONT_AUTOEXPAND, pfx, pfx)
); );
return error; return error;
...@@ -1433,10 +1441,8 @@ int git_diff_index_to_index( ...@@ -1433,10 +1441,8 @@ int git_diff_index_to_index(
assert(diff && old_index && new_index); assert(diff && old_index && new_index);
DIFF_FROM_ITERATORS( DIFF_FROM_ITERATORS(
git_iterator_for_index( git_iterator_for_index(&a, old_index, &a_opts), GIT_ITERATOR_DONT_IGNORE_CASE,
&a, old_index, GIT_ITERATOR_DONT_IGNORE_CASE, pfx, pfx), git_iterator_for_index(&b, new_index, &b_opts), GIT_ITERATOR_DONT_IGNORE_CASE
git_iterator_for_index(
&b, new_index, GIT_ITERATOR_DONT_IGNORE_CASE, pfx, pfx)
); );
/* if index is in case-insensitive order, re-sort deltas to match */ /* if index is in case-insensitive order, re-sort deltas to match */
......
...@@ -2658,6 +2658,7 @@ int git_index_read_index( ...@@ -2658,6 +2658,7 @@ int git_index_read_index(
remove_entries = GIT_VECTOR_INIT; remove_entries = GIT_VECTOR_INIT;
git_iterator *index_iterator = NULL; git_iterator *index_iterator = NULL;
git_iterator *new_iterator = NULL; git_iterator *new_iterator = NULL;
git_iterator_options opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *old_entry, *new_entry; const git_index_entry *old_entry, *new_entry;
git_index_entry *entry; git_index_entry *entry;
size_t i; size_t i;
...@@ -2667,10 +2668,10 @@ int git_index_read_index( ...@@ -2667,10 +2668,10 @@ int git_index_read_index(
(error = git_vector_init(&remove_entries, index->entries.length, NULL)) < 0) (error = git_vector_init(&remove_entries, index->entries.length, NULL)) < 0)
goto done; goto done;
if ((error = git_iterator_for_index(&index_iterator, opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
index, GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL)) < 0 ||
(error = git_iterator_for_index(&new_iterator, if ((error = git_iterator_for_index(&index_iterator, index, &opts)) < 0 ||
(git_index *)new_index, GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL)) < 0) (error = git_iterator_for_index(&new_iterator, (git_index *)new_index, &opts)) < 0)
goto done; goto done;
if (((error = git_iterator_current(&old_entry, index_iterator)) < 0 && if (((error = git_iterator_current(&old_entry, index_iterator)) < 0 &&
......
...@@ -31,12 +31,15 @@ ...@@ -31,12 +31,15 @@
(P)->base.cb = &(P)->cb; \ (P)->base.cb = &(P)->cb; \
ITERATOR_SET_CB(P,NAME_LC); \ ITERATOR_SET_CB(P,NAME_LC); \
(P)->base.repo = (REPO); \ (P)->base.repo = (REPO); \
(P)->base.start = start ? git__strdup(start) : NULL; \ (P)->base.start = options && options->start ? \
(P)->base.end = end ? git__strdup(end) : NULL; \ git__strdup(options->start) : NULL; \
if ((start && !(P)->base.start) || (end && !(P)->base.end)) { \ (P)->base.end = options && options->end ? \
git__strdup(options->end) : NULL; \
if ((options && options->start && !(P)->base.start) || \
(options && options->end && !(P)->base.end)) { \
git__free(P); return -1; } \ git__free(P); return -1; } \
(P)->base.prefixcomp = git__prefixcmp; \ (P)->base.prefixcomp = git__prefixcmp; \
(P)->base.flags = flags & ~ITERATOR_CASE_FLAGS; \ (P)->base.flags = options ? options->flags & ~ITERATOR_CASE_FLAGS : 0; \
if ((P)->base.flags & GIT_ITERATOR_DONT_AUTOEXPAND) \ if ((P)->base.flags & GIT_ITERATOR_DONT_AUTOEXPAND) \
(P)->base.flags |= GIT_ITERATOR_INCLUDE_TREES; \ (P)->base.flags |= GIT_ITERATOR_INCLUDE_TREES; \
} while (0) } while (0)
...@@ -149,9 +152,7 @@ typedef struct { ...@@ -149,9 +152,7 @@ typedef struct {
int git_iterator_for_nothing( int git_iterator_for_nothing(
git_iterator **iter, git_iterator **iter,
git_iterator_flag_t flags, git_iterator_options *options)
const char *start,
const char *end)
{ {
empty_iterator *i = git__calloc(1, sizeof(empty_iterator)); empty_iterator *i = git__calloc(1, sizeof(empty_iterator));
GITERR_CHECK_ALLOC(i); GITERR_CHECK_ALLOC(i);
...@@ -162,7 +163,7 @@ int git_iterator_for_nothing( ...@@ -162,7 +163,7 @@ int git_iterator_for_nothing(
ITERATOR_BASE_INIT(i, empty, EMPTY, NULL); ITERATOR_BASE_INIT(i, empty, EMPTY, NULL);
if ((flags & GIT_ITERATOR_IGNORE_CASE) != 0) if (options && (options->flags & GIT_ITERATOR_IGNORE_CASE) != 0)
i->base.flags |= GIT_ITERATOR_IGNORE_CASE; i->base.flags |= GIT_ITERATOR_IGNORE_CASE;
*iter = (git_iterator *)i; *iter = (git_iterator *)i;
...@@ -607,15 +608,13 @@ static int tree_iterator__create_root_frame(tree_iterator *ti, git_tree *tree) ...@@ -607,15 +608,13 @@ static int tree_iterator__create_root_frame(tree_iterator *ti, git_tree *tree)
int git_iterator_for_tree( int git_iterator_for_tree(
git_iterator **iter, git_iterator **iter,
git_tree *tree, git_tree *tree,
git_iterator_flag_t flags, git_iterator_options *options)
const char *start,
const char *end)
{ {
int error; int error;
tree_iterator *ti; tree_iterator *ti;
if (tree == NULL) if (tree == NULL)
return git_iterator_for_nothing(iter, flags, start, end); return git_iterator_for_nothing(iter, options);
if ((error = git_object_dup((git_object **)&tree, (git_object *)tree)) < 0) if ((error = git_object_dup((git_object **)&tree, (git_object *)tree)) < 0)
return error; return error;
...@@ -625,7 +624,7 @@ int git_iterator_for_tree( ...@@ -625,7 +624,7 @@ int git_iterator_for_tree(
ITERATOR_BASE_INIT(ti, tree, TREE, 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, options ? options->flags : 0)) < 0)
goto fail; goto fail;
ti->strncomp = iterator__ignore_case(ti) ? git__strncasecmp : git__strncmp; ti->strncomp = iterator__ignore_case(ti) ? git__strncasecmp : git__strncmp;
...@@ -860,9 +859,7 @@ static void index_iterator__free(git_iterator *self) ...@@ -860,9 +859,7 @@ static void index_iterator__free(git_iterator *self)
int git_iterator_for_index( int git_iterator_for_index(
git_iterator **iter, git_iterator **iter,
git_index *index, git_index *index,
git_iterator_flag_t flags, git_iterator_options *options)
const char *start,
const char *end)
{ {
int error = 0; int error = 0;
index_iterator *ii = git__calloc(1, sizeof(index_iterator)); index_iterator *ii = git__calloc(1, sizeof(index_iterator));
...@@ -876,7 +873,7 @@ int git_iterator_for_index( ...@@ -876,7 +873,7 @@ int git_iterator_for_index(
ITERATOR_BASE_INIT(ii, index, INDEX, git_index_owner(index)); ITERATOR_BASE_INIT(ii, index, INDEX, git_index_owner(index));
if ((error = iterator__update_ignore_case((git_iterator *)ii, flags)) < 0) { if ((error = iterator__update_ignore_case((git_iterator *)ii, options ? options->flags : 0)) < 0) {
git_iterator_free((git_iterator *)ii); git_iterator_free((git_iterator *)ii);
return error; return error;
} }
...@@ -1062,6 +1059,8 @@ static int dirload_with_stat( ...@@ -1062,6 +1059,8 @@ static int dirload_with_stat(
memcpy(ps->path, path, path_len); memcpy(ps->path, path, path_len);
/* TODO: don't stat if assume unchanged for this path */
if ((error = git_path_diriter_stat(&ps->st, &diriter)) < 0) { if ((error = git_path_diriter_stat(&ps->st, &diriter)) < 0) {
if (error == GIT_ENOTFOUND) { if (error == GIT_ENOTFOUND) {
/* file was removed between readdir and lstat */ /* file was removed between readdir and lstat */
...@@ -1366,16 +1365,14 @@ static int fs_iterator__initialize( ...@@ -1366,16 +1365,14 @@ static int fs_iterator__initialize(
int git_iterator_for_filesystem( int git_iterator_for_filesystem(
git_iterator **out, git_iterator **out,
const char *root, const char *root,
git_iterator_flag_t flags, git_iterator_options *options)
const char *start,
const char *end)
{ {
fs_iterator *fi = git__calloc(1, sizeof(fs_iterator)); fs_iterator *fi = git__calloc(1, sizeof(fs_iterator));
GITERR_CHECK_ALLOC(fi); GITERR_CHECK_ALLOC(fi);
ITERATOR_BASE_INIT(fi, fs, FS, NULL); ITERATOR_BASE_INIT(fi, fs, FS, NULL);
if ((flags & GIT_ITERATOR_IGNORE_CASE) != 0) if (options && (options->flags & GIT_ITERATOR_IGNORE_CASE) != 0)
fi->base.flags |= GIT_ITERATOR_IGNORE_CASE; fi->base.flags |= GIT_ITERATOR_IGNORE_CASE;
return fs_iterator__initialize(out, fi, root); return fs_iterator__initialize(out, fi, root);
...@@ -1559,9 +1556,7 @@ int git_iterator_for_workdir_ext( ...@@ -1559,9 +1556,7 @@ int git_iterator_for_workdir_ext(
const char *repo_workdir, const char *repo_workdir,
git_index *index, git_index *index,
git_tree *tree, git_tree *tree,
git_iterator_flag_t flags, git_iterator_options *options)
const char *start,
const char *end)
{ {
int error, precompose = 0; int error, precompose = 0;
workdir_iterator *wi; workdir_iterator *wi;
...@@ -1583,7 +1578,7 @@ int git_iterator_for_workdir_ext( ...@@ -1583,7 +1578,7 @@ int git_iterator_for_workdir_ext(
wi->fi.leave_dir_cb = workdir_iterator__leave_dir; wi->fi.leave_dir_cb = workdir_iterator__leave_dir;
wi->fi.update_entry_cb = workdir_iterator__update_entry; wi->fi.update_entry_cb = workdir_iterator__update_entry;
if ((error = iterator__update_ignore_case((git_iterator *)wi, flags)) < 0 || if ((error = iterator__update_ignore_case((git_iterator *)wi, options ? options->flags : 0)) < 0 ||
(error = git_ignore__for_path(repo, ".gitignore", &wi->ignores)) < 0) (error = git_ignore__for_path(repo, ".gitignore", &wi->ignores)) < 0)
{ {
git_iterator_free((git_iterator *)wi); git_iterator_free((git_iterator *)wi);
......
...@@ -38,6 +38,17 @@ typedef enum { ...@@ -38,6 +38,17 @@ typedef enum {
GIT_ITERATOR_INCLUDE_CONFLICTS = (1u << 5), GIT_ITERATOR_INCLUDE_CONFLICTS = (1u << 5),
} git_iterator_flag_t; } git_iterator_flag_t;
typedef struct {
const char *start;
const char *end;
/* flags, from above */
unsigned int flags;
} git_iterator_options;
#define GIT_ITERATOR_OPTIONS_INIT {0}
typedef struct { typedef struct {
int (*current)(const git_index_entry **, git_iterator *); int (*current)(const git_index_entry **, git_iterator *);
int (*advance)(const git_index_entry **, git_iterator *); int (*advance)(const git_index_entry **, git_iterator *);
...@@ -61,9 +72,7 @@ struct git_iterator { ...@@ -61,9 +72,7 @@ struct git_iterator {
extern int git_iterator_for_nothing( extern int git_iterator_for_nothing(
git_iterator **out, git_iterator **out,
git_iterator_flag_t flags, git_iterator_options *options);
const char *start,
const char *end);
/* tree iterators will match the ignore_case value from the index of the /* tree iterators will match the ignore_case value from the index of the
* repository, unless you override with a non-zero flag value * repository, unless you override with a non-zero flag value
...@@ -71,9 +80,7 @@ extern int git_iterator_for_nothing( ...@@ -71,9 +80,7 @@ extern int git_iterator_for_nothing(
extern int git_iterator_for_tree( extern int git_iterator_for_tree(
git_iterator **out, git_iterator **out,
git_tree *tree, git_tree *tree,
git_iterator_flag_t flags, git_iterator_options *options);
const char *start,
const char *end);
/* index iterators will take the ignore_case value from the index; the /* index iterators will take the ignore_case value from the index; the
* ignore_case flags are not used * ignore_case flags are not used
...@@ -81,9 +88,7 @@ extern int git_iterator_for_tree( ...@@ -81,9 +88,7 @@ extern int git_iterator_for_tree(
extern int git_iterator_for_index( extern int git_iterator_for_index(
git_iterator **out, git_iterator **out,
git_index *index, git_index *index,
git_iterator_flag_t flags, git_iterator_options *options);
const char *start,
const char *end);
extern int git_iterator_for_workdir_ext( extern int git_iterator_for_workdir_ext(
git_iterator **out, git_iterator **out,
...@@ -91,9 +96,7 @@ extern int git_iterator_for_workdir_ext( ...@@ -91,9 +96,7 @@ extern int git_iterator_for_workdir_ext(
const char *repo_workdir, const char *repo_workdir,
git_index *index, git_index *index,
git_tree *tree, git_tree *tree,
git_iterator_flag_t flags, git_iterator_options *options);
const char *start,
const char *end);
/* workdir iterators will match the ignore_case value from the index of the /* workdir iterators will match the ignore_case value from the index of the
* repository, unless you override with a non-zero flag value * repository, unless you override with a non-zero flag value
...@@ -103,11 +106,9 @@ GIT_INLINE(int) git_iterator_for_workdir( ...@@ -103,11 +106,9 @@ GIT_INLINE(int) git_iterator_for_workdir(
git_repository *repo, git_repository *repo,
git_index *index, git_index *index,
git_tree *tree, git_tree *tree,
git_iterator_flag_t flags, git_iterator_options *options)
const char *start,
const char *end)
{ {
return git_iterator_for_workdir_ext(out, repo, NULL, index, tree, flags, start, end); return git_iterator_for_workdir_ext(out, repo, NULL, index, tree, options);
} }
/* for filesystem iterators, you have to explicitly pass in the ignore_case /* for filesystem iterators, you have to explicitly pass in the ignore_case
...@@ -116,9 +117,7 @@ GIT_INLINE(int) git_iterator_for_workdir( ...@@ -116,9 +117,7 @@ GIT_INLINE(int) git_iterator_for_workdir(
extern int git_iterator_for_filesystem( extern int git_iterator_for_filesystem(
git_iterator **out, git_iterator **out,
const char *root, const char *root,
git_iterator_flag_t flags, git_iterator_options *options);
const char *start,
const char *end);
extern void git_iterator_free(git_iterator *iter); extern void git_iterator_free(git_iterator *iter);
......
...@@ -1695,10 +1695,14 @@ on_error: ...@@ -1695,10 +1695,14 @@ on_error:
static git_iterator *iterator_given_or_empty(git_iterator **empty, git_iterator *given) static git_iterator *iterator_given_or_empty(git_iterator **empty, git_iterator *given)
{ {
git_iterator_options opts = GIT_ITERATOR_OPTIONS_INIT;
if (given) if (given)
return given; return given;
if (git_iterator_for_nothing(empty, GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL) < 0) opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
if (git_iterator_for_nothing(empty, &opts) < 0)
return NULL; return NULL;
return *empty; return *empty;
...@@ -1780,14 +1784,17 @@ int git_merge_trees( ...@@ -1780,14 +1784,17 @@ int git_merge_trees(
const git_merge_options *merge_opts) const git_merge_options *merge_opts)
{ {
git_iterator *ancestor_iter = NULL, *our_iter = NULL, *their_iter = NULL; git_iterator *ancestor_iter = NULL, *our_iter = NULL, *their_iter = NULL;
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
int error; int error;
if ((error = git_iterator_for_tree(&ancestor_iter, (git_tree *)ancestor_tree, iter_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL)) < 0 ||
(error = git_iterator_for_tree(&our_iter, (git_tree *)our_tree, if ((error = git_iterator_for_tree(
GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL)) < 0 || &ancestor_iter, (git_tree *)ancestor_tree, &iter_opts)) < 0 ||
(error = git_iterator_for_tree(&their_iter, (git_tree *)their_tree, (error = git_iterator_for_tree(
GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL)) < 0) &our_iter, (git_tree *)our_tree, &iter_opts)) < 0 ||
(error = git_iterator_for_tree(
&their_iter, (git_tree *)their_tree, &iter_opts)) < 0)
goto done; goto done;
error = git_merge__iterators( error = git_merge__iterators(
...@@ -2319,6 +2326,7 @@ static int merge_check_index(size_t *conflicts, git_repository *repo, git_index ...@@ -2319,6 +2326,7 @@ static int merge_check_index(size_t *conflicts, git_repository *repo, git_index
git_tree *head_tree = NULL; git_tree *head_tree = NULL;
git_index *index_repo = NULL; git_index *index_repo = NULL;
git_iterator *iter_repo = NULL, *iter_new = NULL; git_iterator *iter_repo = NULL, *iter_new = NULL;
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
git_diff *staged_diff_list = NULL, *index_diff_list = NULL; git_diff *staged_diff_list = NULL, *index_diff_list = NULL;
git_diff_delta *delta; git_diff_delta *delta;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
...@@ -2351,8 +2359,10 @@ static int merge_check_index(size_t *conflicts, git_repository *repo, git_index ...@@ -2351,8 +2359,10 @@ static int merge_check_index(size_t *conflicts, git_repository *repo, git_index
opts.pathspec.count = staged_paths.length; opts.pathspec.count = staged_paths.length;
opts.pathspec.strings = (char **)staged_paths.contents; opts.pathspec.strings = (char **)staged_paths.contents;
if ((error = git_iterator_for_index(&iter_repo, index_repo, GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL)) < 0 || iter_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
(error = git_iterator_for_index(&iter_new, index_new, GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL)) < 0 ||
if ((error = git_iterator_for_index(&iter_repo, index_repo, &iter_opts)) < 0 ||
(error = git_iterator_for_index(&iter_new, index_new, &iter_opts)) < 0 ||
(error = git_diff__from_iterators(&index_diff_list, repo, iter_repo, iter_new, &opts)) < 0) (error = git_diff__from_iterators(&index_diff_list, repo, iter_repo, iter_new, &opts)) < 0)
goto done; goto done;
...@@ -2414,6 +2424,7 @@ int git_merge__check_result(git_repository *repo, git_index *index_new) ...@@ -2414,6 +2424,7 @@ int git_merge__check_result(git_repository *repo, git_index *index_new)
{ {
git_tree *head_tree = NULL; git_tree *head_tree = NULL;
git_iterator *iter_head = NULL, *iter_new = NULL; git_iterator *iter_head = NULL, *iter_new = NULL;
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
git_diff *merged_list = NULL; git_diff *merged_list = NULL;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_delta *delta; git_diff_delta *delta;
...@@ -2422,9 +2433,11 @@ int git_merge__check_result(git_repository *repo, git_index *index_new) ...@@ -2422,9 +2433,11 @@ int git_merge__check_result(git_repository *repo, git_index *index_new)
const git_index_entry *e; const git_index_entry *e;
int error = 0; int error = 0;
iter_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
if ((error = git_repository_head_tree(&head_tree, repo)) < 0 || if ((error = git_repository_head_tree(&head_tree, repo)) < 0 ||
(error = git_iterator_for_tree(&iter_head, head_tree, GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL)) < 0 || (error = git_iterator_for_tree(&iter_head, head_tree, &iter_opts)) < 0 ||
(error = git_iterator_for_index(&iter_new, index_new, GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL)) < 0 || (error = git_iterator_for_index(&iter_new, index_new, &iter_opts)) < 0 ||
(error = git_diff__from_iterators(&merged_list, repo, iter_head, iter_new, &opts)) < 0) (error = git_diff__from_iterators(&merged_list, repo, iter_head, iter_new, &opts)) < 0)
goto done; goto done;
......
...@@ -663,7 +663,7 @@ int git_note_iterator_new( ...@@ -663,7 +663,7 @@ int git_note_iterator_new(
if (error < 0) if (error < 0)
goto cleanup; goto cleanup;
if ((error = git_iterator_for_tree(it, tree, 0, NULL, NULL)) < 0) if ((error = git_iterator_for_tree(it, tree, NULL)) < 0)
git_iterator_free(*it); git_iterator_free(*it);
cleanup: cleanup:
......
...@@ -524,16 +524,16 @@ int git_pathspec_match_workdir( ...@@ -524,16 +524,16 @@ int git_pathspec_match_workdir(
uint32_t flags, uint32_t flags,
git_pathspec *ps) git_pathspec *ps)
{ {
int error = 0;
git_iterator *iter; git_iterator *iter;
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
int error = 0;
assert(repo); assert(repo);
if (!(error = git_iterator_for_workdir( iter_opts.flags = pathspec_match_iter_flags(flags);
&iter, repo, NULL, NULL, pathspec_match_iter_flags(flags), NULL, NULL))) {
if (!(error = git_iterator_for_workdir(&iter, repo, NULL, NULL, &iter_opts))) {
error = pathspec_match_from_iterator(out, iter, flags, ps); error = pathspec_match_from_iterator(out, iter, flags, ps);
git_iterator_free(iter); git_iterator_free(iter);
} }
...@@ -546,16 +546,16 @@ int git_pathspec_match_index( ...@@ -546,16 +546,16 @@ int git_pathspec_match_index(
uint32_t flags, uint32_t flags,
git_pathspec *ps) git_pathspec *ps)
{ {
int error = 0;
git_iterator *iter; git_iterator *iter;
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
int error = 0;
assert(index); assert(index);
if (!(error = git_iterator_for_index( iter_opts.flags = pathspec_match_iter_flags(flags);
&iter, index, pathspec_match_iter_flags(flags), NULL, NULL))) {
if (!(error = git_iterator_for_index(&iter, index, &iter_opts))) {
error = pathspec_match_from_iterator(out, iter, flags, ps); error = pathspec_match_from_iterator(out, iter, flags, ps);
git_iterator_free(iter); git_iterator_free(iter);
} }
...@@ -568,16 +568,16 @@ int git_pathspec_match_tree( ...@@ -568,16 +568,16 @@ int git_pathspec_match_tree(
uint32_t flags, uint32_t flags,
git_pathspec *ps) git_pathspec *ps)
{ {
int error = 0;
git_iterator *iter; git_iterator *iter;
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
int error = 0;
assert(tree); assert(tree);
if (!(error = git_iterator_for_tree( iter_opts.flags = pathspec_match_iter_flags(flags);
&iter, tree, pathspec_match_iter_flags(flags), NULL, NULL))) {
if (!(error = git_iterator_for_tree(&iter, tree, &iter_opts))) {
error = pathspec_match_from_iterator(out, iter, flags, ps); error = pathspec_match_from_iterator(out, iter, flags, ps);
git_iterator_free(iter); git_iterator_free(iter);
} }
......
...@@ -480,14 +480,16 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter) ...@@ -480,14 +480,16 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
int error = 0; int error = 0;
git_buf path = GIT_BUF_INIT; git_buf path = GIT_BUF_INIT;
git_iterator *fsit = NULL; git_iterator *fsit = NULL;
git_iterator_options fsit_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry = NULL; const git_index_entry *entry = NULL;
if (!backend->path) /* do nothing if no path for loose refs */ if (!backend->path) /* do nothing if no path for loose refs */
return 0; return 0;
fsit_opts.flags = backend->iterator_flags;
if ((error = git_buf_printf(&path, "%s/refs", backend->path)) < 0 || if ((error = git_buf_printf(&path, "%s/refs", backend->path)) < 0 ||
(error = git_iterator_for_filesystem( (error = git_iterator_for_filesystem(&fsit, path.ptr, &fsit_opts)) < 0) {
&fsit, path.ptr, backend->iterator_flags, NULL, NULL)) < 0) {
git_buf_free(&path); git_buf_free(&path);
return error; return error;
} }
......
...@@ -679,12 +679,14 @@ static int merge_indexes( ...@@ -679,12 +679,14 @@ static int merge_indexes(
git_index *theirs_index) git_index *theirs_index)
{ {
git_iterator *ancestor = NULL, *ours = NULL, *theirs = NULL; git_iterator *ancestor = NULL, *ours = NULL, *theirs = NULL;
const git_iterator_flag_t flags = GIT_ITERATOR_DONT_IGNORE_CASE; git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
int error; int error;
if ((error = git_iterator_for_tree(&ancestor, ancestor_tree, flags, NULL, NULL)) < 0 || iter_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
(error = git_iterator_for_index(&ours, ours_index, flags, NULL, NULL)) < 0 ||
(error = git_iterator_for_index(&theirs, theirs_index, flags, NULL, NULL)) < 0) if ((error = git_iterator_for_tree(&ancestor, ancestor_tree, &iter_opts)) < 0 ||
(error = git_iterator_for_index(&ours, ours_index, &iter_opts)) < 0 ||
(error = git_iterator_for_index(&theirs, theirs_index, &iter_opts)) < 0)
goto done; goto done;
error = git_merge__iterators(out, repo, ancestor, ours, theirs, NULL); error = git_merge__iterators(out, repo, ancestor, ours, theirs, NULL);
...@@ -704,12 +706,14 @@ static int merge_index_and_tree( ...@@ -704,12 +706,14 @@ static int merge_index_and_tree(
git_tree *theirs_tree) git_tree *theirs_tree)
{ {
git_iterator *ancestor = NULL, *ours = NULL, *theirs = NULL; git_iterator *ancestor = NULL, *ours = NULL, *theirs = NULL;
const git_iterator_flag_t flags = GIT_ITERATOR_DONT_IGNORE_CASE; git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
int error; int error;
if ((error = git_iterator_for_tree(&ancestor, ancestor_tree, flags, NULL, NULL)) < 0 || iter_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
(error = git_iterator_for_index(&ours, ours_index, flags, NULL, NULL)) < 0 ||
(error = git_iterator_for_tree(&theirs, theirs_tree, flags, NULL, NULL)) < 0) if ((error = git_iterator_for_tree(&ancestor, ancestor_tree, &iter_opts)) < 0 ||
(error = git_iterator_for_index(&ours, ours_index, &iter_opts)) < 0 ||
(error = git_iterator_for_tree(&theirs, theirs_tree, &iter_opts)) < 0)
goto done; goto done;
error = git_merge__iterators(out, repo, ancestor, ours, theirs, NULL); error = git_merge__iterators(out, repo, ancestor, ours, theirs, NULL);
...@@ -797,14 +801,15 @@ static int stage_new_files( ...@@ -797,14 +801,15 @@ static int stage_new_files(
git_tree *tree) git_tree *tree)
{ {
git_iterator *iterators[2] = { NULL, NULL }; git_iterator *iterators[2] = { NULL, NULL };
git_iterator_options iterator_options = GIT_ITERATOR_OPTIONS_INIT;
git_index *index = NULL; git_index *index = NULL;
int error; int error;
if ((error = git_index_new(&index)) < 0 || if ((error = git_index_new(&index)) < 0 ||
(error = git_iterator_for_tree(&iterators[0], parent_tree, (error = git_iterator_for_tree(
GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL)) < 0 || &iterators[0], parent_tree, &iterator_options)) < 0 ||
(error = git_iterator_for_tree(&iterators[1], tree, (error = git_iterator_for_tree(
GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL)) < 0) &iterators[1], tree, &iterator_options)) < 0)
goto done; goto done;
error = git_iterator_walk(iterators, 2, stage_new_file, index); error = git_iterator_walk(iterators, 2, stage_new_file, index);
......
...@@ -286,7 +286,7 @@ static int submodules_from_index(git_strmap *map, git_index *idx) ...@@ -286,7 +286,7 @@ static int submodules_from_index(git_strmap *map, git_index *idx)
git_iterator *i; git_iterator *i;
const git_index_entry *entry; const git_index_entry *entry;
if ((error = git_iterator_for_index(&i, idx, 0, NULL, NULL)) < 0) if ((error = git_iterator_for_index(&i, idx, NULL)) < 0)
return error; return error;
while (!(error = git_iterator_advance(&entry, i))) { while (!(error = git_iterator_advance(&entry, i))) {
...@@ -322,7 +322,7 @@ static int submodules_from_head(git_strmap *map, git_tree *head) ...@@ -322,7 +322,7 @@ static int submodules_from_head(git_strmap *map, git_tree *head)
git_iterator *i; git_iterator *i;
const git_index_entry *entry; const git_index_entry *entry;
if ((error = git_iterator_for_tree(&i, head, 0, NULL, NULL)) < 0) if ((error = git_iterator_for_tree(&i, head, NULL)) < 0)
return error; return error;
while (!(error = git_iterator_advance(&entry, i))) { while (!(error = git_iterator_advance(&entry, i))) {
......
...@@ -30,13 +30,17 @@ static void tree_iterator_test( ...@@ -30,13 +30,17 @@ static void tree_iterator_test(
{ {
git_tree *t; git_tree *t;
git_iterator *i; git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry; const git_index_entry *entry;
int error, count = 0, count_post_reset = 0; int error, count = 0, count_post_reset = 0;
git_repository *repo = cl_git_sandbox_init(sandbox); git_repository *repo = cl_git_sandbox_init(sandbox);
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
i_opts.start = start;
i_opts.end = end;
cl_assert(t = resolve_commit_oid_to_tree(repo, treeish)); cl_assert(t = resolve_commit_oid_to_tree(repo, treeish));
cl_git_pass(git_iterator_for_tree( cl_git_pass(git_iterator_for_tree(&i, t, &i_opts));
&i, t, GIT_ITERATOR_DONT_IGNORE_CASE, start, end));
/* test loop */ /* test loop */
while (!(error = git_iterator_advance(&entry, i))) { while (!(error = git_iterator_advance(&entry, i))) {
...@@ -297,6 +301,7 @@ void test_diff_iterator__tree_special_functions(void) ...@@ -297,6 +301,7 @@ void test_diff_iterator__tree_special_functions(void)
{ {
git_tree *t; git_tree *t;
git_iterator *i; git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry; const git_index_entry *entry;
git_repository *repo = cl_git_sandbox_init("attr"); git_repository *repo = cl_git_sandbox_init("attr");
int error, cases = 0; int error, cases = 0;
...@@ -306,8 +311,9 @@ void test_diff_iterator__tree_special_functions(void) ...@@ -306,8 +311,9 @@ void test_diff_iterator__tree_special_functions(void)
repo, "24fa9a9fc4e202313e24b648087495441dab432b"); repo, "24fa9a9fc4e202313e24b648087495441dab432b");
cl_assert(t != NULL); cl_assert(t != NULL);
cl_git_pass(git_iterator_for_tree( i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
&i, t, GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL));
cl_git_pass(git_iterator_for_tree(&i, t, &i_opts));
while (!(error = git_iterator_advance(&entry, i))) { while (!(error = git_iterator_advance(&entry, i))) {
cl_assert(entry); cl_assert(entry);
...@@ -365,11 +371,16 @@ static void index_iterator_test( ...@@ -365,11 +371,16 @@ static void index_iterator_test(
const git_index_entry *entry; const git_index_entry *entry;
int error, count = 0, caps; int error, count = 0, caps;
git_repository *repo = cl_git_sandbox_init(sandbox); git_repository *repo = cl_git_sandbox_init(sandbox);
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_repository_index(&index, repo));
caps = git_index_caps(index); caps = git_index_caps(index);
cl_git_pass(git_iterator_for_index(&i, index, flags, start, end)); iter_opts.flags = flags;
iter_opts.start = start;
iter_opts.end = end;
cl_git_pass(git_iterator_for_index(&i, index, &iter_opts));
while (!(error = git_iterator_advance(&entry, i))) { while (!(error = git_iterator_advance(&entry, i))) {
cl_assert(entry); cl_assert(entry);
...@@ -581,12 +592,16 @@ static void workdir_iterator_test( ...@@ -581,12 +592,16 @@ static void workdir_iterator_test(
const char *an_ignored_name) const char *an_ignored_name)
{ {
git_iterator *i; git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry; const git_index_entry *entry;
int error, count = 0, count_all = 0, count_all_post_reset = 0; int error, count = 0, count_all = 0, count_all_post_reset = 0;
git_repository *repo = cl_git_sandbox_init(sandbox); git_repository *repo = cl_git_sandbox_init(sandbox);
cl_git_pass(git_iterator_for_workdir( i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
&i, repo, NULL, NULL, GIT_ITERATOR_DONT_AUTOEXPAND, start, end)); i_opts.start = start;
i_opts.end = end;
cl_git_pass(git_iterator_for_workdir(&i, repo, NULL, NULL, &i_opts));
error = git_iterator_current(&entry, i); error = git_iterator_current(&entry, i);
cl_assert((error == 0 && entry != NULL) || cl_assert((error == 0 && entry != NULL) ||
...@@ -765,6 +780,7 @@ void test_diff_iterator__workdir_builtin_ignores(void) ...@@ -765,6 +780,7 @@ void test_diff_iterator__workdir_builtin_ignores(void)
{ {
git_repository *repo = cl_git_sandbox_init("attr"); git_repository *repo = cl_git_sandbox_init("attr");
git_iterator *i; git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry; const git_index_entry *entry;
int idx; int idx;
static struct { static struct {
...@@ -796,8 +812,12 @@ void test_diff_iterator__workdir_builtin_ignores(void) ...@@ -796,8 +812,12 @@ void test_diff_iterator__workdir_builtin_ignores(void)
cl_git_pass(p_mkdir("attr/sub/sub/.git", 0777)); cl_git_pass(p_mkdir("attr/sub/sub/.git", 0777));
cl_git_mkfile("attr/sub/.git", "whatever"); cl_git_mkfile("attr/sub/.git", "whatever");
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = "dir";
i_opts.end = "sub/sub/file";
cl_git_pass(git_iterator_for_workdir( cl_git_pass(git_iterator_for_workdir(
&i, repo, NULL, NULL, GIT_ITERATOR_DONT_AUTOEXPAND, "dir", "sub/sub/file")); &i, repo, NULL, NULL, &i_opts));
cl_git_pass(git_iterator_current(&entry, i)); cl_git_pass(git_iterator_current(&entry, i));
for (idx = 0; entry != NULL; ++idx) { for (idx = 0; entry != NULL; ++idx) {
...@@ -827,12 +847,17 @@ static void check_wd_first_through_third_range( ...@@ -827,12 +847,17 @@ static void check_wd_first_through_third_range(
git_repository *repo, const char *start, const char *end) git_repository *repo, const char *start, const char *end)
{ {
git_iterator *i; git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry; const git_index_entry *entry;
int error, idx; int error, idx;
static const char *expected[] = { "FIRST", "second", "THIRD", NULL }; static const char *expected[] = { "FIRST", "second", "THIRD", NULL };
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
i_opts.start = start;
i_opts.end = end;
cl_git_pass(git_iterator_for_workdir( cl_git_pass(git_iterator_for_workdir(
&i, repo, NULL, NULL, GIT_ITERATOR_IGNORE_CASE, start, end)); &i, repo, NULL, NULL, &i_opts));
cl_git_pass(git_iterator_current(&entry, i)); cl_git_pass(git_iterator_current(&entry, i));
for (idx = 0; entry != NULL; ++idx) { for (idx = 0; entry != NULL; ++idx) {
...@@ -877,14 +902,16 @@ static void check_tree_range( ...@@ -877,14 +902,16 @@ static void check_tree_range(
{ {
git_tree *head; git_tree *head;
git_iterator *i; git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
int error, count; int error, count;
i_opts.flags = ignore_case ? GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE;
i_opts.start = start;
i_opts.end = end;
cl_git_pass(git_repository_head_tree(&head, repo)); cl_git_pass(git_repository_head_tree(&head, repo));
cl_git_pass(git_iterator_for_tree( cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
&i, head,
ignore_case ? GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE,
start, end));
for (count = 0; !(error = git_iterator_advance(NULL, i)); ++count) for (count = 0; !(error = git_iterator_advance(NULL, i)); ++count)
/* count em up */; /* count em up */;
...@@ -931,6 +958,7 @@ static void check_index_range( ...@@ -931,6 +958,7 @@ static void check_index_range(
{ {
git_index *index; git_index *index;
git_iterator *i; git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
int error, count, caps; int error, count, caps;
bool is_ignoring_case; bool is_ignoring_case;
...@@ -942,7 +970,11 @@ static void check_index_range( ...@@ -942,7 +970,11 @@ static void check_index_range(
if (ignore_case != is_ignoring_case) if (ignore_case != is_ignoring_case)
cl_git_pass(git_index_set_caps(index, caps ^ GIT_INDEXCAP_IGNORE_CASE)); cl_git_pass(git_index_set_caps(index, caps ^ GIT_INDEXCAP_IGNORE_CASE));
cl_git_pass(git_iterator_for_index(&i, index, 0, start, end)); i_opts.flags = 0;
i_opts.start = start;
i_opts.end = end;
cl_git_pass(git_iterator_for_index(&i, index, &i_opts));
cl_assert(git_iterator_ignore_case(i) == ignore_case); cl_assert(git_iterator_ignore_case(i) == ignore_case);
......
...@@ -44,6 +44,7 @@ static void test_find_differences( ...@@ -44,6 +44,7 @@ static void test_find_differences(
git_oid ancestor_oid, ours_oid, theirs_oid; git_oid ancestor_oid, ours_oid, theirs_oid;
git_tree *ancestor_tree, *ours_tree, *theirs_tree; git_tree *ancestor_tree, *ours_tree, *theirs_tree;
git_iterator *ancestor_iter, *ours_iter, *theirs_iter; git_iterator *ancestor_iter, *ours_iter, *theirs_iter;
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT; git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
opts.tree_flags |= GIT_MERGE_TREE_FIND_RENAMES; opts.tree_flags |= GIT_MERGE_TREE_FIND_RENAMES;
...@@ -67,12 +68,11 @@ static void test_find_differences( ...@@ -67,12 +68,11 @@ static void test_find_differences(
cl_git_pass(git_tree_lookup(&ours_tree, repo, &ours_oid)); cl_git_pass(git_tree_lookup(&ours_tree, repo, &ours_oid));
cl_git_pass(git_tree_lookup(&theirs_tree, repo, &theirs_oid)); cl_git_pass(git_tree_lookup(&theirs_tree, repo, &theirs_oid));
cl_git_pass(git_iterator_for_tree(&ancestor_iter, ancestor_tree, iter_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL));
cl_git_pass(git_iterator_for_tree(&ours_iter, ours_tree, cl_git_pass(git_iterator_for_tree(&ancestor_iter, ancestor_tree, &iter_opts));
GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL)); cl_git_pass(git_iterator_for_tree(&ours_iter, ours_tree, &iter_opts));
cl_git_pass(git_iterator_for_tree(&theirs_iter, theirs_tree, cl_git_pass(git_iterator_for_tree(&theirs_iter, theirs_tree, &iter_opts));
GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL));
cl_git_pass(git_merge_diff_list__find_differences(merge_diff_list, ancestor_iter, ours_iter, theirs_iter)); cl_git_pass(git_merge_diff_list__find_differences(merge_diff_list, ancestor_iter, ours_iter, theirs_iter));
cl_git_pass(git_merge_diff_list__find_renames(repo, merge_diff_list, &opts)); cl_git_pass(git_merge_diff_list__find_renames(repo, merge_diff_list, &opts));
......
...@@ -264,6 +264,7 @@ static int confirm_submodule_status( ...@@ -264,6 +264,7 @@ static int confirm_submodule_status(
void test_submodule_status__iterator(void) void test_submodule_status__iterator(void)
{ {
git_iterator *iter; git_iterator *iter;
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry; const git_index_entry *entry;
size_t i; size_t i;
static const char *expected[] = { static const char *expected[] = {
...@@ -308,9 +309,10 @@ void test_submodule_status__iterator(void) ...@@ -308,9 +309,10 @@ void test_submodule_status__iterator(void)
git_status_options opts = GIT_STATUS_OPTIONS_INIT; git_status_options opts = GIT_STATUS_OPTIONS_INIT;
git_index *index; git_index *index;
iter_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_repository_index(&index, g_repo)); cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_iterator_for_workdir(&iter, g_repo, index, NULL, cl_git_pass(git_iterator_for_workdir(&iter, g_repo, index, NULL, &iter_opts));
GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
for (i = 0; !git_iterator_advance(&entry, iter); ++i) for (i = 0; !git_iterator_advance(&entry, iter); ++i)
cl_assert_equal_s(expected[i], entry->path); cl_assert_equal_s(expected[i], entry->path);
......
...@@ -13,10 +13,13 @@ static void *run_workdir_iterator(void *arg) ...@@ -13,10 +13,13 @@ static void *run_workdir_iterator(void *arg)
{ {
int error = 0; int error = 0;
git_iterator *iter; git_iterator *iter;
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry = NULL; const git_index_entry *entry = NULL;
iter_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
cl_git_pass(git_iterator_for_workdir( cl_git_pass(git_iterator_for_workdir(
&iter, _repo, NULL, NULL, GIT_ITERATOR_DONT_AUTOEXPAND, NULL, NULL)); &iter, _repo, NULL, NULL, &iter_opts));
while (!error) { while (!error) {
if (entry && entry->mode == GIT_FILEMODE_TREE) { if (entry && entry->mode == GIT_FILEMODE_TREE) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment