git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>, drizzd@aon.at
Cc: fullung@gmail.com, matthijs@stdin.nl, j.sixt@viscovery.net,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2] get_cwd_relative(): do not misinterpret root path
Date: Sat, 20 Nov 2010 13:50:51 +0700	[thread overview]
Message-ID: <1290235851-23276-1-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <20101119204159.GA28622@localhost>

Commit 490544b (get_cwd_relative(): do not misinterpret suffix as
subdirectory) handles case where:

dir = "/path/work";
cwd = "/path/work-xyz";

When it comes to the end of get_cwd_relative(), dir is at '\0' and cwd
is at '-'. The rest of cwd, "-xyz", clearly cannot be the relative
path from dir to cwd. However there is another case where:

dir = "/";          /* or even "c:/" */
cwd = "/path/to/here";

In this special case, while *cwd == 'p', which is not a path
separator, the rest of cwd, "path/to/here", can be returned as a
relative path from dir to cwd.

Handle this case and make t1509 pass again.

Reported-by: Albert Strasheim <fullung@gmail.com>
Reported-by: Matthijs Kooijman <matthijs@stdin.nl>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 2010/11/20 Clemens Buchacher <drizzd@aon.at>:
 > make_absolute_path() already rewrites dir to contain slashes only.
 > I think it is confusing to use is_dir_sep() here, when we only
 > check for / above.

 I was thinking about GIT_WORK_TREE="c:\" (so dir would be "c:\") when
 I wrote that. It is recognized as absolute path, no normalization
 will be done.

 But then the comparison part earlier in this function would fail because
 getcwd in Windows port always return '/'.

 I will make a patch to convert GIT_WORK_TREE (and GIT_DIR too?) to '/'
 so everything is consistent.

 dir.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/dir.c b/dir.c
index b2dfb69..b687504 100644
--- a/dir.c
+++ b/dir.c
@@ -965,6 +965,12 @@ char *get_relative_cwd(char *buffer, int size, const char *dir)
 	case '/':
 		return cwd + 1;
 	default:
+		/*
+		 * dir can end with a path separator when it's root
+		 * directory. Return proper prefix in that case.
+		 */
+		if (dir[-1] == '/')
+			return cwd;
 		return NULL;
 	}
 }
-- 
1.7.3.2.316.gda8b3

      reply	other threads:[~2010-11-20  6:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1290158239-12138-1-git-send-email-pclouds@gmail.com>
2010-11-19 20:41 ` [PATCH] get_cwd_relative(): do not misinterpret root path Clemens Buchacher
2010-11-20  6:50   ` Nguyễn Thái Ngọc Duy [this message]

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=1290235851-23276-1-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=drizzd@aon.at \
    --cc=fullung@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.net \
    --cc=matthijs@stdin.nl \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).