summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Doan <andy@opensourcefoundries.com>2017-10-30 11:38:33 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2017-12-29 23:53:17 +0000
commite9628e7b8d4f19a12a1cc98306c973e36c20f29c (patch)
tree5a8f30a0a23a273e9a7df38253bb59795c949fa6
parent083b1a2e2d8d190db02db3db0dad4fa742eccb02 (diff)
downloadlibgit2-e9628e7b8d4f19a12a1cc98306c973e36c20f29c.tar.gz
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>
-rw-r--r--src/iterator.c22
-rw-r--r--src/iterator.h2
-rw-r--r--src/refdb_fs.c1
3 files changed, 24 insertions, 1 deletions
diff --git a/src/iterator.c b/src/iterator.c
index 960031233..b8f2e7918 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__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);
diff --git a/src/iterator.h b/src/iterator.h
index 0bcb128d9..cde35cc62 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 when looking for references */
+ GIT_ITERATOR_INCLUDE_SYMLINK_REFSDIR = (1u << 7),
} git_iterator_flag_t;
typedef enum {
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index ade734c6a..c09b40c73 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_INCLUDE_SYMLINK_REFSDIR;
backend->parent.exists = &refdb_fs_backend__exists;
backend->parent.lookup = &refdb_fs_backend__lookup;