git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Sixt <j.sixt@viscovery.net>
To: David Reiss <dreiss@facebook.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2] Add support for GIT_CEILING_DIRS
Date: Thu, 15 May 2008 09:06:19 +0200	[thread overview]
Message-ID: <482BE0EB.6040306@viscovery.net> (raw)
In-Reply-To: <482B935D.20105@facebook.com>

David Reiss schrieb:
>  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

  reply	other threads:[~2008-05-15  7:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-15  1:35 [PATCH v2] Add support for GIT_CEILING_DIRS David Reiss
2008-05-15  7:06 ` Johannes Sixt [this message]
2008-05-15  7:11   ` David Reiss
2008-05-15  8:38     ` Johannes Sixt
2008-05-15  9:06       ` Johannes Schindelin
2008-05-15 16:26         ` David Reiss
2008-05-15 17:45           ` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=482BE0EB.6040306@viscovery.net \
    --to=j.sixt@viscovery.net \
    --cc=dreiss@facebook.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).