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

Re: [PATCH v2] Simplify handling of setup_git_directory_gently() failure cases.

From
Jeff King <peff@peff.net>
Date
Dec 18, 2018, 17:54 UTC
Message-ID
<20181218175418.GB31070@sigill.intra.peff.net>
In-Reply-To
<1544922308-740-1-git-send-email-eedahlgren@gmail.com>
On Sat, Dec 15, 2018 at 05:05:08PM -0800, Erin Dahlgren wrote:
> setup_git_directory_gently() expects two types of failures to
> discover a git directory (e.g. .git/):
> [...]

When I read your subject line, I'll admit to having a funny feeling in the pit of my stomach. This setup code has historically been full of subtle corner cases, and I expected a very tricky review.

However, your explanation was so well-written that it was a pleasure to read. :)

Show 5 quoted lines
> Before this change are two misleading additional behaviors:
> 
>   - GIT_DIR_HIT_CEILING: setup_nongit() changes to the cwd for no
> 	apparent reason. We never had the chance to change directories
> 	up to this point so chdir(current cwd) is pointless.

That makes sense. I think this is a holdover from when we used to walk backwards via chdir(), prior to ce9b8aab5d (setup_git_directory_1(): avoid changing global state, 2017-03-13). Back then, we needed to restore the state at this point, but now we don't.

Show 5 quoted lines
>   - GIT_DIR_HIT_MOUNT_POINT: strbuf_release() frees the buffer
> 	of a static struct strbuf (cwd). This is unnecessary because the
> 	struct is static so its buffer is always reachable. This is also
> 	misleading because nowhere else in the function is this buffer
> 	released.
Makes sense.
I do have one question, though:
Show 9 quoted lines
>  	case GIT_DIR_HIT_CEILING:
> -		prefix = setup_nongit(cwd.buf, nongit_ok);
> -		break;
> +		if (!nongit_ok)
> +			die(_("not a git repository (or any of the parent directories): %s"),
>a +					DEFAULT_GIT_DIR_ENVIRONMENT);
> +		*nongit_ok = 1;
> +		strbuf_release(&dir);
> +		return NULL;
This case used to break out of the switch, and now returns early.

So we do not execute the later code which clears GIT_PREFIX_ENVIRONMENT, and zeroes the fields in startup_info. Those probably don't matter in most cases, but I wonder if there are some obscure ones where it might.

Might it make sense to make GIT_DIR_HIT_MOUNT_POINT more like GIT_DIR_HIT_CEILING currently is, rather than the other way around? I.e., something like:

  case GIT_DIR_HIT_CEILING:
	if (!nongit_ok)
		die(...);
	*nongit_ok = 1;
	prefix = NULL;
	break;
  case GIT_DIR_HIT_MOUNT_POINT:
	if (!nongit_ok)
		die(...);
	*nongit_ok = 1;
	prefix = NULL;
	break;
?
-Peff
Previous: Erin DahlgrenNext: Erin Dahlgren
Message 7 of 19 in “Simplify handling of setup_git_directory_gently() failure cases.”
  1. Simplify handling of setup_git_directory_gently() failure cases.Erin Dahlgren, Dec 13, 2018
  2. Johannes SchindelinDec 14, 2018
  3. Erin DahlgrenDec 16, 2018
  4. Simplify handling of setup_git_directory_gently() failure cases.Erin Dahlgren, Dec 16, 2018
  5. Johannes SchindelinDec 18, 2018
  6. Erin DahlgrenDec 18, 2018
  7. Jeff KingDec 18, 2018
  8. Erin DahlgrenDec 18, 2018
  9. Jeff KingDec 19, 2018
  10. Junio C HamanoDec 26, 2018
  11. Jeff KingDec 27, 2018
  12. Erin DahlgrenDec 27, 2018
  13. Jeff KingJan 3, 2019
  14. Simplify handling of setup_git_directory_gently() failure cases.Erin Dahlgren, Dec 27, 2018
  15. Jeff KingJan 3, 2019
  16. Junio C HamanoJan 3, 2019
  17. Jeff KingJan 4, 2019
  18. Erin DahlgrenJan 5, 2019
  19. Jeff KingJan 6, 2019

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.