archive: convert to use parse_pathspec
[gitweb.git] / dir.c
diff --git a/dir.c b/dir.c
index 048041954418315d73924b3d73c6f2c794a5edb1..19978d3d59753a810503cf6dbac9eacb0f16c474 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -11,6 +11,7 @@
 #include "dir.h"
 #include "refs.h"
 #include "wildmatch.h"
+#include "pathspec.h"
 
 struct path_simplify {
        int len;
@@ -339,8 +340,12 @@ int match_pathspec_depth(const struct pathspec *ps,
 {
        int i, retval = 0;
 
+       GUARD_PATHSPEC(ps, PATHSPEC_FROMTOP | PATHSPEC_MAXDEPTH);
+
        if (!ps->nr) {
-               if (!ps->recursive || ps->max_depth == -1)
+               if (!ps->recursive ||
+                   !(ps->magic & PATHSPEC_MAXDEPTH) ||
+                   ps->max_depth == -1)
                        return MATCHED_RECURSIVELY;
 
                if (within_depth(name, namelen, 0, ps->max_depth))
@@ -357,7 +362,9 @@ int match_pathspec_depth(const struct pathspec *ps,
                if (seen && seen[i] == MATCHED_EXACTLY)
                        continue;
                how = match_pathspec_item(ps->items+i, prefix, name, namelen);
-               if (ps->recursive && ps->max_depth != -1 &&
+               if (ps->recursive &&
+                   (ps->magic & PATHSPEC_MAXDEPTH) &&
+                   ps->max_depth != -1 &&
                    how && how != MATCHED_FNMATCH) {
                        int len = ps->items[i].len;
                        if (name[len] == '/')
@@ -380,7 +387,7 @@ int match_pathspec_depth(const struct pathspec *ps,
 /*
  * Return the length of the "simple" part of a path match limiter.
  */
-static int simple_length(const char *match)
+int simple_length(const char *match)
 {
        int len = -1;
 
@@ -392,7 +399,7 @@ static int simple_length(const char *match)
        }
 }
 
-static int no_wildcard(const char *string)
+int no_wildcard(const char *string)
 {
        return string[simple_length(string)] == '\0';
 }
@@ -1598,6 +1605,7 @@ int init_pathspec(struct pathspec *pathspec, const char **paths)
                const char *path = paths[i];
 
                item->match = path;
+               item->original = path;
                item->len = strlen(path);
                item->flags = 0;
                if (limit_pathspec_to_literal()) {