Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-08-09 21:52:35 +0400
committerRussell Belfer <rb@github.com>2013-08-09 21:52:35 +0400
commit4ba64794aee983483eef659623a765d61311ded1 (patch)
tree33b048d3b6bda96f53058f43ff6303c257fcb7fb /src/attr_file.c
parentfbb6c0c84c65d5e36ad552040897cfbde83b59b2 (diff)
Revert PR #1462 and provide alternative fix
This rolls back the changes to fnmatch parsing from commit 2e40a60e847d6c128af23e24ea7a8efebd2427da except for the tests that were added. Instead this adds couple of new flags that can be passed in when attempting to parse an fnmatch pattern. Also, this changes the pathspec match logic to special case matching a filename with a '!' prefix against a negative pattern. This fixes the build.
Diffstat (limited to 'src/attr_file.c')
-rw-r--r--src/attr_file.c61
1 files changed, 19 insertions, 42 deletions
diff --git a/src/attr_file.c b/src/attr_file.c
index ca5f2137c..92702df98 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -79,13 +79,17 @@ int git_attr_file__parse_buffer(
while (!error && *scan) {
/* allocate rule if needed */
- if (!rule && !(rule = git__calloc(1, sizeof(git_attr_rule)))) {
- error = -1;
- break;
+ if (!rule) {
+ if (!(rule = git__calloc(1, sizeof(git_attr_rule)))) {
+ error = -1;
+ break;
+ }
+ rule->match.flags = GIT_ATTR_FNMATCH_ALLOWNEG |
+ GIT_ATTR_FNMATCH_ALLOWMACRO;
}
/* parse the next "pattern attr attr attr" line */
- if (!(error = git_attr_fnmatch__parse_gitattr_format(
+ if (!(error = git_attr_fnmatch__parse(
&rule->match, attrs->pool, context, &scan)) &&
!(error = git_attr_assignment__parse(
repo, attrs->pool, &rule->assigns, &scan)))
@@ -337,16 +341,23 @@ 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_gitattr_format(
+int git_attr_fnmatch__parse(
git_attr_fnmatch *spec,
git_pool *pool,
const char *source,
const char **base)
{
- const char *pattern;
+ const char *pattern, *scan;
+ int slash_count, allow_space;
assert(spec && base && *base);
+ if (parse_optimized_patterns(spec, pool, *base))
+ return 0;
+
+ spec->flags = (spec->flags & GIT_ATTR_FNMATCH__INCOMING);
+ allow_space = ((spec->flags & GIT_ATTR_FNMATCH_ALLOWSPACE) != 0);
+
pattern = *base;
while (git__isspace(*pattern)) pattern++;
@@ -355,7 +366,7 @@ int git_attr_fnmatch__parse_gitattr_format(
return GIT_ENOTFOUND;
}
- if (*pattern == '[') {
+ if (*pattern == '[' && (spec->flags & GIT_ATTR_FNMATCH_ALLOWMACRO) != 0) {
if (strncmp(pattern, "[attr]", 6) == 0) {
spec->flags = spec->flags | GIT_ATTR_FNMATCH_MACRO;
pattern += 6;
@@ -363,44 +374,11 @@ int git_attr_fnmatch__parse_gitattr_format(
/* else a character range like [a-e]* which is accepted */
}
- if (*pattern == '!') {
+ if (*pattern == '!' && (spec->flags & GIT_ATTR_FNMATCH_ALLOWNEG) != 0) {
spec->flags = spec->flags | GIT_ATTR_FNMATCH_NEGATIVE;
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 */
@@ -636,7 +614,6 @@ 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)