Commit e9628e7b by Andy Doan Committed by Edward Thomson

branches: Check symlinked subdirectories

 Native Git allows symlinked directories under .git/refs. This
 change allows libgit2 to also look for references that live under
 symlinked directories.

Signed-off-by: Andy Doan <andy@opensourcefoundries.com>
parent 083b1a2e
......@@ -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__symlinksdir(I) iterator__flag(I,INCLUDE_SYMLINK_REFSDIR)
static void iterator_set_ignore_case(git_iterator *iter, bool ignore_case)
......@@ -1491,6 +1492,25 @@ static int filesystem_iterator_current(
return 0;
}
static int is_directory(
const filesystem_iterator *iter, const filesystem_iterator_entry *entry)
{
int isdir = 0;
struct stat st;
git_buf fullpath;
if (S_ISDIR(entry->st.st_mode))
return 1;
if (!iterator__symlinksdir(iter) || !S_ISLNK(entry->st.st_mode))
return 0;
git_buf_init(&fullpath, 0);
git_buf_joinpath(&fullpath, iter->root, entry->path);
isdir = !p_stat(fullpath.ptr, &st) && S_ISDIR(st.st_mode);
git_buf_free(&fullpath);
return isdir;
}
static int filesystem_iterator_advance(
const git_index_entry **out, git_iterator *i)
{
......@@ -1519,7 +1539,7 @@ static int filesystem_iterator_advance(
entry = frame->entries.contents[frame->next_idx];
frame->next_idx++;
if (S_ISDIR(entry->st.st_mode)) {
if (is_directory(iter, entry)) {
if (iterator__do_autoexpand(iter)) {
error = filesystem_iterator_frame_push(iter, entry);
......
......@@ -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 when looking for references */
GIT_ITERATOR_INCLUDE_SYMLINK_REFSDIR = (1u << 7),
} git_iterator_flag_t;
typedef enum {
......
......@@ -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_INCLUDE_SYMLINK_REFSDIR;
backend->parent.exists = &refdb_fs_backend__exists;
backend->parent.lookup = &refdb_fs_backend__lookup;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment