From 719630eb4826ff7f36bc060533dbccc3c96d151c Mon Sep 17 00:00:00 2001 From: Matheus Tavares Date: Thu, 8 Apr 2021 17:41:25 -0300 Subject: pathspec: allow to ignore SKIP_WORKTREE entries on index matching Add a new enum parameter to `add_pathspec_matches_against_index()` and `find_pathspecs_matching_against_index()`, allowing callers to specify whether these function should attempt to match SKIP_WORKTREE entries or not. This will be used in a future patch to make `git add` display a warning when it is asked to update SKIP_WORKTREE entries. Signed-off-by: Matheus Tavares Signed-off-by: Junio C Hamano --- pathspec.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'pathspec.h') diff --git a/pathspec.h b/pathspec.h index 454ce364fa..0feb8e9f67 100644 --- a/pathspec.h +++ b/pathspec.h @@ -149,11 +149,17 @@ static inline int ps_strcmp(const struct pathspec_item *item, return strcmp(s1, s2); } +enum ps_skip_worktree_action { + PS_HEED_SKIP_WORKTREE = 0, + PS_IGNORE_SKIP_WORKTREE = 1 +}; void add_pathspec_matches_against_index(const struct pathspec *pathspec, const struct index_state *istate, - char *seen); + char *seen, + enum ps_skip_worktree_action sw_action); char *find_pathspecs_matching_against_index(const struct pathspec *pathspec, - const struct index_state *istate); + const struct index_state *istate, + enum ps_skip_worktree_action sw_action); int match_pathspec_attrs(const struct index_state *istate, const char *name, int namelen, const struct pathspec_item *item); -- cgit v1.2.3 From a20f70478ffcc66d30936920ebcc35ebfc12a7c7 Mon Sep 17 00:00:00 2001 From: Matheus Tavares Date: Thu, 8 Apr 2021 17:41:27 -0300 Subject: add: warn when asked to update SKIP_WORKTREE entries `git add` already refrains from updating SKIP_WORKTREE entries, but it silently exits with zero code when it is asked to do so. Instead, let's warn the user and display a hint on how to update these entries. Note that we only warn the user whey they give a pathspec item that matches no eligible path for updating, but it does match one or more SKIP_WORKTREE entries. A warning was chosen over erroring out right away to reproduce the same behavior `add` already exhibits with ignored files. This also allow users to continue their workflow without having to invoke `add` again with only the eligible paths (as those will have already been added). Signed-off-by: Matheus Tavares Signed-off-by: Junio C Hamano --- pathspec.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'pathspec.h') diff --git a/pathspec.h b/pathspec.h index 0feb8e9f67..5b4c6614bf 100644 --- a/pathspec.h +++ b/pathspec.h @@ -160,6 +160,14 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec, char *find_pathspecs_matching_against_index(const struct pathspec *pathspec, const struct index_state *istate, enum ps_skip_worktree_action sw_action); +char *find_pathspecs_matching_skip_worktree(const struct pathspec *pathspec); +static inline int matches_skip_worktree(const struct pathspec *pathspec, + int item, char **seen_ptr) +{ + if (!*seen_ptr) + *seen_ptr = find_pathspecs_matching_skip_worktree(pathspec); + return (*seen_ptr)[item]; +} int match_pathspec_attrs(const struct index_state *istate, const char *name, int namelen, const struct pathspec_item *item); -- cgit v1.2.3