summaryrefslogtreecommitdiff
path: root/src/checkout.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-03-05 16:10:05 -0800
committerRussell Belfer <rb@github.com>2013-03-06 16:52:01 -0800
commit169dc61607b69726c6012ab70758692637928a85 (patch)
tree01593b00741391d9c9d6aad6344aed4cbc8ef6a4 /src/checkout.c
parented4f95e5d9f2f59dc5d5a4b76a696b0595b6175d (diff)
downloadlibgit2-169dc61607b69726c6012ab70758692637928a85.tar.gz
Make iterator APIs consistent with standards
The iterator APIs are not currently consistent with the parameter ordering of the rest of the codebase. This rearranges the order of parameters, simplifies the naming of a number of functions, and makes somewhat better use of macros internally to clean up the iterator code. This also expands the test coverage of iterator functionality, making sure that case sensitive range-limited iteration works correctly.
Diffstat (limited to 'src/checkout.c')
-rw-r--r--src/checkout.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/src/checkout.c b/src/checkout.c
index 19ac913d3..0be87b4a3 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,9 +1242,9 @@ 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(
+ (error = git_iterator_for_workdir(
&workdir, data.repo, iterflags, data.pfx, data.pfx)) < 0 ||
- (error = git_iterator_for_tree_range(
+ (error = git_iterator_for_tree(
&baseline, data.opts.baseline, iterflags, data.pfx, data.pfx)) < 0)
goto cleanup;
@@ -1321,7 +1322,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 +1349,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 +1370,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);