]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'mt/add-rm-in-sparse-checkout'
authorJunio C Hamano <gitster@pobox.com>
Fri, 7 May 2021 03:47:39 +0000 (12:47 +0900)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 May 2021 03:47:40 +0000 (12:47 +0900)
"git add" and "git rm" learned not to touch those paths that are
outside of sparse checkout.

* mt/add-rm-in-sparse-checkout:
  rm: honor sparse checkout patterns
  add: warn when asked to update SKIP_WORKTREE entries
  refresh_index(): add flag to ignore SKIP_WORKTREE entries
  pathspec: allow to ignore SKIP_WORKTREE entries on index matching
  add: make --chmod and --renormalize honor sparse checkouts
  t3705: add tests for `git add` in sparse checkouts
  add: include magic part of pathspec on --refresh error

1  2 
builtin/add.c
builtin/rm.c
cache.h
pathspec.c
pathspec.h
read-cache.c

diff --cc builtin/add.c
Simple merge
diff --cc builtin/rm.c
index 5559a0b453a3566d85f6a550332ecd9ee8ebea88,d23a3b2164f5f7f0b9083515b95c2144e27d09cd..d89f241e97bf507816f79becbd990fae732c17b6
@@@ -293,10 -294,10 +294,12 @@@ int cmd_rm(int argc, const char **argv
  
        seen = xcalloc(pathspec.nr, 1);
  
 +      /* TODO: audit for interaction with sparse-index. */
 +      ensure_full_index(&the_index);
        for (i = 0; i < active_nr; i++) {
                const struct cache_entry *ce = active_cache[i];
+               if (ce_skip_worktree(ce))
+                       continue;
                if (!ce_path_match(&the_index, ce, &pathspec, seen))
                        continue;
                ALLOC_GROW(list.entry, list.nr + 1, list.alloc);
diff --cc cache.h
Simple merge
diff --cc pathspec.c
index 14c7e9fbe3310b8e40640fd43fc139e88c0c04e8,8247a65ec8f8188c438b13b4c978e29c469b03f8..08f8d3eedc39aa46e8bf3a4cba3220ba9b4e74ab
@@@ -20,8 -20,9 +20,9 @@@
   * to use find_pathspecs_matching_against_index() instead.
   */
  void add_pathspec_matches_against_index(const struct pathspec *pathspec,
 -                                      const struct index_state *istate,
 +                                      struct index_state *istate,
-                                       char *seen)
+                                       char *seen,
+                                       enum ps_skip_worktree_action sw_action)
  {
        int num_unmatched = 0, i;
  
                        num_unmatched++;
        if (!num_unmatched)
                return;
 +      /* TODO: audit for interaction with sparse-index. */
 +      ensure_full_index(istate);
        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);
        }
  }
   * given pathspecs achieves against all items in the index.
   */
  char *find_pathspecs_matching_against_index(const struct pathspec *pathspec,
-                                           struct index_state *istate)
 -                                          const struct index_state *istate,
++                                          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;
+ }
+ char *find_pathspecs_matching_skip_worktree(const struct pathspec *pathspec)
+ {
+       struct index_state *istate = the_repository->index;
+       char *seen = xcalloc(pathspec->nr, 1);
+       int i;
+       for (i = 0; i < istate->cache_nr; i++) {
+               struct cache_entry *ce = istate->cache[i];
+               if (ce_skip_worktree(ce))
+                   ce_path_match(istate, ce, pathspec, seen);
+       }
        return seen;
  }
  
diff --cc pathspec.h
index 2ccc8080b6cc9388d30909c1698538f9a3fc4006,5b4c6614bf6711e1bf0c1a4faa0397fea0c80a41..fceebb876f7a2f5d03fd18b6ad3d487d7c59938a
@@@ -149,12 -149,26 +149,26 @@@ static inline int ps_strcmp(const struc
                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,
 +                                      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,
-                                           struct index_state *istate);
 -                                          const struct index_state *istate,
++                                          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,
 +int match_pathspec_attrs(struct index_state *istate,
                         const char *name, int namelen,
                         const struct pathspec_item *item);
  
diff --cc read-cache.c
Simple merge