Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2020-04-01 07:17:41 +0300
committerJunio C Hamano <gitster@pobox.com>2020-04-01 21:10:38 +0300
commit0bbd0e8b5233b7cf66b846d4c1825a530d8402bd (patch)
tree18ced603d487ea5bd71d1ef0a34b8f8d5a244aa0 /dir.c
parent2df179d3dfeb431cc3030ac44e79b136debf1fd9 (diff)
dir: refactor treat_directory to clarify control flow
The logic in treat_directory() is handled by a multi-case switch statement, but this switch is very asymmetrical, as the first two cases are simple but the third is more complicated than the rest of the method. In fact, the third case includes a "break" statement that leads to the block of code outside the switch statement. That is the only way to reach that block, as the switch handles all possible values from directory_exists_in_index(); Extract the switch statement into a series of "if" statements. This simplifies the trivial cases, while clarifying how to reach the "show_other_directories" case. This is particularly important as the "show_other_directories" case will expand in a later change. Helped-by: Elijah Newren <newren@gmail.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/dir.c b/dir.c
index 8074e651e6..d9bcb7e19b 100644
--- a/dir.c
+++ b/dir.c
@@ -1660,29 +1660,28 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
const struct pathspec *pathspec)
{
int nested_repo = 0;
-
/* The "len-1" is to strip the final '/' */
- switch (directory_exists_in_index(istate, dirname, len-1)) {
- case index_directory:
- return path_recurse;
+ enum exist_status status = directory_exists_in_index(istate, dirname, len-1);
- case index_gitdir:
+ if (status == index_directory)
+ return path_recurse;
+ if (status == index_gitdir)
return path_none;
+ if (status != index_nonexistent)
+ BUG("Unhandled value for directory_exists_in_index: %d\n", status);
- case index_nonexistent:
- if ((dir->flags & DIR_SKIP_NESTED_GIT) ||
- !(dir->flags & DIR_NO_GITLINKS)) {
- struct strbuf sb = STRBUF_INIT;
- strbuf_addstr(&sb, dirname);
- nested_repo = is_nonbare_repository_dir(&sb);
- strbuf_release(&sb);
- }
- if (nested_repo)
- return ((dir->flags & DIR_SKIP_NESTED_GIT) ? path_none :
- (excluded ? path_excluded : path_untracked));
+ if ((dir->flags & DIR_SKIP_NESTED_GIT) ||
+ !(dir->flags & DIR_NO_GITLINKS)) {
+ struct strbuf sb = STRBUF_INIT;
+ strbuf_addstr(&sb, dirname);
+ nested_repo = is_nonbare_repository_dir(&sb);
+ strbuf_release(&sb);
+ }
+ if (nested_repo)
+ return ((dir->flags & DIR_SKIP_NESTED_GIT) ? path_none :
+ (excluded ? path_excluded : path_untracked));
- if (dir->flags & DIR_SHOW_OTHER_DIRECTORIES)
- break;
+ if (!(dir->flags & DIR_SHOW_OTHER_DIRECTORIES)) {
if (excluded &&
(dir->flags & DIR_SHOW_IGNORED_TOO) &&
(dir->flags & DIR_SHOW_IGNORED_TOO_MODE_MATCHING)) {