From: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: bmalehorn@gmail.com, Elijah Newren <newren@gmail.com>,
Elijah Newren <newren@gmail.com>
Subject: [PATCH 2/4] dir, clean: avoid disallowed behavior
Date: Thu, 11 Jun 2020 06:59:31 +0000 [thread overview]
Message-ID: <d59f877dd5cb5515f6af5ac6ce308263051b926b.1591858774.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.806.git.git.1591858774.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>
dir.h documented quite clearly that DIR_SHOW_IGNORED and
DIR_SHOW_IGNORED_TOO are mutually exclusive, with a big comment to this
effect by the definition of both enum values. However, a command like
git clean -fx $DIR
would set both values for dir.flags. I _think_ it happened to work
because:
* As dir.h points out, DIR_KEEP_UNTRACKED_CONTENTS only takes effect
if DIR_SHOW_IGNORED_TOO is set.
* As coded, I believe DIR_SHOW_IGNORED would just happen to take
precedence over DIR_SHOW_IGNORED_TOO in the code as currently
constructed.
Which is a long way of saying "we just got lucky".
Fix clean.c to avoid setting these mutually exclusive values at the same
time, and add a check to dir.c that will throw a BUG() to prevent anyone
else from making this mistake.
Signed-off-by: Elijah Newren <newren@gmail.com>
---
builtin/clean.c | 2 +-
dir.c | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/builtin/clean.c b/builtin/clean.c
index 4ca12bc0c0b..3ca940f83a2 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -954,7 +954,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
remove_directories = 1;
}
- if (remove_directories)
+ if (remove_directories && !ignored_only)
dir.flags |= DIR_SHOW_IGNORED_TOO | DIR_KEEP_UNTRACKED_CONTENTS;
if (read_cache() < 0)
diff --git a/dir.c b/dir.c
index 6fb2f8ecdd7..a3ad9702d64 100644
--- a/dir.c
+++ b/dir.c
@@ -193,6 +193,10 @@ int fill_directory(struct dir_struct *dir,
const char *prefix;
size_t prefix_len;
+ unsigned exclusive_flags = DIR_SHOW_IGNORED | DIR_SHOW_IGNORED_TOO;
+ if ((dir->flags & exclusive_flags) == exclusive_flags)
+ BUG("DIR_SHOW_IGNORED and DIR_SHOW_IGNORED_TOO are exclusive");
+
/*
* Calculate common prefix for the pathspec, and
* use that to optimize the directory walk
--
gitgitgadget
next prev parent reply other threads:[~2020-06-11 6:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-11 6:59 [PATCH 0/4] Clean cleanups Elijah Newren via GitGitGadget
2020-06-11 6:59 ` [PATCH 1/4] dir: fix a few confusing comments Elijah Newren via GitGitGadget
2020-06-11 6:59 ` Elijah Newren via GitGitGadget [this message]
2020-06-11 6:59 ` [PATCH 3/4] clean: consolidate handling of ignored parameters Elijah Newren via GitGitGadget
2020-06-11 6:59 ` [PATCH 4/4] clean: optimize and document cases where we recurse into subdirectories Elijah Newren via GitGitGadget
2020-06-13 0:28 ` Junio C Hamano
2020-06-18 6:19 ` Brian Malehorn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d59f877dd5cb5515f6af5ac6ce308263051b926b.1591858774.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=bmalehorn@gmail.com \
--cc=git@vger.kernel.org \
--cc=newren@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).