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

[PATCH v2 17/21] Convert refresh_index to take struct pathspec

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jan 11, 2013, 11:21 UTC
Message-ID
<1357903275-16804-18-git-send-email-pclouds@gmail.com>
In-Reply-To
<1357903275-16804-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/add.c    | 14 ++++++--------
 builtin/commit.c |  2 +-
 builtin/rm.c     |  2 +-
 cache.h          |  2 +-
 read-cache.c     |  5 +++--
 5 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/builtin/add.c b/builtin/add.c
index c8592fe..4e2b603 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -153,19 +153,17 @@ static char *prune_directory(struct dir_struct *dir, const char **pathspec, int
 	return seen;
 }
 
-static void refresh(int verbose, const char **pathspec)
+static void refresh(int verbose, const struct pathspec *pathspec)
 {
 	char *seen;
-	int i, specs;
+	int i;
 
-	for (specs = 0; pathspec[specs];  specs++)
-		/* nothing */;
-	seen = xcalloc(specs, 1);
+	seen = xcalloc(pathspec->nr, 1);
 	refresh_index(&the_index, verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET,
 		      pathspec, seen, _("Unstaged changes after refreshing the index:"));
-	for (i = 0; i < specs; i++) {
+	for (i = 0; i < pathspec->nr; i++) {
 		if (!seen[i])
-			die(_("pathspec '%s' did not match any files"), pathspec[i]);
+			die(_("pathspec '%s' did not match any files"), pathspec->raw[i]);
 	}
         free(seen);
 }
@@ -410,7 +408,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 	}
 
 	if (refresh_only) {
-		refresh(verbose, pathspec.raw);
+		refresh(verbose, &pathspec);
 		goto finish;
 	}
 
diff --git a/builtin/commit.c b/builtin/commit.c
index 8777c19..2fe6054 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1208,7 +1208,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 		       prefix, argv);
 
 	read_cache_preload(&s.pathspec);
-	refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, s.pathspec.raw, NULL, NULL);
+	refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
 
 	fd = hold_locked_index(&index_lock, 0);
 	if (0 <= fd)
diff --git a/builtin/rm.c b/builtin/rm.c
index d719d95..b5edde8 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -250,7 +250,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
 	}
 
 	parse_pathspec(&pathspec, PATHSPEC_FROMTOP, 0, prefix, argv);
-	refresh_index(&the_index, REFRESH_QUIET, pathspec.raw, NULL, NULL);
+	refresh_index(&the_index, REFRESH_QUIET, &pathspec, NULL, NULL);
 
 	seen = NULL;
 	seen = xcalloc(pathspec.nr, 1);
diff --git a/cache.h b/cache.h
index 40eaa04..32298ba 100644
--- a/cache.h
+++ b/cache.h
@@ -515,7 +515,7 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
 #define REFRESH_IGNORE_MISSING	0x0008	/* ignore non-existent */
 #define REFRESH_IGNORE_SUBMODULES	0x0010	/* ignore submodules */
 #define REFRESH_IN_PORCELAIN	0x0020	/* user friendly output, not "needs update" */
-extern int refresh_index(struct index_state *, unsigned int flags, const char **pathspec, char *seen, const char *header_msg);
+extern int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);
 
 struct lock_file {
 	struct lock_file *next;
diff --git a/read-cache.c b/read-cache.c
index fda78bc..dec2ba6 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1093,7 +1093,8 @@ static void show_file(const char * fmt, const char * name, int in_porcelain,
 	printf(fmt, name);
 }
 
-int refresh_index(struct index_state *istate, unsigned int flags, const char **pathspec,
+int refresh_index(struct index_state *istate, unsigned int flags,
+		  const struct pathspec *pathspec,
 		  char *seen, const char *header_msg)
 {
 	int i;
@@ -1128,7 +1129,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
 			continue;
 
 		if (pathspec &&
-		    !match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen))
+		    !match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, seen))
 			filtered = 1;
 
 		if (ce_stage(ce)) {
-- 
1.8.0.rc2.23.g1fb49df
Previous: Nguyễn Thái Ngọc DuyNext: Nguyen Thai Ngoc Duy
Message 21 of 27 in “nd/parse-pathspec reroll”
  1. 00/21 nd/parse-pathspec rerollNguyễn Thái Ngọc Duy, Jan 11, 2013
  2. 01/21 pathspec: save the non-wildcard length partNguyễn Thái Ngọc Duy, Jan 11, 2013
  3. 02/21 Add parse_pathspec() that converts cmdline args to struct pathspecNguyễn Thái Ngọc Duy, Jan 11, 2013
  4. 03/21 Export parse_pathspec() and convert some get_pathspec() callsNguyễn Thái Ngọc Duy, Jan 11, 2013
  5. Matt KraaiJan 11, 2013
  6. Duy NguyenJan 12, 2013
  7. 04/21 clean: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 11, 2013
  8. 05/21 commit: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 11, 2013
  9. Martin von ZweigbergkJan 12, 2013
  10. 06/21 status: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 11, 2013
  11. 07/21 rerere: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 11, 2013
  12. 08/21 checkout: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 11, 2013
  13. 09/21 rm: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 11, 2013
  14. 10/21 ls-files: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 11, 2013
  15. 11/21 archive: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 11, 2013
  16. 12/21 add: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 11, 2013
  17. 13/21 Convert read_cache_preload() to take struct pathspecNguyễn Thái Ngọc Duy, Jan 11, 2013
  18. 14/21 Convert unmerge_cache to take struct pathspecNguyễn Thái Ngọc Duy, Jan 11, 2013
  19. 15/21 checkout: convert read_tree_some to take struct pathspecNguyễn Thái Ngọc Duy, Jan 11, 2013
  20. 16/21 Convert report_path_error to take struct pathspecNguyễn Thái Ngọc Duy, Jan 11, 2013
  21. 17/21 Convert refresh_index to take struct pathspecNguyễn Thái Ngọc Duy, Jan 11, 2013
  22. Nguyen Thai Ngoc DuyJan 11, 2013
  23. 18/21 Convert {read,fill}_directory to take struct pathspecNguyễn Thái Ngọc Duy, Jan 11, 2013
  24. 19/21 Convert add_files_to_cache to take struct pathspecNguyễn Thái Ngọc Duy, Jan 11, 2013
  25. 20/21 Convert more init_pathspec() to parse_pathspec()Nguyễn Thái Ngọc Duy, Jan 11, 2013
  26. 21/21 Rename field "raw" to "_raw" in struct pathspecNguyễn Thái Ngọc Duy, Jan 11, 2013
  27. 22/21 Convert the last use of match_pathspec() and remove itNguyễn Thái Ngọc Duy, Jan 11, 2013

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.