summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/dir.c b/dir.c
index 74b3bbf..0c8553b 100644
--- a/dir.c
+++ b/dir.c
@@ -19,7 +19,7 @@ static int read_directory_recursive(struct dir_struct *dir,
int check_only, const struct path_simplify *simplify);
static int get_dtype(struct dirent *de, const char *path);
-int common_prefix(const char **pathspec)
+static int common_prefix(const char **pathspec)
{
const char *path, *slash, *next;
int prefix;
@@ -52,6 +52,27 @@ int common_prefix(const char **pathspec)
return prefix;
}
+int fill_directory(struct dir_struct *dir, const char **pathspec)
+{
+ const char *path, *base;
+ int baselen;
+
+ /*
+ * Calculate common prefix for the pathspec, and
+ * use that to optimize the directory walk
+ */
+ baselen = common_prefix(pathspec);
+ path = "";
+ base = "";
+
+ if (baselen)
+ path = base = xmemdupz(*pathspec, baselen);
+
+ /* Read the directory and prune it */
+ read_directory(dir, path, base, baselen, pathspec);
+ return baselen;
+}
+
/*
* Does 'match' match the given name?
* A match is found if