git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 4/7] pathspec: allow to ignore SKIP_WORKTREE entries on index matching

From
Matheus Tavares <matheus.bernardino@usp.br>
Date
Feb 24, 2021, 04:05 UTC
Message-ID
<a8a8af22a03f73c572c3d45d9e7dbb0503451fa2.1614138107.git.matheus.bernardino@usp.br>
In-Reply-To
<cover.1614138107.git.matheus.bernardino@usp.br>

Add the 'ignore_skip_worktree' boolean parameter to both add_pathspec_matches_against_index() and find_pathspecs_matching_against_index(). When true, these functions will not try to match the given pathspec with SKIP_WORKTREE entries. This will be used in a future patch to make `git add` display a hint when the pathspec matches only sparse paths.

Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
---
 builtin/add.c          |  4 ++--
 builtin/check-ignore.c |  2 +-
 pathspec.c             | 10 +++++++---
 pathspec.h             |  5 +++--
 4 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/builtin/add.c b/builtin/add.c
index 5fec21a792..e15b25a623 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -177,7 +177,7 @@ 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, 0);
 	return seen;
 }
 
@@ -578,7 +578,7 @@ 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, 0);
 
 		/*
 		 * file_exists() assumes exact match
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index 3c652748d5..235b7fc905 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -100,7 +100,7 @@ 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, 0);
 	for (i = 0; i < pathspec.nr; i++) {
 		full_path = pathspec.items[i].match;
 		pattern = NULL;
diff --git a/pathspec.c b/pathspec.c
index 7a229d8d22..e5e6b7458d 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -21,7 +21,7 @@
  */
 void add_pathspec_matches_against_index(const struct pathspec *pathspec,
 					const struct index_state *istate,
-					char *seen)
+					char *seen, int ignore_skip_worktree)
 {
 	int num_unmatched = 0, i;
 
@@ -38,6 +38,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 (ignore_skip_worktree && ce_skip_worktree(ce))
+			continue;
 		ce_path_match(istate, ce, pathspec, seen);
 	}
 }
@@ -51,10 +53,12 @@ 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,
+					    int ignore_skip_worktree)
 {
 	char *seen = xcalloc(pathspec->nr, 1);
-	add_pathspec_matches_against_index(pathspec, istate, seen);
+	add_pathspec_matches_against_index(pathspec, istate, seen,
+					   ignore_skip_worktree);
 	return seen;
 }
 
diff --git a/pathspec.h b/pathspec.h
index 454ce364fa..8202882ecd 100644
--- a/pathspec.h
+++ b/pathspec.h
@@ -151,9 +151,10 @@ static inline int ps_strcmp(const struct pathspec_item *item,
 
 void add_pathspec_matches_against_index(const struct pathspec *pathspec,
 					const struct index_state *istate,
-					char *seen);
+					char *seen, int ignore_skip_worktree);
 char *find_pathspecs_matching_against_index(const struct pathspec *pathspec,
-					    const struct index_state *istate);
+					    const struct index_state *istate,
+					    int ignore_skip_worktree);
 int match_pathspec_attrs(const struct index_state *istate,
 			 const char *name, int namelen,
 			 const struct pathspec_item *item);
-- 
2.30.1
Previous: Matheus TavaresNext: Elijah Newren
Message 6 of 19 in “add/rm: honor sparse checkout and warn on sparse paths”
  1. 0/7 add/rm: honor sparse checkout and warn on sparse pathsMatheus Tavares, Feb 24, 2021
  2. 1/7 add: include magic part of pathspec on --refresh errorMatheus Tavares, Feb 24, 2021
  3. 2/7 t3705: add tests for `git add` in sparse checkoutsMatheus Tavares, Feb 24, 2021
  4. Elijah NewrenFeb 24, 2021
  5. 3/7 add: make --chmod and --renormalize honor sparse checkoutsMatheus Tavares, Feb 24, 2021
  6. 4/7 pathspec: allow to ignore SKIP_WORKTREE entries on index matchingMatheus Tavares, Feb 24, 2021
  7. Elijah NewrenFeb 24, 2021
  8. 5/7 refresh_index(): add REFRESH_DONT_MARK_SPARSE_MATCHES flagMatheus Tavares, Feb 24, 2021
  9. 6/7 add: warn when pathspec only matches SKIP_WORKTREE entriesMatheus Tavares, Feb 24, 2021
  10. Elijah NewrenFeb 24, 2021
  11. Matheus TavaresFeb 24, 2021
  12. Matheus TavaresMar 4, 2021
  13. Elijah NewrenMar 4, 2021
  14. Junio C HamanoMar 4, 2021
  15. Elijah NewrenMar 4, 2021
  16. Matheus Tavares BernardinoMar 4, 2021
  17. 7/7 rm: honor sparse checkout patternsMatheus Tavares, Feb 24, 2021
  18. Elijah NewrenFeb 24, 2021
  19. Elijah NewrenFeb 24, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.