diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2017-12-30 12:47:57 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-12-30 12:47:57 -0600 |
| commit | 2b7a3393beefa08656ffbd2c6725e5e52e3b8af2 (patch) | |
| tree | 0dd76605280855e437f4789296af11c1e764c484 /src | |
| parent | e14bf97ebbed574dd23dc937a05994074baad91c (diff) | |
| parent | 7a830f28d2795da60b8be534f448cb026071462f (diff) | |
| download | libgit2-2b7a3393beefa08656ffbd2c6725e5e52e3b8af2.tar.gz | |
Merge pull request #4455 from libgit2/ethomson/branch_symlinks
refs: traverse symlinked directories
Diffstat (limited to 'src')
| -rw-r--r-- | src/iterator.c | 37 | ||||
| -rw-r--r-- | src/iterator.h | 2 | ||||
| -rw-r--r-- | src/refdb_fs.c | 1 |
3 files changed, 39 insertions, 1 deletions
diff --git a/src/iterator.c b/src/iterator.c index 960031233..132b2c77c 100644 --- a/src/iterator.c +++ b/src/iterator.c @@ -23,6 +23,7 @@ #define iterator__has_been_accessed(I) iterator__flag(I,FIRST_ACCESS) #define iterator__honor_ignores(I) iterator__flag(I,HONOR_IGNORES) #define iterator__ignore_dot_git(I) iterator__flag(I,IGNORE_DOT_GIT) +#define iterator__descend_symlinks(I) iterator__flag(I,DESCEND_SYMLINKS) static void iterator_set_ignore_case(git_iterator *iter, bool ignore_case) @@ -1491,10 +1492,41 @@ static int filesystem_iterator_current( return 0; } +static int filesystem_iterator_is_dir( + bool *is_dir, + const filesystem_iterator *iter, + const filesystem_iterator_entry *entry) +{ + struct stat st; + git_buf fullpath = GIT_BUF_INIT; + int error = 0; + + if (S_ISDIR(entry->st.st_mode)) { + *is_dir = 1; + goto done; + } + + if (!iterator__descend_symlinks(iter) || !S_ISLNK(entry->st.st_mode)) { + *is_dir = 0; + goto done; + } + + if ((error = git_buf_joinpath(&fullpath, iter->root, entry->path)) < 0 || + (error = p_stat(fullpath.ptr, &st)) < 0) + goto done; + + *is_dir = S_ISDIR(st.st_mode); + +done: + git_buf_free(&fullpath); + return error; +} + static int filesystem_iterator_advance( const git_index_entry **out, git_iterator *i) { filesystem_iterator *iter = (filesystem_iterator *)i; + bool is_dir; int error = 0; iter->base.flags |= GIT_ITERATOR_FIRST_ACCESS; @@ -1519,7 +1551,10 @@ static int filesystem_iterator_advance( entry = frame->entries.contents[frame->next_idx]; frame->next_idx++; - if (S_ISDIR(entry->st.st_mode)) { + if ((error = filesystem_iterator_is_dir(&is_dir, iter, entry)) < 0) + break; + + if (is_dir) { if (iterator__do_autoexpand(iter)) { error = filesystem_iterator_frame_push(iter, entry); diff --git a/src/iterator.h b/src/iterator.h index 0bcb128d9..a6497d87b 100644 --- a/src/iterator.h +++ b/src/iterator.h @@ -39,6 +39,8 @@ typedef enum { GIT_ITERATOR_DONT_PRECOMPOSE_UNICODE = (1u << 5), /** include conflicts */ GIT_ITERATOR_INCLUDE_CONFLICTS = (1u << 6), + /** descend into symlinked directories */ + GIT_ITERATOR_DESCEND_SYMLINKS = (1u << 7), } git_iterator_flag_t; typedef enum { diff --git a/src/refdb_fs.c b/src/refdb_fs.c index ade734c6a..140879d23 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -2035,6 +2035,7 @@ int git_refdb_backend_fs( if ((!git_repository__cvar(&t, backend->repo, GIT_CVAR_FSYNCOBJECTFILES) && t) || git_repository__fsync_gitdir) backend->fsync = 1; + backend->iterator_flags |= GIT_ITERATOR_DESCEND_SYMLINKS; backend->parent.exists = &refdb_fs_backend__exists; backend->parent.lookup = &refdb_fs_backend__lookup; |
