diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2015-12-03 16:27:15 -0500 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2015-12-03 16:27:15 -0500 |
commit | 626f9e243edbd8d82a27557b3433d19217714069 (patch) | |
tree | 55bce104986ced6256a3bb4747da33af2d804d87 | |
parent | 15e6a5afb9217b09e60cd0aef48e0a7781f3922f (diff) | |
download | libgit2-626f9e243edbd8d82a27557b3433d19217714069.tar.gz |
index: canonicalize inserted paths safely
When adding to the index, we look to see if a portion of the given
path matches a portion of a path in the index. If so, we will use
the existing path information. For example, when adding `foo/bar.c`,
if there is an index entry to `FOO/other` and the filesystem is case
insensitive, then we will put `bar.c` into the existing tree instead
of creating a new one with a different case.
Use `strncmp` to do that instead of `memcmp`. When we `bsearch`
into the index, we locate the position where the new entry would
go. The index entry at that position does not necessarily have
a relation to the entry we're adding, so we cannot make assumptions
and use `memcmp`. Instead, compare them as strings.
When canonicalizing paths, we look for the first index entry that
matches a given substring.
-rw-r--r-- | src/index.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/index.c b/src/index.c index ca5b2c46e..391738e39 100644 --- a/src/index.c +++ b/src/index.c @@ -1167,7 +1167,7 @@ static int canonicalize_directory_path( while ((match = git_vector_get(&index->entries, pos))) { if (GIT_IDXENTRY_STAGE(match) != 0) { /* conflicts do not contribute to canonical paths */ - } else if (memcmp(search, match->path, search_len) == 0) { + } else if (strncmp(search, match->path, search_len) == 0) { /* prefer an exact match to the input filename */ best = match; best_len = search_len; |