diff options
author | Russell Belfer <rb@github.com> | 2013-08-09 09:32:06 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-08-09 09:32:06 -0700 |
commit | 33d532dcfacbc0d936341848efc60dd55956ec10 (patch) | |
tree | 2f6bbfb7e6ee7d3fde653982f9026fe65751a88c /src | |
parent | 7f7ebe13c458217dcae419914dd15b434f513373 (diff) | |
parent | 2e40a60e847d6c128af23e24ea7a8efebd2427da (diff) | |
download | libgit2-33d532dcfacbc0d936341848efc60dd55956ec10.tar.gz |
Merge pull request #1462 from yorah/fix/libgit2sharp-issue-379
status: fix handling of filenames with special prefixes
Diffstat (limited to 'src')
-rw-r--r-- | src/attr_file.c | 47 | ||||
-rw-r--r-- | src/attr_file.h | 8 | ||||
-rw-r--r-- | src/ignore.c | 2 | ||||
-rw-r--r-- | src/pathspec.c | 2 |
4 files changed, 46 insertions, 13 deletions
diff --git a/src/attr_file.c b/src/attr_file.c index d880398e8..ca5f2137c 100644 --- a/src/attr_file.c +++ b/src/attr_file.c @@ -85,7 +85,7 @@ int git_attr_file__parse_buffer( } /* parse the next "pattern attr attr attr" line */ - if (!(error = git_attr_fnmatch__parse( + if (!(error = git_attr_fnmatch__parse_gitattr_format( &rule->match, attrs->pool, context, &scan)) && !(error = git_attr_assignment__parse( repo, attrs->pool, &rule->assigns, &scan))) @@ -337,23 +337,16 @@ void git_attr_path__free(git_attr_path *info) * GIT_ENOTFOUND if the fnmatch does not require matching, or * another error code there was an actual problem. */ -int git_attr_fnmatch__parse( +int git_attr_fnmatch__parse_gitattr_format( git_attr_fnmatch *spec, git_pool *pool, const char *source, const char **base) { - const char *pattern, *scan; - int slash_count, allow_space; + const char *pattern; assert(spec && base && *base); - if (parse_optimized_patterns(spec, pool, *base)) - return 0; - - spec->flags = (spec->flags & GIT_ATTR_FNMATCH_ALLOWSPACE); - allow_space = (spec->flags != 0); - pattern = *base; while (git__isspace(*pattern)) pattern++; @@ -375,6 +368,39 @@ int git_attr_fnmatch__parse( pattern++; } + if (git_attr_fnmatch__parse_shellglob_format(spec, pool, + source, &pattern) < 0) + return -1; + + *base = pattern; + + return 0; +} + +/* + * Fills a spec for the purpose of pure pathspec matching, not + * related to a gitattribute file parsing. + * + * This will return 0 if the spec was filled out, or + * another error code there was an actual problem. + */ +int git_attr_fnmatch__parse_shellglob_format( + git_attr_fnmatch *spec, + git_pool *pool, + const char *source, + const char **base) +{ + const char *pattern, *scan; + int slash_count, allow_space; + + assert(spec && base && *base); + + if (parse_optimized_patterns(spec, pool, *base)) + return 0; + + allow_space = (spec->flags & GIT_ATTR_FNMATCH_ALLOWSPACE) != 0; + pattern = *base; + slash_count = 0; for (scan = pattern; *scan != '\0'; ++scan) { /* scan until (non-escaped) white space */ @@ -610,6 +636,7 @@ static void git_attr_rule__clear(git_attr_rule *rule) /* match.pattern is stored in a git_pool, so no need to free */ rule->match.pattern = NULL; rule->match.length = 0; + rule->match.flags = 0; } void git_attr_rule__free(git_attr_rule *rule) diff --git a/src/attr_file.h b/src/attr_file.h index 15bba1c6a..afea1e115 100644 --- a/src/attr_file.h +++ b/src/attr_file.h @@ -115,7 +115,13 @@ extern uint32_t git_attr_file__name_hash(const char *name); * other utilities */ -extern int git_attr_fnmatch__parse( +extern int git_attr_fnmatch__parse_gitattr_format( + git_attr_fnmatch *spec, + git_pool *pool, + const char *source, + const char **base); + +extern int git_attr_fnmatch__parse_shellglob_format( git_attr_fnmatch *spec, git_pool *pool, const char *source, diff --git a/src/ignore.c b/src/ignore.c index cc90b0c61..7d8280403 100644 --- a/src/ignore.c +++ b/src/ignore.c @@ -39,7 +39,7 @@ static int parse_ignore_file( match->flags = GIT_ATTR_FNMATCH_ALLOWSPACE; - if (!(error = git_attr_fnmatch__parse( + if (!(error = git_attr_fnmatch__parse_gitattr_format( match, ignores->pool, context, &scan))) { match->flags |= GIT_ATTR_FNMATCH_IGNORE; diff --git a/src/pathspec.c b/src/pathspec.c index 625726e0b..4266bb99e 100644 --- a/src/pathspec.c +++ b/src/pathspec.c @@ -85,7 +85,7 @@ int git_pathspec__vinit( match->flags = GIT_ATTR_FNMATCH_ALLOWSPACE; - ret = git_attr_fnmatch__parse(match, strpool, NULL, &pattern); + ret = git_attr_fnmatch__parse_shellglob_format(match, strpool, NULL, &pattern); if (ret == GIT_ENOTFOUND) { git__free(match); continue; |