[PATCH 08/19] pathspec: mark wildcard pathspecs from the beginning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Nguyán ThÃi Ngác Duy <pclouds@xxxxxxxxx>
---
 prefix_len was used, but no longer. Still hesitate to remove it. It
 might get used again..

 cache.h |    4 +++-
 dir.c   |   13 +++++++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/cache.h b/cache.h
index 36819b6..3a1acf1 100644
--- a/cache.h
+++ b/cache.h
@@ -496,8 +496,10 @@ extern int ie_modified(const struct index_state *, struct cache_entry *, struct
 struct pathspec {
 	const char **raw; /* get_pathspec() result, not freed by free_pathspec() */
 	int nr;
+	int has_wildcard:1;
 	struct pathspec_item {
-		int len;
+		int len, prefix_len;
+		int has_wildcard:1;
 	} *items;
 };
 
diff --git a/dir.c b/dir.c
index 646c79f..0987d0c 100644
--- a/dir.c
+++ b/dir.c
@@ -1089,8 +1089,17 @@ int init_pathspec(struct pathspec *pathspec, const char **paths)
 	pathspec->items = xmalloc(sizeof(struct pathspec_item)*pathspec->nr);
 	for (i = 0; i < pathspec->nr; i++) {
 		struct pathspec_item *item = pathspec->items+i;
-
-		item->len = strlen(paths[i]);
+		const char *path = paths[i];
+
+		item->len = strlen(path);
+		item->has_wildcard = !no_wildcard(path);
+		if (item->has_wildcard) {
+			pathspec->has_wildcard = 1;
+			item->prefix_len = 0;
+			while (item->prefix_len < item->len &&
+			       strchr("*?[{\\", path[item->prefix_len]) == NULL)
+				item->prefix_len++;
+		}
 	}
 	return 0;
 }
-- 
1.7.3.3.476.g10a82

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]