diff options
author | Edward Thomson <ethomson@microsoft.com> | 2015-04-29 14:04:01 -0400 |
---|---|---|
committer | Edward Thomson <ethomson@microsoft.com> | 2015-05-01 12:31:26 -0400 |
commit | 7ef005f165518a9f76774c392fa2895dc1b34c96 (patch) | |
tree | fe5ecffcfef5cab943916ea467bc177d6aeb8218 /src/path.c | |
parent | ba8ef18a53b89c02df012cb80b01e195f478aada (diff) | |
download | libgit2-7ef005f165518a9f76774c392fa2895dc1b34c96.tar.gz |
git_path_dirload_with_stat: moved to fs_iterator
Diffstat (limited to 'src/path.c')
-rw-r--r-- | src/path.c | 127 |
1 files changed, 0 insertions, 127 deletions
diff --git a/src/path.c b/src/path.c index 7285acc62..d8f3c234e 100644 --- a/src/path.c +++ b/src/path.c @@ -1078,49 +1078,6 @@ int git_path_direach( return error; } -static int entry_path_alloc( - char **out, - const char *path, - size_t path_len, - const char *de_path, - size_t de_len, - size_t alloc_extra) -{ - int need_slash = (path_len > 0 && path[path_len-1] != '/') ? 1 : 0; - size_t alloc_size; - char *entry_path; - - GITERR_CHECK_ALLOC_ADD(&alloc_size, path_len, de_len); - GITERR_CHECK_ALLOC_ADD(&alloc_size, alloc_size, need_slash); - GITERR_CHECK_ALLOC_ADD(&alloc_size, alloc_size, 1); - GITERR_CHECK_ALLOC_ADD(&alloc_size, alloc_size, alloc_extra); - entry_path = git__calloc(1, alloc_size); - GITERR_CHECK_ALLOC(entry_path); - - if (path_len) - memcpy(entry_path, path, path_len); - - if (need_slash) - entry_path[path_len] = '/'; - - memcpy(&entry_path[path_len + need_slash], de_path, de_len); - - *out = entry_path; - return 0; -} - -int git_path_with_stat_cmp(const void *a, const void *b) -{ - const git_path_with_stat *psa = a, *psb = b; - return strcmp(psa->path, psb->path); -} - -int git_path_with_stat_cmp_icase(const void *a, const void *b) -{ - const git_path_with_stat *psa = a, *psb = b; - return strcasecmp(psa->path, psb->path); -} - int git_path_diriter_init( git_path_diriter *diriter, const char *path, @@ -1277,90 +1234,6 @@ int git_path_dirload( return error; } -int git_path_dirload_with_stat( - const char *dirpath, - size_t prefix_len, - unsigned int flags, - const char *start_stat, - const char *end_stat, - git_vector *contents) -{ - git_path_diriter diriter = {0}; - const char *path; - int (*strncomp)(const char *a, const char *b, size_t sz); - size_t start_len = start_stat ? strlen(start_stat) : 0; - size_t end_len = end_stat ? strlen(end_stat) : 0; - git_path_with_stat *ps; - size_t path_len, cmp_len, ps_size; - int error; - - strncomp = (flags & GIT_PATH_DIR_IGNORE_CASE) != 0 ? - git__strncasecmp : git__strncmp; - - if ((error = git_path_diriter_init(&diriter, dirpath, flags)) < 0) - goto done; - - while ((error = git_path_diriter_next(&path, &path_len, &diriter)) == 0) { - if ((error = git_path_diriter_fullpath(&path, &path_len, &diriter)) < 0) - goto done; - - assert(path_len > prefix_len); - - /* remove the prefix if requested */ - path += prefix_len; - path_len -= prefix_len; - - /* skip if before start_stat or after end_stat */ - cmp_len = min(start_len, path_len); - if (cmp_len && strncomp(path, start_stat, cmp_len) < 0) - continue; - cmp_len = min(end_len, path_len); - if (cmp_len && strncomp(path, end_stat, cmp_len) > 0) - continue; - - GITERR_CHECK_ALLOC_ADD(&ps_size, sizeof(git_path_with_stat), path_len); - GITERR_CHECK_ALLOC_ADD(&ps_size, ps_size, 2); - - ps = git__calloc(1, ps_size); - ps->path_len = path_len; - - memcpy(ps->path, path, path_len); - - if ((error = git_path_diriter_stat(&ps->st, &diriter)) < 0) { - if (error == GIT_ENOTFOUND) { - /* file was removed between readdir and lstat */ - git__free(ps); - continue; - } - - /* Treat the file as unreadable if we get any other error */ - memset(&ps->st, 0, sizeof(ps->st)); - ps->st.st_mode = GIT_FILEMODE_UNREADABLE; - - giterr_clear(); - error = 0; - } else if (S_ISDIR(ps->st.st_mode)) { - /* Suffix directory paths with a '/' */ - ps->path[ps->path_len++] = '/'; - ps->path[ps->path_len] = '\0'; - } else if(!S_ISREG(ps->st.st_mode) && !S_ISLNK(ps->st.st_mode)) { - /* Ignore wacky things in the filesystem */ - } - - git_vector_insert(contents, ps); - } - - if (error == GIT_ITEROVER) - error = 0; - - /* sort now that directory suffix is added */ - git_vector_sort(contents); - -done: - git_path_diriter_free(&diriter); - return error; -} - int git_path_from_url_or_path(git_buf *local_path_out, const char *url_or_path) { if (git_path_is_local_file_url(url_or_path)) |