[PATCH/WIP 09/11] tree_entry_interesting: differentiate partial vs full match

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

 



Up until now, for a/b pathspec, both paths a and a/b would return
entry_interesting. Make it return entry_matched for the latter.

This way if the caller follows up to "a", but decide to stop for some
reason, then it knows that "a" has not really matched the given
pathspec yet.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 tree-walk.c |   13 ++++++++-----
 tree-walk.h |    5 +++--
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/tree-walk.c b/tree-walk.c
index 5e9c522..6e12f0f 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -616,19 +616,22 @@ enum interesting tree_entry_interesting(const struct name_entry *entry,
 					    baselen - matchlen - 1,
 					    !!S_ISDIR(entry->mode),
 					    ps->max_depth) ?
-				entry_interesting : entry_not_interesting;
+				entry_matched : entry_not_interesting;
 		}
 
 		/* Either there must be no base, or the base must match. */
 		if (baselen == 0 || !strncmp(base_str, match, baselen)) {
 			if (match_entry(entry, pathlen,
 					match + baselen, matchlen - baselen,
-					&never_interesting))
-				return entry_interesting;
+					&never_interesting)) {
+				if (match[baselen + pathlen] == '/')
+					return entry_interesting;
+				return entry_matched;
+			}
 
 			if (item->use_wildcard) {
 				if (!fnmatch(match + baselen, entry->path, 0))
-					return entry_interesting;
+					return entry_matched;
 
 				/*
 				 * Match all directories. We'll try to
@@ -654,7 +657,7 @@ match_wildcards:
 
 		if (!fnmatch(match, base->buf + base_offset, 0)) {
 			strbuf_setlen(base, base_offset + baselen);
-			return entry_interesting;
+			return entry_matched;
 		}
 		strbuf_setlen(base, base_offset + baselen);
 
diff --git a/tree-walk.h b/tree-walk.h
index 2bf0db9..a5f92fa 100644
--- a/tree-walk.h
+++ b/tree-walk.h
@@ -65,8 +65,9 @@ static inline int traverse_path_len(const struct traverse_info *info, const stru
 enum interesting {
 	all_entries_not_interesting = -1, /* no, and no subsequent entries will be either */
 	entry_not_interesting = 0,
-	entry_interesting = 1,
-	all_entries_interesting = 2 /* yes, and all subsequent entries will be */
+	entry_interesting = 1, /* a potential match, not not there yet  */
+	entry_matched = 2,
+	all_entries_interesting = 3 /* yes, and all subsequent entries will be */
 };
 
 extern enum interesting tree_entry_interesting(const struct name_entry *,
-- 
1.7.3.1.256.g2539c.dirty

--
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]