From: Pete Wyckoff <pw@padd.com>
To: git@vger.kernel.org
Cc: "Miklós Fazekas" <mfazekas@szemafor.com>,
"John Keeping" <john@keeping.me.uk>,
"Johannes Sixt" <j.sixt@viscovery.net>
Subject: [PATCH v2 3/3] git p4: avoid expanding client paths in chdir
Date: Mon, 11 Mar 2013 17:45:29 -0400 [thread overview]
Message-ID: <1363038329-20185-4-git-send-email-pw@padd.com> (raw)
In-Reply-To: <1363038329-20185-1-git-send-email-pw@padd.com>
From: Miklós Fazekas <mfazekas@szemafor.com>
The generic chdir() helper sets the PWD environment
variable, as that is what is used by p4 to know its
current working directory. Normally the shell would
do this, but in git-p4, we must do it by hand.
However, when the path contains a symbolic link,
os.getcwd() will return the physical location. If the
p4 client specification includes symlinks, setting PWD
to the physical location causes p4 to think it is not
inside the client workspace. It complains, e.g.
Path /vol/bar/projects/foo/... is not under client root /p/foo
One workaround is to use AltRoots in the p4 client specification,
but it is cleaner to handle it directly in git-p4.
Other uses of chdir still require setting PWD to an
absolute path so p4 features like P4CONFIG work. See
bf1d68f (git-p4: use absolute directory for PWD env
var, 2011-12-09).
[ pw: tweak patch and commit message ]
Thanks-to: John Keeping <john@keeping.me.uk>
Signed-off-by: Pete Wyckoff <pw@padd.com>
---
git-p4.py | 29 ++++++++++++++++++++++-------
t/t9808-git-p4-chdir.sh | 2 +-
2 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index 647f110..7288c0b 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -79,12 +79,27 @@ def p4_build_cmd(cmd):
real_cmd += cmd
return real_cmd
-def chdir(dir):
- # 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.chdir(dir)
- os.environ['PWD'] = os.getcwd()
+def chdir(path, is_client_path=False):
+ """Do chdir to the given path, and set the PWD environment
+ variable for use by P4. It does not look at getcwd() output.
+ Since we're not using the shell, it is necessary to set the
+ PWD environment variable explicitly.
+
+ Normally, expand the path to force it to be absolute. This
+ addresses the use of relative path names inside P4 settings,
+ e.g. P4CONFIG=.p4config. P4 does not simply open the filename
+ as given; it looks for .p4config using PWD.
+
+ If is_client_path, the path was handed to us directly by p4,
+ and may be a symbolic link. Do not call os.getcwd() in this
+ case, because it will cause p4 to think that PWD is not inside
+ the client path.
+ """
+
+ os.chdir(path)
+ if not is_client_path:
+ path = os.getcwd()
+ os.environ['PWD'] = path
def die(msg):
if verbose:
@@ -1624,7 +1639,7 @@ class P4Submit(Command, P4UserMap):
new_client_dir = True
os.makedirs(self.clientPath)
- chdir(self.clientPath)
+ chdir(self.clientPath, is_client_path=True)
if self.dry_run:
print "Would synchronize p4 checkout in %s" % self.clientPath
else:
diff --git a/t/t9808-git-p4-chdir.sh b/t/t9808-git-p4-chdir.sh
index 4773296..11d2b51 100755
--- a/t/t9808-git-p4-chdir.sh
+++ b/t/t9808-git-p4-chdir.sh
@@ -58,7 +58,7 @@ test_expect_success 'p4 client root would be relative due to clone --dest' '
# When the p4 client Root is a symlink, make sure chdir() does not use
# getcwd() to convert it to a physical path.
-test_expect_failure SYMLINKS 'p4 client root symlink should stay symbolic' '
+test_expect_success SYMLINKS 'p4 client root symlink should stay symbolic' '
physical="$TRASH_DIRECTORY/physical" &&
symbolic="$TRASH_DIRECTORY/symbolic" &&
test_when_finished "rm -rf \"$physical\"" &&
--
1.8.2.rc2.65.g92f3e2d
next prev parent reply other threads:[~2013-03-11 21:55 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
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 ` Pete Wyckoff [this message]
2013-03-07 23:19 ` [PATCH 3/3] git p4: avoid expanding client paths in chdir 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=1363038329-20185-4-git-send-email-pw@padd.com \
--to=pw@padd.com \
--cc=git@vger.kernel.org \
--cc=j.sixt@viscovery.net \
--cc=john@keeping.me.uk \
--cc=mfazekas@szemafor.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).