summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-06-13 16:09:53 -0700
committerRussell Belfer <rb@github.com>2013-06-17 10:03:49 -0700
commiteefef642c8c0d9d527633294acdf9d7a0c9e94c0 (patch)
tree3dfded43c63d45d3cd30464b8e7f89aed0f20af4
parent6ea999bb88e1c5d0be17d823c23728d11adfed47 (diff)
downloadlibgit2-eefef642c8c0d9d527633294acdf9d7a0c9e94c0.tar.gz
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).
-rw-r--r--src/diff.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/diff.c b/src/diff.c
index 87189a49c..fa2c5c71d 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -364,6 +364,8 @@ static git_diff_list *diff_list_alloc(
diff->strncomp = git__strncasecmp;
diff->pfxcomp = git__prefixcmp_icase;
diff->entrycomp = git_index_entry__cmp_icase;
+
+ diff->deltas._cmp = git_diff_delta__casecmp;
}
return diff;
@@ -1127,17 +1129,40 @@ int git_diff_tree_to_index(
const git_diff_options *opts)
{
int error = 0;
+ bool reset_index_ignore_case = false;
assert(diff && repo);
if (!index && (error = git_repository_index__weakptr(&index, repo)) < 0)
return error;
+ if (index->ignore_case) {
+ git_index__set_ignore_case(index, false);
+ reset_index_ignore_case = true;
+ }
+
DIFF_FROM_ITERATORS(
git_iterator_for_tree(&a, old_tree, 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;
}