diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-05-14 13:22:36 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-07-09 01:11:26 -0700 |
commit | 1d8842d921cc2695f155f4a10904eeffad085c77 (patch) | |
tree | 87186d8b5c8116ec5b442c6f401c2c3a6729de53 /dir.c | |
parent | completion: __git_config_get_set_variables() handle values with spaces (diff) | |
download | tgif-1d8842d921cc2695f155f4a10904eeffad085c77.tar.xz |
Add 'fill_directory()' helper function for directory traversal
Most of the users of "read_directory()" actually want a much simpler
interface than the whole complex (but rather powerful) one.
In fact 'git add' had already largely abstracted out the core interface
issues into a private "fill_directory()" function that was largely
applicable almost as-is to a number of callers. Yes, 'git add' wants to
do some extra work of its own, specific to the add semantics, but we can
easily split that out, and use the core as a generic function.
This function does exactly that, and now that much simplified
'fill_directory()' function can be shared with a number of callers,
while also ensuring that the rather more complex calling conventions of
read_directory() are used by fewer call-sites.
This also makes the 'common_prefix()' helper function private to dir.c,
since all callers are now in that file.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'dir.c')
-rw-r--r-- | dir.c | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -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 |