diff options
author | Russell Belfer <arrbee@arrbee.com> | 2012-02-22 02:46:24 +0400 |
---|---|---|
committer | Russell Belfer <arrbee@arrbee.com> | 2012-02-22 02:46:24 +0400 |
commit | b6c93aef4276051f9c4536ecbed48f4cd093bd1b (patch) | |
tree | a15962c672890c0c8cc021dafa7d29487f81c75a /src/path.h | |
parent | 9c94a356cc61daa85e17c6342db9b3d62f788802 (diff) |
Uniform iterators for trees, index, and workdir
This create a new git_iterator type of object that provides a
uniform interface for iterating over the index, an arbitrary
tree, or the working directory of a repository.
As part of this, git ignore support was extended to support
push and pop of directory-based ignore files as the working
directory is being traversed (so the array of ignores does
not have to be recreated at each directory during traveral).
There are a number of other small utility functions in buffer,
path, vector, and fileops that are included in this patch
that made the iterator implementation cleaner.
Diffstat (limited to 'src/path.h')
-rw-r--r-- | src/path.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/path.h b/src/path.h index 0f7ebb732..7a4f1f4fd 100644 --- a/src/path.h +++ b/src/path.h @@ -9,6 +9,7 @@ #include "common.h" #include "buffer.h" +#include "vector.h" /** * Path manipulation utils @@ -129,6 +130,15 @@ extern int git_path_isdir(const char *path); extern int git_path_isfile(const char *path); /** + * Check if the parent directory contains the item. + * + * @param dir Directory to check. + * @param item Item that might be in the directory. + * @return GIT_SUCCESS if item exists in directory, <0 otherwise. + */ +extern int git_path_contains(git_buf *dir, const char *item); + +/** * Check if the given path contains the given subdirectory. * * @param parent Directory path that might contain subdir @@ -216,4 +226,26 @@ extern int git_path_walk_up( int (*fn)(void *state, git_buf *), void *state); +/** + * Load all directory entries (except '.' and '..') into a vector. + * + * For cases where `git_path_direach()` is not appropriate, this + * allows you to load the filenames in a directory into a vector + * of strings. That vector can then be sorted, iterated, or whatever. + * Remember to free alloc of the allocated strings when you are done. + * + * @param path The directory to read from. + * @param prefix_len When inserting entries, the trailing part of path + * will be prefixed after this length. I.e. given path "/a/b" and + * prefix_len 3, the entries will look like "b/e1", "b/e2", etc. + * @param alloc_extra Extra bytes to add to each string allocation in + * case you want to append anything funny. + * @param contents Vector to fill with directory entry names. + */ +extern int git_path_dirload( + const char *path, + size_t prefix_len, + size_t alloc_extra, + git_vector *contents); + #endif |