diff options
author | yorah <yoram.harmelin@gmail.com> | 2013-01-18 16:37:13 +0100 |
---|---|---|
committer | yorah <yoram.harmelin@gmail.com> | 2013-02-07 20:44:34 +0100 |
commit | 943700ecbbc2be4ef49c5c31d8e5c49353fd3d84 (patch) | |
tree | 4e49b623e5df6506acb995ed5b492ff18d658a18 /src/pathspec.c | |
parent | 41713ec15f66d263c2d7d40dd07f1f5a468e3e22 (diff) | |
download | libgit2-943700ecbbc2be4ef49c5c31d8e5c49353fd3d84.tar.gz |
Return the matched pathspec pattern in `git_pathspec_match_path`
Instead of returning directly the pattern as the return value, I used an
out parameter, because the function also tests if the passed pathspecs
vector is empty. If yes, it considers that the path "matches", but in
that case there is no matched pattern per se.
Diffstat (limited to 'src/pathspec.c')
-rw-r--r-- | src/pathspec.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/pathspec.c b/src/pathspec.c index 2bde3ba5f..732180248 100644 --- a/src/pathspec.c +++ b/src/pathspec.c @@ -106,14 +106,21 @@ void git_pathspec_free(git_vector *vspec) /* match a path against the vectorized pathspec */ bool git_pathspec_match_path( - git_vector *vspec, const char *path, bool disable_fnmatch, bool casefold) + git_vector *vspec, + const char *path, + bool disable_fnmatch, + bool casefold, + const char **matched_pathspec) { - unsigned int i; + size_t i; git_attr_fnmatch *match; int fnmatch_flags = 0; int (*use_strcmp)(const char *, const char *); int (*use_strncmp)(const char *, const char *, size_t); + if (matched_pathspec) + *matched_pathspec = NULL; + if (!vspec || !vspec->length) return true; @@ -143,8 +150,12 @@ bool git_pathspec_match_path( path[match->length] == '/') result = 0; - if (result == 0) + if (result == 0) { + if (matched_pathspec) + *matched_pathspec = match->pattern; + return (match->flags & GIT_ATTR_FNMATCH_NEGATIVE) ? false : true; + } } return false; |