git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/4] clean: consolidate handling of ignored parameters

From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Date
Jun 11, 2020, 06:59 UTC
Message-ID
<e6c700b3b4fa064c6a78e6d3ab262cf105b0e1e4.1591858774.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.806.git.git.1591858774.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>

I spent a long time trying to figure out how and whether the code worked with different values of ignore, ignore_only, and remove_directories. After lots of time setting up lots of testcases, sifting through lots of print statements, and walking through the debugger, I finally realized that one piece of code related to how it was all setup was found in clean.c rather than dir.c. Make a change that would have made it easier for me to do the extra testing by putting this handling in one spot.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/clean.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/builtin/clean.c b/builtin/clean.c
index 3ca940f83a2..1be437bd5a3 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -924,12 +924,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 			     0);
 
 	memset(&dir, 0, sizeof(dir));
-	if (ignored_only)
-		dir.flags |= DIR_SHOW_IGNORED;
-
-	if (ignored && ignored_only)
-		die(_("-x and -X cannot be used together"));
-
 	if (!interactive && !dry_run && !force) {
 		if (config_set)
 			die(_("clean.requireForce set to true and neither -i, -n, nor -f given; "
@@ -946,6 +940,13 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 
 	dir.flags |= DIR_SHOW_OTHER_DIRECTORIES;
 
+	if (ignored && ignored_only)
+		die(_("-x and -X cannot be used together"));
+	if (!ignored)
+		setup_standard_excludes(&dir);
+	if (ignored_only)
+		dir.flags |= DIR_SHOW_IGNORED;
+
 	if (argc) {
 		/*
 		 * Remaining args implies pathspecs specified, and we should
@@ -960,9 +961,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 	if (read_cache() < 0)
 		die(_("index file corrupt"));
 
-	if (!ignored)
-		setup_standard_excludes(&dir);
-
 	pl = add_pattern_list(&dir, EXC_CMDL, "--exclude option");
 	for (i = 0; i < exclude_list.nr; i++)
 		add_pattern(exclude_list.items[i].string, "", 0, pl, -(i+1));
-- 
gitgitgadget
Previous: Elijah Newren via GitGitGadgetNext: Elijah Newren via GitGitGadget
Message 4 of 7 in “Clean cleanups”
  1. 0/4 Clean cleanupsElijah Newren via GitGitGadget, Jun 11, 2020
  2. 1/4 dir: fix a few confusing commentsElijah Newren via GitGitGadget, Jun 11, 2020
  3. 2/4 dir, clean: avoid disallowed behaviorElijah Newren via GitGitGadget, Jun 11, 2020
  4. 3/4 clean: consolidate handling of ignored parametersElijah Newren via GitGitGadget, Jun 11, 2020
  5. 4/4 clean: optimize and document cases where we recurse into subdirectoriesElijah Newren via GitGitGadget, Jun 11, 2020
  6. Junio C HamanoJun 13, 2020
  7. Brian MalehornJun 18, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.