[PATCH 15/21] Convert ce_path_match() to use struct pathspec

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?=
Date: Friday, December 17, 2010 - 5:43 am

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 The old 14/21. Slightly changed because of rev_info->pathspec change.

 builtin/update-index.c |    8 ++++++--
 cache.h                |    2 +-
 diff-lib.c             |    4 ++--
 preload-index.c        |    5 ++++-
 read-cache.c           |    7 ++++---
 revision.c             |    2 +-
 wt-status.c            |    5 ++++-
 7 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/builtin/update-index.c b/builtin/update-index.c
index 3ab214d..9d1f67e 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -543,7 +543,10 @@ static int do_reupdate(int ac, const char **av,
 	 */
 	int pos;
 	int has_head = 1;
-	const char **pathspec = get_pathspec(prefix, av + 1);
+	const char **paths = get_pathspec(prefix, av + 1);
+	struct pathspec pathspec;
+
+	init_pathspec(&pathspec, paths);
 
 	if (read_ref("HEAD", head_sha1))
 		/* If there is no HEAD, that means it is an initial
@@ -556,7 +559,7 @@ static int do_reupdate(int ac, const char **av,
 		struct cache_entry *old = NULL;
 		int save_nr;
 
-		if (ce_stage(ce) || !ce_path_match(ce, pathspec))
+		if (ce_stage(ce) || !ce_path_match(ce, &pathspec))
 			continue;
 		if (has_head)
 			old = read_one_ent(NULL, head_sha1,
@@ -575,6 +578,7 @@ static int do_reupdate(int ac, const char **av,
 		if (save_nr != active_nr)
 			goto redo;
 	}
+	free_pathspec(&pathspec);
 	return 0;
 }
 
diff --git a/cache.h b/cache.h
index dc0bfb4..b5cd61c 100644
--- a/cache.h
+++ b/cache.h
@@ -508,7 +508,7 @@ struct pathspec {
 
 extern int init_pathspec(struct pathspec *, const char **);
 extern void free_pathspec(struct pathspec *);
-extern int ce_path_match(const struct cache_entry *ce, const char **pathspec);
+extern int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec);
 extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path);
 extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object);
 extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
diff --git a/diff-lib.c b/diff-lib.c
index 2251f3d..1e22992 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -106,7 +106,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 			DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
 			break;
 
-		if (!ce_path_match(ce, revs->prune_data.raw))
+		if (!ce_path_match(ce, &revs->prune_data))
 			continue;
 
 		if (ce_stage(ce)) {
@@ -427,7 +427,7 @@ static int oneway_diff(struct cache_entry **src, struct unpack_trees_options *o)
 	if (tree == o->df_conflict_entry)
 		tree = NULL;
 
-	if (ce_path_match(idx ? idx : tree, revs->prune_data.raw))
+	if (ce_path_match(idx ? idx : tree, &revs->prune_data))
 		do_oneway_diff(o, idx, tree);
 
 	return 0;
diff --git a/preload-index.c b/preload-index.c
index e3d0bda..49cb08d 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -35,7 +35,9 @@ static void *preload_thread(void *_data)
 	struct index_state *index = p->index;
 	struct cache_entry **cep = index->cache + p->offset;
 	struct cache_def cache;
+	struct pathspec pathspec;
 
+	init_pathspec(&pathspec, p->pathspec);
 	memset(&cache, 0, sizeof(cache));
 	nr = p->nr;
 	if (nr + p->offset > index->cache_nr)
@@ -51,7 +53,7 @@ static void *preload_thread(void *_data)
 			continue;
 		if (ce_uptodate(ce))
 			continue;
-		if (!ce_path_match(ce, p->pathspec))
+		if (!ce_path_match(ce, &pathspec))
 			continue;
 		if (threaded_has_symlink_leading_path(&cache, ce->name, ce_namelen(ce)))
 			continue;
@@ -61,6 +63,7 @@ static void *preload_thread(void *_data)
 			continue;
 		ce_mark_uptodate(ce);
 	} while (--nr > 0);
+	free_pathspec(&pathspec);
 	return NULL;
 }
 
diff --git a/read-cache.c b/read-cache.c
index 1f42473..f1141a3 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -683,17 +683,18 @@ int ce_same_name(struct cache_entry *a, struct cache_entry *b)
 	return ce_namelen(b) == len && !memcmp(a->name, b->name, len);
 }
 
-int ce_path_match(const struct cache_entry *ce, const char **pathspec)
+int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec)
 {
 	const char *match, *name;
+	const char **ps = pathspec->raw;
 	int len;
 
-	if (!pathspec)
+	if (!pathspec->nr)
 		return 1;
 
 	len = ce_namelen(ce);
 	name = ce->name;
-	while ((match = *pathspec++) != NULL) {
+	while ((match = *ps++) != NULL) {
 		int matchlen = strlen(match);
 		if (matchlen > len)
 			continue;
diff --git a/revision.c b/revision.c
index 515e2dd..a0d3816 100644
--- a/revision.c
+++ b/revision.c
@@ -969,7 +969,7 @@ static void prepare_show_merge(struct rev_info *revs)
 		struct cache_entry *ce = active_cache[i];
 		if (!ce_stage(ce))
 			continue;
-		if (ce_path_match(ce, revs->prune_data.raw)) {
+		if (ce_path_match(ce, &revs->prune_data)) {
 			prune_num++;
 			prune = xrealloc(prune, sizeof(*prune) * prune_num);
 			prune[prune_num-2] = ce->name;
diff --git a/wt-status.c b/wt-status.c
index 5c6b118..457d265 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -350,14 +350,16 @@ static void wt_status_collect_changes_index(struct wt_status *s)
 
 static void wt_status_collect_changes_initial(struct wt_status *s)
 {
+	struct pathspec pathspec;
 	int i;
 
+	init_pathspec(&pathspec, s->pathspec);
 	for (i = 0; i < active_nr; i++) {
 		struct string_list_item *it;
 		struct wt_status_change_data *d;
 		struct cache_entry *ce = active_cache[i];
 
-		if (!ce_path_match(ce, s->pathspec))
+		if (!ce_path_match(ce, &pathspec))
 			continue;
 		it = string_list_insert(&s->change, ce->name);
 		d = it->util;
@@ -372,6 +374,7 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
 		else
 			d->index_status = DIFF_STATUS_ADDED;
 	}
+	free_pathspec(&pathspec);
 }
 
 static void wt_status_collect_untracked(struct wt_status *s)
-- 
1.7.3.3.476.g10a82

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/21] nd/struct-pathspec v2, =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 01/21] Add struct pathspec, =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 02/21] diff-no-index: use diff_tree_setup_paths(), =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 03/21] Convert struct diff_options to use struct pa ..., =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 04/21] tree_entry_interesting(): remove dependency ..., =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 05/21] Move tree_entry_interesting() to tree-walk.c ..., =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 06/21] glossary: define pathspec, =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 07/21] diff-tree: convert base+baselen to writable ..., =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 08/21] tree_entry_interesting(): refactor into sepa ..., =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 09/21] tree_entry_interesting(): support depth limit, =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 10/21] tree_entry_interesting(): fix depth limit wi ..., =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 11/21] tree_entry_interesting(): support wildcard m ..., =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 12/21] tree_entry_interesting(): optimize wildcard ..., =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 13/21] pathspec: add match_pathspec_depth(), =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 14/21] Convert ce_path_match() to use struct pathspec, =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 15/21] Convert ce_path_match() to use match_pathspe ..., =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 16/21] grep: convert to use struct pathspec, =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 17/21] grep: use match_pathspec_depth() for cache/w ..., =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 18/21] strbuf: allow &quot;buf&quot; to point to the middle o ..., =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 19/21] grep: use writable strbuf from caller in gre ..., =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 20/21] grep: drop pathspec_matches() in favor of tr ..., =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
[PATCH 21/21] t7810: overlapping pathspecs and depth limit, =?UTF-8?q?Nguy=E1=BB ..., (Wed Dec 15, 8:02 am)
Re: [PATCH 19/21] grep: use writable strbuf from caller in ..., Nguyen Thai Ngoc Duy, (Fri Dec 17, 2:56 am)
Re: [PATCH 14/21] Convert ce_path_match() to use struct pa ..., Nguyen Thai Ngoc Duy, (Fri Dec 17, 2:59 am)
Re: [PATCH 10/21] tree_entry_interesting(): fix depth limi ..., Nguyen Thai Ngoc Duy, (Fri Dec 17, 3:05 am)
[PATCH 14/21] struct rev_info: convert prune_data to struc ..., =?UTF-8?q?Nguy=E1=BB ..., (Fri Dec 17, 5:43 am)
[PATCH 15/21] Convert ce_path_match() to use struct pathspec, =?UTF-8?q?Nguy=E1=BB ..., (Fri Dec 17, 5:43 am)
[PATCH 19/21] grep: use writable strbuf from caller for gr ..., =?UTF-8?q?Nguy=E1=BB ..., (Fri Dec 17, 5:44 am)
[PATCH 20/21] grep: drop pathspec_matches() in favor of tr ..., =?UTF-8?q?Nguy=E1=BB ..., (Fri Dec 17, 5:45 am)
Re: [PATCH 14/21] Convert ce_path_match() to use struct pa ..., Nguyen Thai Ngoc Duy, (Fri Dec 17, 8:11 am)
Re: [PATCH 10/21] tree_entry_interesting(): fix depth limi ..., Nguyen Thai Ngoc Duy, (Fri Dec 17, 8:37 pm)