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

Re: [PATCH 1/1] clean: further clean-up of implementation around "--force"

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 3, 2024, 22:18 UTC
Message-ID
<xmqq5xy3vu0x.fsf@gitster.g>
In-Reply-To
<20240303220600.2491792-2-gitster@pobox.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 16 quoted lines
> @@ -950,13 +950,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
>  	argc = parse_options(argc, argv, prefix, options, builtin_clean_usage,
>  			     0);
>  
> -	/* Dry run won't remove anything, so requiring force makes no sense */
> -	if (dry_run)
> -		require_force = 0;
> -
> -	if (require_force != 0 && !force && !interactive)
> -		die(_("clean.requireForce is true and neither -f nor -i given:"
> -				  " refusing to clean"));
> +	if (require_force != 0 && !force && !interactive && !dry_run)
> +		die(_("clean.requireForce is true and -f not given: refusing to clean"));
>  
>  	if (force > 1)
>  		rm_flags = 0;

An obvious alternative way to clean-up the logic is to do this instead:

	if (dry_run || interactive))
		require_force = 0;
 	if (require_force != 0 && !force)
		die(_("clean.requireForce is true and ..."));

But as I wrote, the most important improvement done by Sergey's patch was to remove the dual meaning of the "force" variable so that it indicates if the "--force" option was given and nothing else, while the "require_force" variable indicates if clean.requireForce was given and nothing else. From that point of view, the conditional tweaking done to require_force in the above alternative makes the code worse, relative to Sergey's patch, and certainly to its follow up, my patch about "--interactive".

Previous: Junio C HamanoNext: Sergey Organov
Message 3 of 9 in “Re: [PATCH v2] clean: improve -n and -f implementation and documentation”
  1. Junio C HamanoMar 3, 2024
  2. 1/1 clean: further clean-up of implementation around "--force"Junio C Hamano, Mar 3, 2024
  3. Junio C HamanoMar 3, 2024
  4. Sergey OrganovMar 4, 2024
  5. Sergey OrganovMar 4, 2024
  6. Junio C HamanoMar 4, 2024
  7. Sergey OrganovMar 4, 2024
  8. Junio C HamanoMar 4, 2024
  9. Sergey OrganovMar 4, 2024

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.