Skip to content

Commit e9628e7

Browse files
Andy Doanethomson
authored andcommitted
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>
1 parent 083b1a2 commit e9628e7

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/iterator.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define iterator__has_been_accessed(I) iterator__flag(I,FIRST_ACCESS)
2424
#define iterator__honor_ignores(I) iterator__flag(I,HONOR_IGNORES)
2525
#define iterator__ignore_dot_git(I) iterator__flag(I,IGNORE_DOT_GIT)
26+
#define iterator__symlinksdir(I) iterator__flag(I,INCLUDE_SYMLINK_REFSDIR)
2627

2728

2829
static void iterator_set_ignore_case(git_iterator *iter, bool ignore_case)
@@ -1491,6 +1492,25 @@ static int filesystem_iterator_current(
14911492
return 0;
14921493
}
14931494

1495+
static int is_directory(
1496+
const filesystem_iterator *iter, const filesystem_iterator_entry *entry)
1497+
{
1498+
int isdir = 0;
1499+
struct stat st;
1500+
git_buf fullpath;
1501+
1502+
if (S_ISDIR(entry->st.st_mode))
1503+
return 1;
1504+
if (!iterator__symlinksdir(iter) || !S_ISLNK(entry->st.st_mode))
1505+
return 0;
1506+
1507+
git_buf_init(&fullpath, 0);
1508+
git_buf_joinpath(&fullpath, iter->root, entry->path);
1509+
isdir = !p_stat(fullpath.ptr, &st) && S_ISDIR(st.st_mode);
1510+
git_buf_free(&fullpath);
1511+
return isdir;
1512+
}
1513+
14941514
static int filesystem_iterator_advance(
14951515
const git_index_entry **out, git_iterator *i)
14961516
{
@@ -1519,7 +1539,7 @@ static int filesystem_iterator_advance(
15191539
entry = frame->entries.contents[frame->next_idx];
15201540
frame->next_idx++;
15211541

1522-
if (S_ISDIR(entry->st.st_mode)) {
1542+
if (is_directory(iter, entry)) {
15231543
if (iterator__do_autoexpand(iter)) {
15241544
error = filesystem_iterator_frame_push(iter, entry);
15251545

src/iterator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ typedef enum {
3939
GIT_ITERATOR_DONT_PRECOMPOSE_UNICODE = (1u << 5),
4040
/** include conflicts */
4141
GIT_ITERATOR_INCLUDE_CONFLICTS = (1u << 6),
42+
/** descend into symlinked directories when looking for references */
43+
GIT_ITERATOR_INCLUDE_SYMLINK_REFSDIR = (1u << 7),
4244
} git_iterator_flag_t;
4345

4446
typedef enum {

src/refdb_fs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,7 @@ int git_refdb_backend_fs(
20352035
if ((!git_repository__cvar(&t, backend->repo, GIT_CVAR_FSYNCOBJECTFILES) && t) ||
20362036
git_repository__fsync_gitdir)
20372037
backend->fsync = 1;
2038+
backend->iterator_flags |= GIT_ITERATOR_INCLUDE_SYMLINK_REFSDIR;
20382039

20392040
backend->parent.exists = &refdb_fs_backend__exists;
20402041
backend->parent.lookup = &refdb_fs_backend__lookup;

0 commit comments

Comments
 (0)