]> Pileus Git - ~andy/git/blobdiff - dir.c
Add 'fill_directory()' helper function for directory traversal
[~andy/git] / dir.c
diff --git a/dir.c b/dir.c
index 74b3bbf6fd557943e0e7b9027556312203e58d7a..0c8553b27c80ca649fa5b8c864583fb75be6fabe 100644 (file)
--- 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