summaryrefslogtreecommitdiff
path: root/include/git2/pathspec.h
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-07-08 22:46:36 -0700
committerVicent Marti <tanoku@gmail.com>2013-07-10 20:50:33 +0200
commit2b672d5b646edf94ae315a9f968611ff65508c90 (patch)
tree3902904ccac637c075418e2dbfbbaabc826dd6ab /include/git2/pathspec.h
parent6fc5a58197bf04e1b5c6ca1bdb5765e90d3eb106 (diff)
downloadlibgit2-2b672d5b646edf94ae315a9f968611ff65508c90.tar.gz
Add git_pathspec_match_diff API
This adds an additional pathspec API that will match a pathspec against a diff object. This is convenient if you want to handle renames (so you need the whole diff and can't use the pathspec constraint built into the diff API) but still want to tell if the diff had any files that matched the pathspec. When the pathspec is matched against a diff, instead of keeping a list of filenames that matched, instead the API keeps the list of git_diff_deltas that matched and they can be retrieved via a new API git_pathspec_match_list_diff_entry. There are a couple of other minor API extensions here that were mostly for the sake of convenience and to reduce dependencies on knowing the internal data structure between files inside the library.
Diffstat (limited to 'include/git2/pathspec.h')
-rw-r--r--include/git2/pathspec.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/include/git2/pathspec.h b/include/git2/pathspec.h
index 6d97bb326..a835f8e52 100644
--- a/include/git2/pathspec.h
+++ b/include/git2/pathspec.h
@@ -10,6 +10,7 @@
#include "common.h"
#include "types.h"
#include "strarray.h"
+#include "diff.h"
/**
* Compiled pathspec
@@ -167,6 +168,30 @@ GIT_EXTERN(int) git_pathspec_match_tree(
git_pathspec *ps);
/**
+ * Match a pathspec against files in a diff list.
+ *
+ * This matches the pathspec against the files in the given diff list.
+ *
+ * If `out` is not NULL, this returns a `git_patchspec_match_list`. That
+ * contains the list of all matched filenames (unless you pass the
+ * `GIT_PATHSPEC_FAILURES_ONLY` flag) and may also contain the list of
+ * pathspecs with no match (if you used the `GIT_PATHSPEC_FIND_FAILURES`
+ * flag). You must call `git_pathspec_match_list_free()` on this object.
+ *
+ * @param out Output list of matches; pass NULL to just get return value
+ * @param diff A generated diff list
+ * @param flags Combination of git_pathspec_flag_t options to control match
+ * @param ps Pathspec to be matched
+ * @return 0 on success, -1 on error, GIT_ENOTFOUND if no matches and
+ * the GIT_PATHSPEC_NO_MATCH_ERROR flag is used
+ */
+GIT_EXTERN(int) git_pathspec_match_diff(
+ git_pathspec_match_list **out,
+ git_diff_list *diff,
+ uint32_t flags,
+ git_pathspec *ps);
+
+/**
* Free memory associates with a git_pathspec_match_list
*
* @param m The git_pathspec_match_list to be freed
@@ -185,6 +210,9 @@ GIT_EXTERN(size_t) git_pathspec_match_list_entrycount(
/**
* Get a matching filename by position.
*
+ * This routine cannot be used if the match list was generated by
+ * `git_pathspec_match_diff`. If so, it will always return NULL.
+ *
* @param m The git_pathspec_match_list object
* @param pos The index into the list
* @return The filename of the match
@@ -193,6 +221,19 @@ GIT_EXTERN(const char *) git_pathspec_match_list_entry(
const git_pathspec_match_list *m, size_t pos);
/**
+ * Get a matching diff delta by position.
+ *
+ * This routine can only be used if the match list was generated by
+ * `git_pathspec_match_diff`. Otherwise it will always return NULL.
+ *
+ * @param m The git_pathspec_match_list object
+ * @param pos The index into the list
+ * @return The filename of the match
+ */
+GIT_EXTERN(const git_diff_delta *) git_pathspec_match_list_diff_entry(
+ const git_pathspec_match_list *m, size_t pos);
+
+/**
* Get the number of pathspec items that did not match.
*
* This will be zero unless you passed GIT_PATHSPEC_FIND_FAILURES when