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

Re: [PATCHv2 5/5] rm: add absorb a submodules git dir before deletion

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 14, 2016, 18:55 UTC
Message-ID
<xmqq7f72xrvw.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20161213205622.841-6-sbeller@google.com>
Stefan Beller <sbeller@google.com> writes:
Show 38 quoted lines
> diff --git a/builtin/rm.c b/builtin/rm.c
> index fdd7183f61..8c9c535a88 100644
> --- a/builtin/rm.c
> +++ b/builtin/rm.c
> @@ -392,28 +392,14 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
>  		for (i = 0; i < list.nr; i++) {
>  			const char *path = list.entry[i].name;
>  			if (list.entry[i].is_submodule) {
> -				if (is_empty_dir(path)) {
> -					if (!rmdir(path)) {
> -						removed = 1;
> -						if (!remove_path_from_gitmodules(path))
> -							gitmodules_modified = 1;
> -						continue;
> -					}
> -				} else {
> -					strbuf_reset(&buf);
> -					strbuf_addstr(&buf, path);
> -					if (!remove_dir_recursively(&buf, 0)) {
> -						removed = 1;
> -						if (!remove_path_from_gitmodules(path))
> -							gitmodules_modified = 1;
> -						strbuf_release(&buf);
> -						continue;
> -					} else if (!file_exists(path))
> -						/* Submodule was removed by user */
> -						if (!remove_path_from_gitmodules(path))
> -							gitmodules_modified = 1;
> -					/* Fallthrough and let remove_path() fail. */
> -				}
> +				if (is_empty_dir(path) && rmdir(path))
> +					die_errno("git rm: '%s'", path);
> +				if (file_exists(path))
> +					depopulate_submodule(path);
> +				removed = 1;
> +				if (!remove_path_from_gitmodules(path))
> +					gitmodules_modified = 1;
> +				continue;

The updated code structure is somewhat nicer for understanding the flow than the original, but it can further be improved.

A step "If empty directory, we try to rmdir and we check its return status and die ourselves if we couldn't remove it" reads very sensible, but coming immediately after that, "if it still exists, call depop()" looks a bit strange. I would have expected a similar construct, i.e.

	if (directory_exists(path) && depop_submodlue(path))
		die("git rm: '%s' submodule still populated", path);
there.  Also,
	if (is_empty_dir(path)) {
		if (rmdir(path))
			die_errno(...);
	} else if (is_nonempty_dir(path)) {
		if (depop_subm(path))
                	die(...);
	}
would have clarified the structure even further.

Yes, I know that you made depop_subm() to die on error, and the above is questioning if that is a sensible design choice.

Previous: Stefan BellerNext: Stefan Beller
Message 9 of 10 in “[PATCHv2 0/5] git-rm absorbs submodule git directory before deletion”
  1. Stefan BellerDec 13, 2016
  2. 1/5 submodule.h: add extern keyword to functionsStefan Beller, Dec 13, 2016
  3. 2/5 submodule: modernize ok_to_remove_submodule to use argv_arrayStefan Beller, Dec 13, 2016
  4. Junio C HamanoDec 14, 2016
  5. 4/5 ok_to_remove_submodule: absorb the submodule git dirStefan Beller, Dec 13, 2016
  6. Junio C HamanoDec 14, 2016
  7. Stefan BellerDec 14, 2016
  8. 5/5 rm: add absorb a submodules git dir before deletionStefan Beller, Dec 13, 2016
  9. Junio C HamanoDec 14, 2016
  10. 3/5 submodule: add flags to ok_to_remove_submoduleStefan Beller, Dec 13, 2016

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.