All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Sixt <j6t@kdbg.org>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Pat Thoyts <patthoyts@gmail.com>,
	gitster@pobox.com, msysGit <msysgit@googlegroups.com>,
	Sebastian Schuberth <sschuberth@gmail.com>,
	git@vger.kernel.org
Subject: Re: [PATCH] Do not trust PWD blindly
Date: Sun, 10 Jul 2011 22:47:08 +0200	[thread overview]
Message-ID: <4E1A0FCC.7080308@kdbg.org> (raw)
In-Reply-To: <alpine.DEB.1.00.1107091935210.1985@bonsai2>

Am 09.07.2011 19:38, schrieb Johannes Schindelin:
> 
> At least on Windows, chdir() does not update PWD.

Very strange wording. chdir() should not update PWD even on POSIX.

> Unfortunately, stat()
> does not fill any ino or dev fields anymore, so get_pwd_cwd() is not
> able to tell.
> 
> But there is a telltale: both ino and dev are 0 when they are not filled
> correctly, so let's be extra cautious.
> 
> This happens to fix a bug in "get-receive-pack working_directory/" when
> the GIT_DIR would not be set correctly due to absolute_path(".")
> returning the wrong value.
> 
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> 
> 	On Fri, 8 Jul 2011, Pat Thoyts wrote:
> 
> 	> ! t5516-fetch-push      (60 receive.denyCurrentBranch = updateInstead)
> 
> 	This patch fixes that.
> 
> 	Hannes, I have no idea whether you meant 10c4c881 to fix anything 
> 	on Windows.

I think this fix worked for me because when git is called from CMD, PWD
is not in the enviornment and the if (pwd && ...) branch is never taken.

> 
>  abspath.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/abspath.c b/abspath.c
> index 01858eb..37287f8 100644
> --- a/abspath.c
> +++ b/abspath.c
> @@ -102,7 +102,8 @@ static const char *get_pwd_cwd(void)
>  	pwd = getenv("PWD");
>  	if (pwd && strcmp(pwd, cwd)) {
>  		stat(cwd, &cwd_stat);
> -		if (!stat(pwd, &pwd_stat) &&
> +		if ((cwd_stat.st_dev || cwd_stat.st_ino) &&
> +		    !stat(pwd, &pwd_stat) &&
>  		    pwd_stat.st_dev == cwd_stat.st_dev &&
>  		    pwd_stat.st_ino == cwd_stat.st_ino) {
>  			strlcpy(cwd, pwd, PATH_MAX);

Acked-by: Johannes Sixt <j6t@kdbg.org>

-- Hannes

  parent reply	other threads:[~2011-07-10 20:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CABNJ2GKgzXGDq9FhKcVP380bs=rEKqYdrOaCb+A99_TBm7A4_A@mail.gmail.com>
2011-07-09 17:38 ` [PATCH] Do not trust PWD blindly Johannes Schindelin
2011-07-09 20:06   ` Sebastian Schuberth
2011-07-10 20:47   ` Johannes Sixt [this message]
2011-07-10 22:59     ` Johannes Schindelin
2011-07-11  1:52       ` Randal L. Schwartz
2011-07-11  9:26         ` Johannes Schindelin
2011-07-11 16:56           ` Junio C Hamano
2011-07-11 17:18             ` 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=4E1A0FCC.7080308@kdbg.org \
    --to=j6t@kdbg.org \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=msysgit@googlegroups.com \
    --cc=patthoyts@gmail.com \
    --cc=sschuberth@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.