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
path: root/src
diff options
context:
space:
mode:
authoryorah <yoram.harmelin@gmail.com>2013-03-04 14:31:50 +0400
committeryorah <yoram.harmelin@gmail.com>2013-04-11 11:59:26 +0400
commit0d32f39eb821dfec2e241ea633c0a6e94c21519d (patch)
tree49ce60c1cecc70320feeef279707699387662906 /src
parent575a54db856947aeb4fc5cf1977844d22dfa1aab (diff)
Notify '*' pathspec correctly when diffing
I also moved all tests related to notifying in their own file.
Diffstat (limited to 'src')
-rw-r--r--src/attr_file.c24
-rw-r--r--src/attr_file.h1
-rw-r--r--src/pathspec.c25
-rw-r--r--src/pathspec.h2
4 files changed, 40 insertions, 12 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;
diff --git a/src/attr_file.h b/src/attr_file.h
index 2cc8546a2..d8abcda58 100644
--- a/src/attr_file.h
+++ b/src/attr_file.h
@@ -27,6 +27,7 @@
#define GIT_ATTR_FNMATCH_HASWILD (1U << 5)
#define GIT_ATTR_FNMATCH_ALLOWSPACE (1U << 6)
#define GIT_ATTR_FNMATCH_ICASE (1U << 7)
+#define GIT_ATTR_FNMATCH_MATCH_ALL (1U << 8)
extern const char *git_attr__true;
extern const char *git_attr__false;
diff --git a/src/pathspec.c b/src/pathspec.c
index 732180248..d4eb12582 100644
--- a/src/pathspec.c
+++ b/src/pathspec.c
@@ -38,18 +38,20 @@ char *git_pathspec_prefix(const git_strarray *pathspec)
}
/* is there anything in the spec that needs to be filtered on */
-bool git_pathspec_is_interesting(const git_strarray *pathspec)
+bool git_pathspec_is_empty(const git_strarray *pathspec)
{
- const char *str;
+ size_t i;
- if (pathspec == NULL || pathspec->count == 0)
- return false;
- if (pathspec->count > 1)
+ if (pathspec == NULL)
return true;
- str = pathspec->strings[0];
- if (!str || !str[0] || (!str[1] && (str[0] == '*' || str[0] == '.')))
- return false;
+ for (i = 0; i < pathspec->count; ++i) {
+ const char *str = pathspec->strings[i];
+
+ if (str && str[0])
+ return false;
+ }
+
return true;
}
@@ -61,7 +63,7 @@ int git_pathspec_init(
memset(vspec, 0, sizeof(*vspec));
- if (!git_pathspec_is_interesting(strspec))
+ if (git_pathspec_is_empty(strspec))
return 0;
if (git_vector_init(vspec, strspec->count, NULL) < 0)
@@ -138,7 +140,10 @@ bool git_pathspec_match_path(
}
git_vector_foreach(vspec, i, match) {
- int result = use_strcmp(match->pattern, path) ? FNM_NOMATCH : 0;
+ int result = (match->flags & GIT_ATTR_FNMATCH_MATCH_ALL) ? 0 : FNM_NOMATCH;
+
+ if (result == FNM_NOMATCH)
+ result = use_strcmp(match->pattern, path) ? FNM_NOMATCH : 0;
if (fnmatch_flags >= 0 && result == FNM_NOMATCH)
result = p_fnmatch(match->pattern, path, fnmatch_flags);
diff --git a/src/pathspec.h b/src/pathspec.h
index c44561520..43a94baad 100644
--- a/src/pathspec.h
+++ b/src/pathspec.h
@@ -16,7 +16,7 @@
extern char *git_pathspec_prefix(const git_strarray *pathspec);
/* is there anything in the spec that needs to be filtered on */
-extern bool git_pathspec_is_interesting(const git_strarray *pathspec);
+extern bool git_pathspec_is_empty(const git_strarray *pathspec);
/* build a vector of fnmatch patterns to evaluate efficiently */
extern int git_pathspec_init(