diff options
author | Russell Belfer <arrbee@arrbee.com> | 2012-02-22 15:15:35 -0800 |
---|---|---|
committer | Russell Belfer <arrbee@arrbee.com> | 2012-02-22 15:15:35 -0800 |
commit | 0534641dfec001794ae9a83cfd1cfc7acaef97b7 (patch) | |
tree | d17e72af0ae9a9435aef29cc388d50a67a3cc0b0 /src/path.c | |
parent | da337c806468d2d8a27dfa9ee5e75e476f5ad546 (diff) | |
download | libgit2-0534641dfec001794ae9a83cfd1cfc7acaef97b7.tar.gz |
Fix iterators based on pull request feedback
This update addresses all of the feedback in pull request #570.
The biggest change was to create actual linked list stacks for
storing the tree and workdir iterator state. This cleaned up
the code a ton. Additionally, all of the static functions had
their 'git_' prefix removed, and a lot of other unnecessary
changes were removed from the original patch.
Diffstat (limited to 'src/path.c')
-rw-r--r-- | src/path.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/path.c b/src/path.c index 6f46dc95e..88ea95a97 100644 --- a/src/path.c +++ b/src/path.c @@ -398,42 +398,38 @@ int git_path_isfile(const char *path) static int _check_dir_contents( git_buf *dir, const char *sub, - int append_on_success, int (*predicate)(const char *)) { int error = GIT_SUCCESS; size_t dir_size = dir->size; size_t sub_size = strlen(sub); - /* leave base valid even if we could not make space for subdir */ + /* separate allocation and join, so we can always leave git_buf valid */ if ((error = git_buf_try_grow(dir, dir_size + sub_size + 2)) < GIT_SUCCESS) return error; - - /* save excursion */ git_buf_joinpath(dir, dir->ptr, sub); error = (*predicate)(dir->ptr); - /* restore excursion */ - if (!append_on_success || error != GIT_SUCCESS) - git_buf_truncate(dir, dir_size); + /* restore path */ + git_buf_truncate(dir, dir_size); return error; } int git_path_contains(git_buf *dir, const char *item) { - return _check_dir_contents(dir, item, 0, &git_path_exists); + return _check_dir_contents(dir, item, &git_path_exists); } -int git_path_contains_dir(git_buf *base, const char *subdir, int append_if_exists) +int git_path_contains_dir(git_buf *base, const char *subdir) { - return _check_dir_contents(base, subdir, append_if_exists, &git_path_isdir); + return _check_dir_contents(base, subdir, &git_path_isdir); } -int git_path_contains_file(git_buf *base, const char *file, int append_if_exists) +int git_path_contains_file(git_buf *base, const char *file) { - return _check_dir_contents(base, file, append_if_exists, &git_path_isfile); + return _check_dir_contents(base, file, &git_path_isfile); } int git_path_find_dir(git_buf *dir, const char *path, const char *base) |