summaryrefslogtreecommitdiff
path: root/src/path.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-04-29 14:31:59 -0400
committerEdward Thomson <ethomson@microsoft.com>2015-05-01 12:31:29 -0400
commit5c387b6c5a616d245e51e4ca1935e6ffd78c710e (patch)
treee803c19fe45f9a51cadb925210689f6e70bf2b1b /src/path.c
parent7ef005f165518a9f76774c392fa2895dc1b34c96 (diff)
downloadlibgit2-5c387b6c5a616d245e51e4ca1935e6ffd78c710e.tar.gz
git_path_diriter: next shouldn't take path ptr
The _next method shouldn't take a path pointer (and a path_len pointer) as 100% of current users use the full path and ignore the filename. Plus let's add some docs and a unit test.
Diffstat (limited to 'src/path.c')
-rw-r--r--src/path.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/path.c b/src/path.c
index d8f3c234e..ee566985a 100644
--- a/src/path.c
+++ b/src/path.c
@@ -1111,10 +1111,7 @@ int git_path_diriter_init(
return 0;
}
-int git_path_diriter_next(
- const char **out,
- size_t *out_len,
- git_path_diriter *diriter)
+int git_path_diriter_next(git_path_diriter *diriter)
{
struct dirent *de;
const char *filename;
@@ -1122,10 +1119,7 @@ int git_path_diriter_next(
bool skip_dot = !(diriter->flags & GIT_PATH_DIR_INCLUDE_DOT_AND_DOTDOT);
int error = 0;
- assert(out && out_len && diriter);
-
- *out = NULL;
- *out_len = 0;
+ assert(diriter);
errno = 0;
@@ -1155,12 +1149,21 @@ int git_path_diriter_next(
if (git_buf_oom(&diriter->path))
return -1;
- *out = &diriter->path.ptr[diriter->parent_len+1];
- *out_len = filename_len;
-
return error;
}
+int git_path_diriter_filename(
+ const char **out,
+ size_t *out_len,
+ git_path_diriter *diriter)
+{
+ assert(out && out_len && diriter);
+
+ *out = &diriter->path.ptr[diriter->parent_len+1];
+ *out_len = diriter->path.size - diriter->parent_len - 1;
+ return 0;
+}
+
int git_path_diriter_fullpath(
const char **out,
size_t *out_len,
@@ -1214,7 +1217,7 @@ int git_path_dirload(
if ((error = git_path_diriter_init(&iter, path, flags)) < 0)
return error;
- while ((error = git_path_diriter_next(&name, &name_len, &iter)) == 0) {
+ while ((error = git_path_diriter_next(&iter)) == 0) {
if ((error = git_path_diriter_fullpath(&name, &name_len, &iter)) < 0)
break;