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-06-25 10:16:06 +0400
committerVicent Marti <tanoku@gmail.com>2013-07-10 22:50:31 +0400
commitd2ce27dd494b65f54b2d110b4defd69aea976115 (patch)
tree5e81ac8f401fd5a15f73409a6c74142a0ee5e4ca /src/pathspec.h
parentd39fff36484e908438beb17ee043689962182460 (diff)
Add public API for pathspec matching
This adds a new public API for compiling pathspecs and matching them against the working directory, the index, or a tree from the repository. This also reworks the pathspec internals to allow the sharing of code between the existing internal usage of pathspec matching and the new external API. While this is working and the new API is ready for discussion, I think there is still an incorrect behavior in which patterns are always matched against the full path of an entry without taking the subdirectories into account (so "s*" will match "subdir/file" even though it wouldn't with core Git). Further enhancements are coming, but this was a good place to take a functional snapshot.
Diffstat (limited to 'src/pathspec.h')
-rw-r--r--src/pathspec.h43
1 files changed, 28 insertions, 15 deletions
diff --git a/src/pathspec.h b/src/pathspec.h
index f6509df4c..e7edfea38 100644
--- a/src/pathspec.h
+++ b/src/pathspec.h
@@ -8,9 +8,27 @@
#define INCLUDE_pathspec_h__
#include "common.h"
+#include <git2/pathspec.h>
#include "buffer.h"
#include "vector.h"
#include "pool.h"
+#include "array.h"
+
+/* public compiled pathspec */
+struct git_pathspec {
+ git_refcount rc;
+ char *prefix;
+ git_vector pathspec;
+ git_pool pool;
+};
+
+/* public interface to pathspec matching */
+struct git_pathspec_match_list {
+ git_pathspec *pathspec;
+ git_array_t(char *) matches;
+ git_array_t(char *) failures;
+ git_pool pool;
+};
/* what is the common non-wildcard prefix for all items in the pathspec */
extern char *git_pathspec_prefix(const git_strarray *pathspec);
@@ -19,36 +37,31 @@ extern char *git_pathspec_prefix(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(
+extern int git_pathspec__vinit(
git_vector *vspec, const git_strarray *strspec, git_pool *strpool);
/* free data from the pathspec vector */
-extern void git_pathspec_free(git_vector *vspec);
+extern void git_pathspec__vfree(git_vector *vspec);
+
+#define GIT_PATHSPEC_NOMATCH ((size_t)-1)
/*
* Match a path against the vectorized pathspec.
* The matched pathspec is passed back into the `matched_pathspec` parameter,
* unless it is passed as NULL by the caller.
*/
-extern bool git_pathspec_match_path(
- git_vector *vspec,
+extern bool git_pathspec__match(
+ const git_vector *vspec,
const char *path,
bool disable_fnmatch,
bool casefold,
- const char **matched_pathspec);
+ const char **matched_pathspec,
+ size_t *matched_at);
/* easy pathspec setup */
-typedef struct {
- char *prefix;
- git_vector pathspec;
- git_pool pool;
-} git_pathspec_context;
-
-extern int git_pathspec_context_init(
- git_pathspec_context *ctxt, const git_strarray *paths);
+extern int git_pathspec__init(git_pathspec *ps, const git_strarray *paths);
-extern void git_pathspec_context_free(
- git_pathspec_context *ctxt);
+extern void git_pathspec__clear(git_pathspec *ps);
#endif