The excluded function uses a new helper function called
exclude_from_list_1() to perform the inner loop over all of the
exclude patterns.  The helper just tells us whether the path is
included, excluded, or undecided.

However, it may be useful to know _which_ pattern was
triggered.  So let's pass out the entire exclude match,
which contains the status information we were already
passing out.

Further patches can make use of this.

This is a modified forward port of a patch from 2009 by Jeff King:
http://article.gmane.org/gmane.comp.version-control.git/108815

Signed-off-by: Adam Spiers <g...@adamspiers.org>
---
 dir.c | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/dir.c b/dir.c
index 57a5d11..3a532d5 100644
--- a/dir.c
+++ b/dir.c
@@ -509,22 +509,24 @@ static void prep_exclude(struct dir_struct *dir, const 
char *base, int baselen)
        dir->basebuf[baselen] = '\0';
 }
 
-/* Scan the list and let the last match determine the fate.
- * Return 1 for exclude, 0 for include and -1 for undecided.
+/*
+ * Scan the given exclude list in reverse to see whether pathname
+ * should be ignored.  The first match (i.e. the last on the list), if
+ * any, determines the fate.  Returns the exclude_list element which
+ * matched, or NULL for undecided.
  */
-int excluded_from_list(const char *pathname,
-                      int pathlen, const char *basename, int *dtype,
-                      struct exclude_list *el)
+struct exclude *excluded_from_list_1(const char *pathname, int pathlen,
+                                    const char *basename, int *dtype,
+                                    struct exclude_list *el)
 {
        int i;
 
        if (!el->nr)
-               return -1;      /* undefined */
+               return NULL;    /* undefined */
 
        for (i = el->nr - 1; 0 <= i; i--) {
                struct exclude *x = el->excludes[i];
                const char *name, *exclude = x->pattern;
-               int to_exclude = x->to_exclude;
                int namelen, prefix = x->nowildcardlen;
 
                if (x->flags & EXC_FLAG_MUSTBEDIR) {
@@ -538,14 +540,14 @@ int excluded_from_list(const char *pathname,
                        /* match basename */
                        if (prefix == x->patternlen) {
                                if (!strcmp_icase(exclude, basename))
-                                       return to_exclude;
+                                       return x;
                        } else if (x->flags & EXC_FLAG_ENDSWITH) {
                                if (x->patternlen - 1 <= pathlen &&
                                    !strcmp_icase(exclude + 1, pathname + 
pathlen - x->patternlen + 1))
-                                       return to_exclude;
+                                       return x;
                        } else {
                                if (fnmatch_icase(exclude, basename, 0) == 0)
-                                       return to_exclude;
+                                       return x;
                        }
                        continue;
                }
@@ -580,7 +582,23 @@ int excluded_from_list(const char *pathname,
                }
 
                if (!namelen || !fnmatch_icase(exclude, name, FNM_PATHNAME))
-                       return to_exclude;
+                       return x;
+       }
+       return NULL; /* undecided */
+}
+
+/*
+ * Scan the list and let the last match determine the fate.
+ * Return 1 for exclude, 0 for include and -1 for undecided.
+ */
+int excluded_from_list(const char *pathname,
+                      int pathlen, const char *basename, int *dtype,
+                      struct exclude_list *el)
+{
+       struct exclude *exclude;
+       exclude = excluded_from_list_1(pathname, pathlen, basename, dtype, el);
+       if (exclude) {
+               return exclude->to_exclude;
        }
        return -1; /* undecided */
 }
-- 
1.7.12.155.ge5750d5.dirty

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

Reply via email to