git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Carlo Marcelo Arenas Belon <carenas@sajinet.com.pe>
Cc: git@vger.kernel.org, "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: Re: [PATCH] setup: translate symlinks in filename when using absolute paths
Date: Tue, 28 Dec 2010 11:47:07 -0800	[thread overview]
Message-ID: <7vr5d1wuh0.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1293447277-30598-1-git-send-email-carenas@sajinet.com.pe> (Carlo Marcelo Arenas Belon's message of "Mon\, 27 Dec 2010 02\:54\:37 -0800")

Carlo Marcelo Arenas Belon <carenas@sajinet.com.pe> writes:

> otherwise, comparison to validate against work tree will fail when
> the path includes a symlink and the name passed is not canonical.
>
> Signed-off-by: Carlo Marcelo Arenas Belon <carenas@sajinet.com.pe>

I take that "path" and "name passed" refer to the same thing (i.e. "path"
parameter) in the above.

I think you are trying to handle the case where:

 - you give "/home/carenas/one" from the command line;
 - $PWD is "/home/carenas"; and
 - "/home/carenas" is a symlink to "/net/host/home/carenas"

and the scan-from-the-beginning-of-string check done between
"/home/carenas/one" and the return value of get_git_work_tree() which
presumably is "/net/host/home/carenas" disagrees.  I wonder if a more
correct solution might be to help get_git_work_tree() to match the notion
of where the repository and its worktree are to the idea of where the user
thinks they are, i.e. not "/net/host/home/carenas" but "/home/carenas", a
bit better?

That would involve tweaking make_absolute_path() I guess?

Note that your patch is the right thing to do either case, i.e. with or
without such a change to make_absolute_path(), as the function is used to
set up the return value from get_git_work_tree().  Anything we compare
with it should have passed make_absolute_path() at least once.

Nguyễn?

> ---
>  setup.c |   11 +++++++----
>  1 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/setup.c b/setup.c
> index 91887a4..e7c0d4d 100644
> --- a/setup.c
> +++ b/setup.c
> @@ -7,10 +7,13 @@ static int inside_work_tree = -1;
>  char *prefix_path(const char *prefix, int len, const char *path)
>  {
>  	const char *orig = path;
> -	char *sanitized = xmalloc(len + strlen(path) + 1);
> -	if (is_absolute_path(orig))
> -		strcpy(sanitized, path);
> -	else {
> +	char *sanitized;
> +	if (is_absolute_path(orig)) {
> +		const char *temp = make_absolute_path(path);
> +		sanitized = xmalloc(len + strlen(temp) + 1);
> +		strcpy(sanitized, temp);
> +	} else {
> +		sanitized = xmalloc(len + strlen(path) + 1);
>  		if (len)
>  			memcpy(sanitized, prefix, len);
>  		strcpy(sanitized + len, path);
> -- 
> 1.7.3.4.626.g73e7b.dirty

  reply	other threads:[~2010-12-28 19:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-27 10:54 [PATCH] setup: translate symlinks in filename when using absolute paths Carlo Marcelo Arenas Belon
2010-12-28 19:47 ` Junio C Hamano [this message]
2010-12-29  9:35   ` Carlo Marcelo Arenas Belon
2010-12-29 13:44   ` Nguyen Thai Ngoc Duy

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=7vr5d1wuh0.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=carenas@sajinet.com.pe \
    --cc=git@vger.kernel.org \
    --cc=pclouds@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 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).