diff options
author | Edward Thomson <ethomson@microsoft.com> | 2015-08-28 18:30:39 -0400 |
---|---|---|
committer | Edward Thomson <ethomson@microsoft.com> | 2015-08-28 18:40:02 -0400 |
commit | 6c9352bf30e97af5d646d92ceab1c7b0f4c7a1c4 (patch) | |
tree | c5ebd5511ad3bc7a48fef8b1f270e5228357f305 /src/iterator.c | |
parent | 810cabb9dfa57127e78cb47dbe8ea95943fb2642 (diff) | |
download | libgit2-6c9352bf30e97af5d646d92ceab1c7b0f4c7a1c4.tar.gz |
iterator: sort subdirs properly with pathlist
When given a pathlist, don't assume that directories sort before
files. Walk through any list of entries sorting before us to make
sure that we've exhausted all entries that *aren't* directories.
Eg, if we're searching for 'foo/bar', and we have a 'foo.c', keep
advancing the pathlist to keep looking for an entry prefixed with
'foo/'.
Diffstat (limited to 'src/iterator.c')
-rw-r--r-- | src/iterator.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/iterator.c b/src/iterator.c index 28629c708..9fa7cab2c 100644 --- a/src/iterator.c +++ b/src/iterator.c @@ -1071,13 +1071,22 @@ static dirload_pathlist_match_t dirload_pathlist_match( &idx, pathlist, pathlist->_cmp, path) != GIT_ENOTFOUND) return DIRLOAD_PATHLIST_EXACT; - /* the explicit path we searched for was not found, but this may be - * a directory and the pathlist contains a file in it. check. + /* the explicit path that we've seen in the directory iterator was + * not found - however, we may have hit a subdirectory in the directory + * iterator. examine the pathlist to see if it contains children of the + * current path. if so, indicate that we've found a subdirectory that + * is worth examining. */ - if ((matched = git_vector_get(pathlist, idx)) != NULL && - prefixcomp(matched, path) == 0 && - matched[path_len] == '/') - return DIRLOAD_PATHLIST_DIRECTORY; + while ((matched = git_vector_get(pathlist, idx)) != NULL && + prefixcomp(matched, path) == 0) { + + if (matched[path_len] == '/') + return DIRLOAD_PATHLIST_DIRECTORY; + else if (matched[path_len] > '/') + break; + + idx++; + } return DIRLOAD_PATHLIST_NONE; } |