summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/checkout.c2
-rw-r--r--src/diff.c6
-rw-r--r--src/index.c3
-rw-r--r--src/pathspec.c17
-rw-r--r--src/pathspec.h12
5 files changed, 31 insertions, 9 deletions
diff --git a/src/checkout.c b/src/checkout.c
index 40f5732ed..0ce283beb 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -224,7 +224,7 @@ static int checkout_action_wd_only(
if (!git_pathspec_match_path(
pathspec, wd->path,
(data->strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH) != 0,
- git_iterator_ignore_case(workdir)))
+ git_iterator_ignore_case(workdir), NULL))
return 0;
/* check if item is tracked in the index but not in the checkout diff */
diff --git a/src/diff.c b/src/diff.c
index 4b60935f0..3e8028551 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -47,6 +47,7 @@ static int diff_delta__from_one(
const git_index_entry *entry)
{
git_diff_delta *delta;
+ const char *matched_pathspec;
if (status == GIT_DELTA_IGNORED &&
(diff->opts.flags & GIT_DIFF_INCLUDE_IGNORED) == 0)
@@ -59,7 +60,7 @@ static int diff_delta__from_one(
if (!git_pathspec_match_path(
&diff->pathspec, entry->path,
(diff->opts.flags & GIT_DIFF_DISABLE_PATHSPEC_MATCH) != 0,
- (diff->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0))
+ (diff->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0, &matched_pathspec))
return 0;
delta = diff_delta__alloc(diff, status, entry->path);
@@ -419,13 +420,14 @@ static int maybe_modified(
unsigned int omode = oitem->mode;
unsigned int nmode = nitem->mode;
bool new_is_workdir = (new_iter->type == GIT_ITERATOR_TYPE_WORKDIR);
+ const char *matched_pathspec;
GIT_UNUSED(old_iter);
if (!git_pathspec_match_path(
&diff->pathspec, oitem->path,
(diff->opts.flags & GIT_DIFF_DISABLE_PATHSPEC_MATCH) != 0,
- (diff->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0))
+ (diff->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0, &matched_pathspec))
return 0;
/* on platforms with no symlinks, preserve mode of existing symlinks */
diff --git a/src/index.c b/src/index.c
index 1e00dd3fa..f5bf954a8 100644
--- a/src/index.c
+++ b/src/index.c
@@ -1710,7 +1710,8 @@ int git_index_read_tree_match(
goto cleanup;
while (entry != NULL) {
- if (git_pathspec_match_path(&pathspec, entry->path, false, false) &&
+ if (git_pathspec_match_path(
+ &pathspec, entry->path, false, false, NULL) &&
(error = git_index_add(index, entry)) < 0)
goto cleanup;
diff --git a/src/pathspec.c b/src/pathspec.c
index 2bde3ba5f..732180248 100644
--- a/src/pathspec.c
+++ b/src/pathspec.c
@@ -106,14 +106,21 @@ void git_pathspec_free(git_vector *vspec)
/* match a path against the vectorized pathspec */
bool git_pathspec_match_path(
- git_vector *vspec, const char *path, bool disable_fnmatch, bool casefold)
+ git_vector *vspec,
+ const char *path,
+ bool disable_fnmatch,
+ bool casefold,
+ const char **matched_pathspec)
{
- unsigned int i;
+ size_t i;
git_attr_fnmatch *match;
int fnmatch_flags = 0;
int (*use_strcmp)(const char *, const char *);
int (*use_strncmp)(const char *, const char *, size_t);
+ if (matched_pathspec)
+ *matched_pathspec = NULL;
+
if (!vspec || !vspec->length)
return true;
@@ -143,8 +150,12 @@ bool git_pathspec_match_path(
path[match->length] == '/')
result = 0;
- if (result == 0)
+ if (result == 0) {
+ if (matched_pathspec)
+ *matched_pathspec = match->pattern;
+
return (match->flags & GIT_ATTR_FNMATCH_NEGATIVE) ? false : true;
+ }
}
return false;
diff --git a/src/pathspec.h b/src/pathspec.h
index dde63c7d0..c44561520 100644
--- a/src/pathspec.h
+++ b/src/pathspec.h
@@ -25,8 +25,16 @@ extern int git_pathspec_init(
/* free data from the pathspec vector */
extern void git_pathspec_free(git_vector *vspec);
-/* match a path against the vectorized pathspec */
+/*
+ * 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, const char *path, bool disable_fnmatch, bool casefold);
+ git_vector *vspec,
+ const char *path,
+ bool disable_fnmatch,
+ bool casefold,
+ const char **matched_pathspec);
#endif