Commit 546d65a8dae8a7af7288163a580c08c827ebda1d

Russell Belfer 2013-01-02T17:01:34

Fix up spoolandsort iterator usage The spoolandsort iterator changes got sort-of cherry picked out of this branch and so I dropped the commit when rebasing; however, there were a few small changes that got dropped as well (since the version merged upstream wasn't quite the same as what I dropped).

diff --git a/src/checkout.c b/src/checkout.c
index a62df5e..76119c6 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -1223,8 +1223,7 @@ int git_checkout_iterator(
 
 	/* Handle case insensitivity for baseline if necessary */
 	if (workdir->ignore_case && !baseline->ignore_case) {
-		if ((error = git_iterator_spoolandsort(
-				&baseline, baseline, git_index_entry__cmp_icase, true)) < 0)
+		if ((error = git_iterator_spoolandsort_push(baseline, true)) < 0)
 			goto cleanup;
 	}
 
diff --git a/src/diff.c b/src/diff.c
index 042cdf4..82a8164 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -589,8 +589,7 @@ int git_diff__from_iterators(
 
 	*diff_ptr = NULL;
 
-	if (!diff ||
-		diff_list_init_from_iterators(diff, old_iter, new_iter) < 0)
+	if (!diff || diff_list_init_from_iterators(diff, old_iter, new_iter) < 0)
 		goto fail;
 
 	if (diff->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) {
diff --git a/src/iterator.c b/src/iterator.c
index b154534..cf88eff 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -30,8 +30,8 @@
 	(P)->base.start   = start ? git__strdup(start) : NULL; \
 	(P)->base.end     = end ? git__strdup(end) : NULL; \
 	(P)->base.ignore_case = false; \
-	if ((start && !(P)->base.start) || (end && !(P)->base.end)) \
-		return -1; \
+	if ((start && !(P)->base.start) || (end && !(P)->base.end)) { \
+		git__free(P); return -1; } \
 	} while (0)
 
 static int iterator__reset_range(
@@ -990,31 +990,24 @@ fail:
 
 git_index *git_iterator_index_get_index(git_iterator *iter)
 {
-	if (iter->type == GIT_ITERATOR_SPOOLANDSORT)
-		iter = ((spoolandsort_iterator *)iter)->wrapped;
-
 	if (iter->type == GIT_ITERATOR_INDEX)
 		return ((index_iterator *)iter)->index;
 
+	if (iter->type == GIT_ITERATOR_SPOOLANDSORT &&
+		((spoolandsort_callbacks *)iter->cb)->orig_type == GIT_ITERATOR_INDEX)
+		return ((index_iterator *)iter)->index;
+
 	return NULL;
 }
 
 git_iterator_type_t git_iterator_inner_type(git_iterator *iter)
 {
 	if (iter->type == GIT_ITERATOR_SPOOLANDSORT)
-		iter = ((spoolandsort_iterator *)iter)->wrapped;
+		return ((spoolandsort_callbacks *)iter->cb)->orig_type;
 
 	return iter->type;
 }
 
-git_iterator *git_iterator_spoolandsort_inner_iterator(git_iterator *iter)
-{
-	if (iter->type == GIT_ITERATOR_SPOOLANDSORT)
-		return ((spoolandsort_iterator *)iter)->wrapped;
-
-	return NULL;
-}
-
 int git_iterator_current_tree_entry(
 	git_iterator *iter, const git_tree_entry **tree_entry)
 {
@@ -1085,8 +1078,8 @@ int git_iterator_advance_into_directory(
 
 	if (iter->type == GIT_ITERATOR_WORKDIR &&
 		wi->entry.path &&
-		S_ISDIR(wi->entry.mode) &&
-		!S_ISGITLINK(wi->entry.mode))
+		(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. */
diff --git a/src/iterator.h b/src/iterator.h
index ccdab4d..c0e3560 100644
--- a/src/iterator.h
+++ b/src/iterator.h
@@ -198,7 +198,4 @@ extern git_index *git_iterator_index_get_index(git_iterator *iter);
 
 extern git_iterator_type_t git_iterator_inner_type(git_iterator *iter);
 
-extern git_iterator *git_iterator_spoolandsort_inner_iterator(
-	git_iterator *iter);
-
 #endif