summaryrefslogtreecommitdiff
path: root/src/index.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2014-01-29 12:55:33 -0800
committerEdward Thomson <ethomson@microsoft.com>2014-01-29 13:15:54 -0800
commitb747eb1445fa54675044b6d05e892904b517239c (patch)
tree9bb00b0780c8cf8173ad506bffc0f4de8a10045b /src/index.c
parentbae8bea051806682fef48137e32f0305e94398b8 (diff)
downloadlibgit2-b747eb1445fa54675044b6d05e892904b517239c.tar.gz
Give index_isrch the same semantics as index_srch
In case insensitive index mode, we would stop at a prefixed entry, treating the provided search key length as a substring, not the length of the string to match.
Diffstat (limited to 'src/index.c')
-rw-r--r--src/index.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/index.c b/src/index.c
index aa30f9d32..01321d8a1 100644
--- a/src/index.c
+++ b/src/index.c
@@ -134,14 +134,25 @@ static int index_isrch(const void *key, const void *array_member)
{
const struct entry_srch_key *srch_key = key;
const git_index_entry *entry = array_member;
- int ret;
+ int cmp, len1, len2, len;
- ret = strcasecmp(srch_key->path, entry->path);
+ len1 = srch_key->path_len;
+ len2 = strlen(entry->path);
+ len = len1 < len2 ? len1 : len2;
- if (ret == 0 && srch_key->stage != GIT_INDEX_STAGE_ANY)
- ret = srch_key->stage - GIT_IDXENTRY_STAGE(entry);
+ cmp = strncasecmp(srch_key->path, entry->path, len);
- return ret;
+ if (cmp)
+ return cmp;
+ if (len1 < len2)
+ return -1;
+ if (len1 > len2)
+ return 1;
+
+ if (srch_key->stage != GIT_INDEX_STAGE_ANY)
+ return srch_key->stage - GIT_IDXENTRY_STAGE(entry);
+
+ return 0;
}
static int index_cmp_path(const void *a, const void *b)