From 546d65a8dae8a7af7288163a580c08c827ebda1d Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Wed, 2 Jan 2013 17:01:34 -0800 Subject: [PATCH] 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). --- src/checkout.c | 3 +-- src/diff.c | 3 +-- src/iterator.c | 25 +++++++++---------------- src/iterator.h | 3 --- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/checkout.c b/src/checkout.c index a62df5efd..76119c6e9 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 042cdf451..82a816465 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 b15453400..cf88efffd 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 ccdab4d94..c0e35605c 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