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

Re: [PATCH v2] Add support for GIT_CEILING_DIRS

From
Johannes Sixt <j.sixt@viscovery.net>
Date
May 15, 2008, 07:06 UTC
Message-ID
<482BE0EB.6040306@viscovery.net>
In-Reply-To
<482B935D.20105@facebook.com>
David Reiss schrieb:
Show 42 quoted lines
>  const char *setup_git_directory_gently(int *nongit_ok)
>  {
>  	const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);
> +	const char *env_ceiling_dirs = getenv(CEILING_DIRS_ENVIRONMENT);
>  	static char cwd[PATH_MAX+1];
>  	const char *gitdirenv;
>  	const char *gitfile_dir;
> -	int len, offset;
> +	int len, offset, ceil_offset;
>  
>  	/*
>  	 * Let's assume that we are in a git repository.
> @@ -415,6 +517,14 @@ const char *setup_git_directory_gently(int *nongit_ok)
>  		die("Unable to read current working directory");
>  
>  	/*
> +	 * Compute ceil_offset based on GIT_CEILING_DIRS.  It is actually the offset
> +	 * of the first character in cwd after the trailing slash of the ceiling.
> +	 * Putting it so far to the right is necessary in order to bail out of the
> +	 * "--offset" loop early enough.
> +	 */
> +	ceil_offset = 1 + longest_ancestor_length(cwd, env_ceiling_dirs);
> +
> +	/*
>  	 * Test in the following order (relative to the cwd):
>  	 * - .git (file containing "gitdir: <path>")
>  	 * - .git/
> @@ -443,9 +553,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
>  			check_repository_format_gently(nongit_ok);
>  			return NULL;
>  		}
> -		chdir("..");
>  		do {
> -			if (!offset) {
> +			if (offset <= ceil_offset) {
>  				if (nongit_ok) {
>  					if (chdir(cwd))
>  						die("Cannot come back to cwd");
> @@ -455,6 +564,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
>  				die("Not a git repository");
>  			}
>  		} while (cwd[--offset] != '/');

If you make it so that the default value of ceil_offset is 0 (i.e. in the absence of any GIT_CEILING_DIRS), and at this place you did

		} while (offset > ceil_offset && cwd[--offset] != '/');

you wouldn't have to bend backwards with this off-by-one magic, would you? (But I admit that I haven't tried this code, I'm only comparing it to how we do it mingw.git.)

-- Hannes
Previous: David ReissNext: David Reiss
Message 2 of 7 in “Add support for GIT_CEILING_DIRS”
  1. Add support for GIT_CEILING_DIRSDavid Reiss, May 15, 2008
  2. Johannes SixtMay 15, 2008
  3. David ReissMay 15, 2008
  4. Johannes SixtMay 15, 2008
  5. Johannes SchindelinMay 15, 2008
  6. David ReissMay 15, 2008
  7. Johannes SchindelinMay 15, 2008

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.