From: "Miklós Fazekas" <mfazekas@szemafor.com>
To: Pete Wyckoff <pw@padd.com>
Cc: git@vger.kernel.org, Gary Gibbons <ggibbons@perforce.com>
Subject: Re: [PATCH] git p4: chdir resolves symlinks only for relative paths
Date: Thu, 7 Mar 2013 09:36:06 +0100 [thread overview]
Message-ID: <CAAMmcSQszVbDERd964VLu1d4UG7SihC+Pn99D0gPvG7HAZp2UQ@mail.gmail.com> (raw)
In-Reply-To: <20130203230803.GA25555@padd.com>
Sorry for the late turnaround here is an improved version. Now chdir
has an optional argument client_path, if it's true then we don't do
os.getcwd. I think that my first patch is also valid too - when the
path is absolute no need for getcwd no matter what is the context,
when it's relative we have to use os.getcwd() no matter of the
context.
---
If p4 client is configured to /p/foo which is a symlink:
/p/foo -> /vol/barvol/projects/foo. Then resolving the
symlink will confuse p4:
"Path /vol/barvol/projects/foo/... is not under client root
/p/foo". While AltRoots in p4 client specification can be
used as a workaround on p4 side, git-p4 should not resolve
symlinks in client paths.
chdir(dir) uses os.getcwd() after os.chdir(dir) to resolve
relative paths, but as a sideeffect it resolves symlinks
too. Now for client paths we don't call os.getcwd().
Signed-off-by: Miklós Fazekas <mfazekas@szemafor.com>
---
git-p4.py | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index 0682e61..2bd8cc2 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -68,12 +68,17 @@ def p4_build_cmd(cmd):
real_cmd += cmd
return real_cmd
-def chdir(dir):
+def chdir(dir,client_path=False):
# P4 uses the PWD environment variable rather than getcwd(). Since we're
# not using the shell, we have to set it ourselves. This path could
# be relative, so go there first, then figure out where we ended up.
+ # os.getcwd() will resolve symlinks, so we should avoid it for
+ # client_paths.
os.chdir(dir)
- os.environ['PWD'] = os.getcwd()
+ if client_path:
+ os.environ['PWD'] = dir
+ else:
+ os.environ['PWD'] = os.getcwd()
def die(msg):
if verbose:
@@ -1554,7 +1559,7 @@ class P4Submit(Command, P4UserMap):
new_client_dir = True
os.makedirs(self.clientPath)
- chdir(self.clientPath)
+ chdir(self.clientPath,client_path=True)
if self.dry_run:
print "Would synchronize p4 checkout in %s" % self.clientPath
else:
--
1.7.10.2 (Apple Git-33)
On Mon, Feb 4, 2013 at 12:08 AM, Pete Wyckoff <pw@padd.com> wrote:
> mfazekas@szemafor.com wrote on Tue, 29 Jan 2013 09:37 +0100:
>> If a p4 client is configured to /p/foo which is a symlink
>> to /vol/bar/projects/foo, then resolving symlink, which
>> is done by git-p4's chdir will confuse p4: "Path
>> /vol/bar/projects/foo/... is not under client root /p/foo"
>> While AltRoots in p4 client specification can be used as a
>> workaround on p4 side, git-p4 should not resolve symlinks
>> in client paths.
>> chdir(dir) uses os.getcwd() after os.chdir(dir) to resolve
>> relative paths, but as a side effect it resolves symlinks
>> too. Now it checks if the dir is relative before resolving.
>>
>> Signed-off-by: Miklós Fazekas <mfazekas@szemafor.com>
>> ---
>> git-p4.py | 5 ++++-
>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/git-p4.py b/git-p4.py
>> index 2da5649..5d74649 100755
>> --- a/git-p4.py
>> +++ b/git-p4.py
>> @@ -64,7 +64,10 @@ def chdir(dir):
>> # not using the shell, we have to set it ourselves. This path could
>> # be relative, so go there first, then figure out where we ended up.
>> os.chdir(dir)
>> - os.environ['PWD'] = os.getcwd()
>> + if os.path.isabs(dir):
>> + os.environ['PWD'] = dir
>> + else:
>> + os.environ['PWD'] = os.getcwd()
>>
>> def die(msg):
>> if verbose:
>
> Thanks, this is indeed a bug and I have reproduced it with a test
> case. Your patch works, but I think it would be better to
> separate the callers of chdir(): those that know they are
> cd-ing to a path from a p4 client, and everybody else. The former
> should not use os.getcwd(), as you show.
>
> I'll whip something up soon, unless you beat me to it.
>
> -- Pete
next prev parent reply other threads:[~2013-03-07 8:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAAMmcSSvrsZqEVf68Nrqy_ZG6r5ESKhtx7JdQ7vzypkZ3gOFnA@mail.gmail.com>
2013-01-29 8:37 ` [PATCH] git p4: chdir resolves symlinks only for relative paths Miklós Fazekas
2013-02-03 23:08 ` Pete Wyckoff
2013-03-07 8:36 ` Miklós Fazekas [this message]
2013-03-07 9:13 ` John Keeping
2013-03-07 23:19 ` [PATCH 0/3] fix git-p4 client root symlink problems Pete Wyckoff
2013-03-07 23:19 ` [PATCH 1/3] git p4 test: make sure P4CONFIG relative path works Pete Wyckoff
2013-03-07 23:19 ` [PATCH 2/3] git p4 test: should honor symlink in p4 client root Pete Wyckoff
2013-03-08 6:42 ` Johannes Sixt
2013-03-11 21:45 ` [PATCH v2 0/3] fix git-p4 client root symlink problems Pete Wyckoff
2013-03-11 21:45 ` [PATCH v2 1/3] git p4 test: make sure P4CONFIG relative path works Pete Wyckoff
2013-03-11 21:45 ` [PATCH v2 2/3] git p4 test: should honor symlink in p4 client root Pete Wyckoff
2013-03-11 21:45 ` [PATCH v2 3/3] git p4: avoid expanding client paths in chdir Pete Wyckoff
2013-03-07 23:19 ` [PATCH " Pete Wyckoff
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=CAAMmcSQszVbDERd964VLu1d4UG7SihC+Pn99D0gPvG7HAZp2UQ@mail.gmail.com \
--to=mfazekas@szemafor.com \
--cc=ggibbons@perforce.com \
--cc=git@vger.kernel.org \
--cc=pw@padd.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).