Re: [PATCH 15/19] pathspec: add match_pathspec_depth()

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH 15/19] pathspec: add match_pathspec_depth()

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:50:14

Nguyễn Thái Ngọc Duy [off-list ref] writes:
match_pathspec_depth() is similar to match_pathspec() except that it
can take depth limit.

In long term, match_pathspec() should be removed in favor of this
function.
Hmm, this strongly suggests that match_pathspec() should take "const
struct pathspec *" which already contains the necessary information and
more, including the depth limit, no?
quoted hunk
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 dir.c |   45 +++++++++++++++++++++++++++++++++++++++++++++
 dir.h |    3 +++
 2 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/dir.c b/dir.c
index bb5076c..e12dbdd 100644
--- a/dir.c
+++ b/dir.c
@@ -169,6 +169,51 @@ int match_pathspec(const char **pathspec, const char *name, int namelen,
 	return retval;
 }
 
+int match_pathspec_depth(const char **pathspec, int max_depth,
+			 const char *name, int namelen,
+			 int prefix, char *seen)
+{
+	int i, retval = 0;
+
+	if (!pathspec) {
+		if (max_depth == -1)
+			return MATCHED_RECURSIVELY;
+
+		if (within_depth(name, namelen, 0, max_depth))
+			return MATCHED_EXACTLY;
Why the difference between _RECURSIVELY and _EXACTLY here?  If you have a
five-level deep project and give max-depth of 1000, shouldn't you get the
same result as you run the same command with unlimited depth?

Re: [PATCH 15/19] pathspec: add match_pathspec_depth()

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:50:14

2010/12/14 Junio C Hamano [off-list ref]:
Nguyễn Thái Ngọc Duy [off-list ref] writes:
quoted
match_pathspec_depth() is similar to match_pathspec() except that it
can take depth limit.

In long term, match_pathspec() should be removed in favor of this
function.
Hmm, this strongly suggests that match_pathspec() should take "const
struct pathspec *" which already contains the necessary information and
more, including the depth limit, no?
Good idea. Thanks!
quoted
+int match_pathspec_depth(const char **pathspec, int max_depth,
+                      const char *name, int namelen,
+                      int prefix, char *seen)
+{
+     int i, retval = 0;
+
+     if (!pathspec) {
+             if (max_depth == -1)
+                     return MATCHED_RECURSIVELY;
+
+             if (within_depth(name, namelen, 0, max_depth))
+                     return MATCHED_EXACTLY;
Why the difference between _RECURSIVELY and _EXACTLY here?  If you have a
five-level deep project and give max-depth of 1000, shouldn't you get the
same result as you run the same command with unlimited depth?
But if max-depth is 5 and the project is 1000-level deep, it should
return _EXACTLY, not _RECURSIVELY, right?
-- 
Duy
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help