Skip to content

Commit c847dfa

Browse files
newrengitster
authored andcommitted
dir: consolidate similar code in treat_directory()
Both the DIR_SKIP_NESTED_GIT and DIR_NO_GITLINKS cases were checking for whether a path was actually a nonbare repository. That code could be shared, with just the result of how to act differing between the two cases. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 777b420 commit c847dfa

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

dir.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,8 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
14611461
const char *dirname, int len, int baselen, int exclude,
14621462
const struct pathspec *pathspec)
14631463
{
1464+
int nested_repo = 0;
1465+
14641466
/* The "len-1" is to strip the final '/' */
14651467
switch (directory_exists_in_index(istate, dirname, len-1)) {
14661468
case index_directory:
@@ -1470,15 +1472,16 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
14701472
return path_none;
14711473

14721474
case index_nonexistent:
1473-
if (dir->flags & DIR_SKIP_NESTED_GIT) {
1474-
int nested_repo;
1475+
if ((dir->flags & DIR_SKIP_NESTED_GIT) ||
1476+
!(dir->flags & DIR_NO_GITLINKS)) {
14751477
struct strbuf sb = STRBUF_INIT;
14761478
strbuf_addstr(&sb, dirname);
14771479
nested_repo = is_nonbare_repository_dir(&sb);
14781480
strbuf_release(&sb);
1479-
if (nested_repo)
1480-
return path_none;
14811481
}
1482+
if (nested_repo)
1483+
return ((dir->flags & DIR_SKIP_NESTED_GIT) ? path_none :
1484+
(exclude ? path_excluded : path_untracked));
14821485

14831486
if (dir->flags & DIR_SHOW_OTHER_DIRECTORIES)
14841487
break;
@@ -1506,13 +1509,6 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
15061509

15071510
return path_none;
15081511
}
1509-
if (!(dir->flags & DIR_NO_GITLINKS)) {
1510-
struct strbuf sb = STRBUF_INIT;
1511-
strbuf_addstr(&sb, dirname);
1512-
if (is_nonbare_repository_dir(&sb))
1513-
return exclude ? path_excluded : path_untracked;
1514-
strbuf_release(&sb);
1515-
}
15161512
return path_recurse;
15171513
}
15181514

0 commit comments

Comments
 (0)