summaryrefslogtreecommitdiff
path: root/src/attr_file.c
diff options
context:
space:
mode:
authoryorah <yoram.harmelin@gmail.com>2013-03-04 11:31:50 +0100
committeryorah <yoram.harmelin@gmail.com>2013-04-11 09:59:26 +0200
commit0d32f39eb821dfec2e241ea633c0a6e94c21519d (patch)
tree49ce60c1cecc70320feeef279707699387662906 /src/attr_file.c
parent575a54db856947aeb4fc5cf1977844d22dfa1aab (diff)
downloadlibgit2-0d32f39eb821dfec2e241ea633c0a6e94c21519d.tar.gz
Notify '*' pathspec correctly when diffing
I also moved all tests related to notifying in their own file.
Diffstat (limited to 'src/attr_file.c')
-rw-r--r--src/attr_file.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/attr_file.c b/src/attr_file.c
index 74bd2133f..85cd87624 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -8,6 +8,10 @@
static int sort_by_hash_and_name(const void *a_raw, const void *b_raw);
static void git_attr_rule__clear(git_attr_rule *rule);
+static bool parse_optimized_patterns(
+ git_attr_fnmatch *spec,
+ git_pool *pool,
+ const char *pattern);
int git_attr_file__new(
git_attr_file **attrs_ptr,
@@ -296,7 +300,6 @@ void git_attr_path__free(git_attr_path *info)
info->basename = NULL;
}
-
/*
* From gitattributes(5):
*
@@ -345,6 +348,9 @@ int git_attr_fnmatch__parse(
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);
@@ -430,6 +436,22 @@ int git_attr_fnmatch__parse(
return 0;
}
+static bool parse_optimized_patterns(
+ git_attr_fnmatch *spec,
+ git_pool *pool,
+ const char *pattern)
+{
+ if (!pattern[1] && (pattern[0] == '*' || pattern[0] == '.')) {
+ spec->flags = GIT_ATTR_FNMATCH_MATCH_ALL;
+ spec->pattern = git_pool_strndup(pool, pattern, 1);
+ spec->length = 1;
+
+ return true;
+ }
+
+ return false;
+}
+
static int sort_by_hash_and_name(const void *a_raw, const void *b_raw)
{
const git_attr_name *a = a_raw;