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 <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Dec 19, 2019 at 21:28 UTC
c847dfafeee8b0fe3e053ac307de88e04d1ad072
1 file changed
+7
-11
dir.c
+7
-11
@@ -1461,6 +1461,8 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
1461
const char *dirname, int len, int baselen, int exclude,
1462
const struct pathspec *pathspec)
1463
{
1464
+ int nested_repo = 0;
1465
+
1466
/* The "len-1" is to strip the final '/' */
1467
switch (directory_exists_in_index(istate, dirname, len-1)) {
1468
case index_directory:
@@ -1470,15 +1472,16 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
1472
return path_none;
1473
1474
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)) {
1477
struct strbuf sb = STRBUF_INIT;
1478
strbuf_addstr(&sb, dirname);
1479
nested_repo = is_nonbare_repository_dir(&sb);
1480
strbuf_release(&sb);
1479
- if (nested_repo)
1480
- return path_none;
1481
}
1482
+ if (nested_repo)
1483
+ return ((dir->flags & DIR_SKIP_NESTED_GIT) ? path_none :
1484
+ (exclude ? path_excluded : path_untracked));
1485
1486
if (dir->flags & DIR_SHOW_OTHER_DIRECTORIES)
1487
break;
@@ -1506,13 +1509,6 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
1509
1510
return path_none;
1511
}
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
- }
1512
return path_recurse;
1513
}
1514