Always do tree to index diffs case sensitively

Trees are always case sensitive.  The index is always case
preserving and will be case sensitive when it is turned into a
tree.  Therefore the tree and the index can and should always
be compared to one another case sensitively.

This will restore the index to case insensitive order after the
diff has been generated.

Consider this a short-term fix.  The long term fix is to have the
index always stored both case sensitively and case insensitively
(at least on platforms that sometimes require case insensitivity).
This commit is contained in:
Russell Belfer 2013-06-13 16:09:53 -07:00
parent 6ea999bb88
commit eefef642c8

View File

@ -364,6 +364,8 @@ static git_diff_list *diff_list_alloc(
diff->strncomp = git__strncasecmp; diff->strncomp = git__strncasecmp;
diff->pfxcomp = git__prefixcmp_icase; diff->pfxcomp = git__prefixcmp_icase;
diff->entrycomp = git_index_entry__cmp_icase; diff->entrycomp = git_index_entry__cmp_icase;
diff->deltas._cmp = git_diff_delta__casecmp;
} }
return diff; return diff;
@ -1127,17 +1129,40 @@ int git_diff_tree_to_index(
const git_diff_options *opts) const git_diff_options *opts)
{ {
int error = 0; int error = 0;
bool reset_index_ignore_case = false;
assert(diff && repo); assert(diff && repo);
if (!index && (error = git_repository_index__weakptr(&index, repo)) < 0) if (!index && (error = git_repository_index__weakptr(&index, repo)) < 0)
return error; return error;
if (index->ignore_case) {
git_index__set_ignore_case(index, false);
reset_index_ignore_case = true;
}
DIFF_FROM_ITERATORS( DIFF_FROM_ITERATORS(
git_iterator_for_tree(&a, old_tree, 0, pfx, pfx), git_iterator_for_tree(&a, old_tree, 0, pfx, pfx),
git_iterator_for_index(&b, index, 0, pfx, pfx) git_iterator_for_index(&b, index, 0, pfx, pfx)
); );
if (reset_index_ignore_case) {
git_index__set_ignore_case(index, true);
if (!error) {
git_diff_list *d = *diff;
d->opts.flags |= GIT_DIFF_DELTAS_ARE_ICASE;
d->strcomp = git__strcasecmp;
d->strncomp = git__strncasecmp;
d->pfxcomp = git__prefixcmp_icase;
d->entrycomp = git_index_entry__cmp_icase;
d->deltas._cmp = git_diff_delta__casecmp;
git_vector_sort(&d->deltas);
}
}
return error; return error;
} }