]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pathspec: allow to ignore SKIP_WORKTREE entries on index matching
authorMatheus Tavares <matheus.bernardino@usp.br>
Thu, 8 Apr 2021 20:41:25 +0000 (17:41 -0300)
committerJunio C Hamano <gitster@pobox.com>
Thu, 8 Apr 2021 21:18:03 +0000 (14:18 -0700)
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 <matheus.bernardino@usp.br>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/add.c
builtin/check-ignore.c
pathspec.c
pathspec.h

index 5fec21a7928b0895414c61a00b71cfe1b539b1b0..050cb8af303e43ff46060739f57f73b29b0ef386 100644 (file)
@@ -177,7 +177,8 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
                        *dst++ = entry;
        }
        dir->nr = dst - dir->entries;
-       add_pathspec_matches_against_index(pathspec, &the_index, seen);
+       add_pathspec_matches_against_index(pathspec, &the_index, seen,
+                                          PS_HEED_SKIP_WORKTREE);
        return seen;
 }
 
@@ -578,7 +579,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
                int i;
 
                if (!seen)
-                       seen = find_pathspecs_matching_against_index(&pathspec, &the_index);
+                       seen = find_pathspecs_matching_against_index(&pathspec,
+                                       &the_index, PS_HEED_SKIP_WORKTREE);
 
                /*
                 * file_exists() assumes exact match
index 3c652748d58c69dec4378d01de58212f65763328..0f4480a11b707b68a8a58abe8258a81628a1d1f4 100644 (file)
@@ -100,7 +100,8 @@ static int check_ignore(struct dir_struct *dir,
         * should not be ignored, in order to be consistent with
         * 'git status', 'git add' etc.
         */
-       seen = find_pathspecs_matching_against_index(&pathspec, &the_index);
+       seen = find_pathspecs_matching_against_index(&pathspec, &the_index,
+                                                    PS_HEED_SKIP_WORKTREE);
        for (i = 0; i < pathspec.nr; i++) {
                full_path = pathspec.items[i].match;
                pattern = NULL;
index 7a229d8d22f2f67a8e267fda302b53b35a13a3d4..6d502e64e583f53fdefd495cb0793e5299a201a3 100644 (file)
@@ -21,7 +21,8 @@
  */
 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)
 {
        int num_unmatched = 0, i;
 
@@ -38,6 +39,8 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
                return;
        for (i = 0; i < istate->cache_nr; i++) {
                const struct cache_entry *ce = istate->cache[i];
+               if (sw_action == PS_IGNORE_SKIP_WORKTREE && ce_skip_worktree(ce))
+                       continue;
                ce_path_match(istate, ce, pathspec, seen);
        }
 }
@@ -51,10 +54,11 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
  * given pathspecs achieves against all items in the index.
  */
 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)
 {
        char *seen = xcalloc(pathspec->nr, 1);
-       add_pathspec_matches_against_index(pathspec, istate, seen);
+       add_pathspec_matches_against_index(pathspec, istate, seen, sw_action);
        return seen;
 }
 
index 454ce364fac7767a78c3d712fb4f82c448f88f33..0feb8e9f67c19bdb58687d4cf9b31527f855b7d2 100644 (file)
@@ -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);