Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-03-11 22:31:50 +0400
committerRussell Belfer <rb@github.com>2013-03-11 22:31:50 +0400
commita5eea2d7b760ebef0d2f397d763ec8eff32f38cd (patch)
tree0e718ce8321413dffafabe26c9b94da08f5efdc7 /src/iterator.c
parentaec4f6633ccdd359a39d712a27f87e613f788f6c (diff)
Stabilize order for equiv tree iterator entries
Given a group of case-insensitively equivalent tree iterator entries, this ensures that the case-sensitively first trees will be used as the representative items. I.e. if you have conflicting entries "A/B/x", "a/b/x", and "A/b/x", this change ensures that the earliest entry "A/B/x" will be returned. The actual choice is not that important, but it is nice to have it stable and to have it been either the first or last item, as opposed to a random item from within the equivalent span.
Diffstat (limited to 'src/iterator.c')
-rw-r--r--src/iterator.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/iterator.c b/src/iterator.c
index fb76085cd..e6e0ea481 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -285,9 +285,21 @@ static int tree_iterator__tree_entry_cmp(
static int tree_iterator__entry_cmp(const void *a, const void *b, void *p)
{
- return tree_iterator__tree_entry_cmp(
- tree_iterator__tree_entry(p, a), tree_iterator__tree_entry(p, b),
- git__strncasecmp);
+ const tree_iterator_entry *ae = a, *be = b;
+ const git_tree_entry *ate = tree_iterator__tree_entry(p, ae);
+ const git_tree_entry *bte = tree_iterator__tree_entry(p, be);
+ int cmp = tree_iterator__tree_entry_cmp(ate, bte, git__strncasecmp);
+
+ /* stabilize sort order among equivalent names */
+ if (!cmp) {
+ cmp = (ae->parent_entry_index < be->parent_entry_index) ? -1 :
+ (ae->parent_entry_index > be->parent_entry_index) ? 1 : 0;
+ if (!cmp)
+ cmp = (ae->parent_tree_index < be->parent_tree_index) ? -1 :
+ (ae->parent_tree_index > be->parent_tree_index) ? 1 : 0;
+ }
+
+ return cmp;
}
static int tree_iterator__set_next(tree_iterator *ti, tree_iterator_frame *tf)