threads / patch / 14794

patchgit-p4: chdir now properly sets PWD environment variable in msysGit

Subject: [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit

## tl;dr

8 messages between Aug 1, 2008 and Aug 16, 2008. Diffs are folded; open one to read it.

replies: 7people: 5as markdown or json

Robert Blum· Aug 1, 2008, 19:50 UTC · lore

P4 on Windows expects the PWD environment variable to be set to the current working dir, but os.chdir in python doesn't do that by default

Signed-off-by: Robert Blum <rob.blum@gmail.com>
---

Pushing it out to the list since I'm not entirely sure who the git-p4 owner even is. CC'ed likely suspects for ownership ;)

 contrib/fast-import/git-p4 |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
Show changes to contrib/fast-import/git-p4 +11 −5
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 6ae0429..b4d0c65 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -16,6 +16,13 @@ from sets import Set;

 verbose = False

+if os.name == 'nt':
+    def os_chdir(dir):
+        os.environ['PWD']=dir
+        os.chdir(dir)
+else:
+    os_chdir = os.chdir
+
 def die(msg):
     if verbose:
         raise Exception(msg)
@@ -712,7 +719,7 @@ class P4Submit(Command):
         print "Perforce checkout for depot path %s located at %s" % (self.depot
Path, self.clientPath)
         self.oldWorkingDirectory = os.getcwd()

-        os.chdir(self.clientPath)
+        os_chdir(self.clientPath)
         print "Syncronizing p4 checkout..."
         system("p4 sync ...")

@@ -732,7 +739,7 @@ class P4Submit(Command):

         if len(commits) == 0:
             print "All changes applied!"
-            os.chdir(self.oldWorkingDirectory)
+            os_chdir(self.oldWorkingDirectory)

             sync = P4Sync()
             sync.run([])
@@ -1670,7 +1677,7 @@ class P4Clone(P4Sync):
         print "Importing from %s into %s" % (', '.join(depotPaths), self.cloneD
estination)
         if not os.path.exists(self.cloneDestination):
             os.makedirs(self.cloneDestination)
-        os.chdir(self.cloneDestination)
+        os_chdir(self.cloneDestination)
         system("git init")
         self.gitdir = os.getcwd() + "/.git"
         if not P4Sync.run(self, depotPaths):
@@ -1782,7 +1789,7 @@ def main():
                 if os.path.exists(cmd.gitdir):
                     cdup = read_pipe("git rev-parse --show-cdup").strip()
                     if len(cdup) > 0:
-                        os.chdir(cdup);
+                        os_chdir(cdup);

         if not isValidGitDir(cmd.gitdir):
             if isValidGitDir(cmd.gitdir + "/.git"):
--
1.5.5.1015.g9d258
Junio C Hamano· Aug 3, 2008, 21:13 UTC · re: Robert Blum · lore

Re: [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit

"Robert Blum" <rob.blum@gmail.com> writes:
> P4 on Windows expects the PWD environment variable to be set to the
> current working dir, but os.chdir in python doesn't do that by default

Missing full stop at the end of sentence aside, this comment makes me wonder if there is an optional way to have it set it, as opposed to the inconvenient way it behaves "by defualt". If there is none, I think your patch, even though it looks ugly, is the least evil approach. Another way might be to wrap callsites of system() by introducing a "run_p4" function, like:

	def run_p4(arg):
        	os.environ['PWD'] = os.getcwd() if os.name == 'nt'
		return system(arg)
> ---
>
> Pushing it out to the list since I'm not entirely sure who the git-p4 owner
> even is. CC'ed likely suspects for ownership ;)

Thanks. I've been waiting for an Ack from somewhere or success reports from p4 users on Windows.

Simon Hausmann· Aug 5, 2008, 08:24 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit

On Sunday 03 August 2008 23:13:42 Junio C Hamano wrote:
Show 22 quoted lines
> "Robert Blum" <rob.blum@gmail.com> writes:
> > P4 on Windows expects the PWD environment variable to be set to the
> > current working dir, but os.chdir in python doesn't do that by default
>
> Missing full stop at the end of sentence aside, this comment makes me
> wonder if there is an optional way to have it set it, as opposed to the
> inconvenient way it behaves "by defualt".  If there is none, I think your
> patch, even though it looks ugly, is the least evil approach.  Another way
> might be to wrap callsites of system() by introducing a "run_p4" function,
> like:
>
> 	def run_p4(arg):
>         	os.environ['PWD'] = os.getcwd() if os.name == 'nt'
> 		return system(arg)
>
> > ---
> >
> > Pushing it out to the list since I'm not entirely sure who the git-p4
> > owner even is. CC'ed likely suspects for ownership ;)
>
> Thanks.  I've been waiting for an Ack from somewhere or success reports
> from p4 users on Windows.
Acked-by: Simon Hausmann <simon@lst.de>
It may not be the prettiest solution, but I agree it needs to be solved :)
Simon
Han-Wen Nienhuys· Aug 4, 2008, 03:06 UTC · re: Robert Blum · lore

Re: [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit

Robert Blum escreveu:
> P4 on Windows expects the PWD environment variable to be set to the
> current working dir, but os.chdir in python doesn't do that by default
Show 7 quoted lines
> +if os.name == 'nt':
> +    def os_chdir(dir):
> +        os.environ['PWD']=dir
> +        os.chdir(dir)
> +else:
> +    os_chdir = os.chdir
> +
Stylistic:
I think the naming is a bit ugly (os_); I would write
  def chdir(d):
     if os.name == 'nt': .. 
     os.chdir(dir)
for the rest: looks good to me.
	
-- 
 Han-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen
Alex Riesen· Aug 5, 2008, 22:23 UTC · re: Robert Blum · lore

Re: [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit

2008/8/1 Robert Blum <rob.blum@gmail.com>:
> P4 on Windows expects the PWD environment variable to be set to the
> current working dir, but os.chdir in python doesn't do that by default
Try just removing it (if you can). It worked for me (in bash of cygwin).
Robert Blum· Aug 4, 2008, 13:04 UTC · lore

Fwd: [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit

Forgot reply-all - forwarding to list....
> Missing full stop at the end of sentence aside, this comment makes me
> wonder if there is an optional way to have it set it, as opposed to the
> inconvenient way it behaves "by defualt".

Not that I'm aware of. My 'by default' comment refers to a default Python installation, i.e. unpatched. As far as I know, the real culprit in this is p4. I'd argue it's a bug, since they should be using getcwd(), not getpwd(). Moot point - I don't want to wait for git-p4 until I have convinced perforce to fix this and a new p4 rolls around ;)

>  If there is none, I think your
> patch, even though it looks ugly, is the least evil approach.
Warms the cockles of my heart ;)
Show 7 quoted lines
> Another way
> might be to wrap callsites of system() by introducing a "run_p4" function,
> like:
>
>        def run_p4(arg):
>                os.environ['PWD'] = os.getcwd() if os.name == 'nt'
>                return system(arg)
Happy to submit a new patch with that, if that's preferred.
> Thanks.  I've been waiting for an Ack from somewhere or success reports
> from p4 users on Windows.

Han-Wen seems OK with it. (BTW: Who *is* the maintainer of git-p4?) But hold off on applying - I'll resubmit with the run_p4 approach today.

(Oh, and of course: Works for me ;)
 - Robert
Junio C Hamano· Aug 16, 2008, 05:44 UTC · re: Robert Blum · lore

Re: Fwd: [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit

"Robert Blum" <rob.blum@gmail.com> writes:
Show 36 quoted lines
> Forgot reply-all - forwarding to list....
>
>> Missing full stop at the end of sentence aside, this comment makes me
>> wonder if there is an optional way to have it set it, as opposed to the
>> inconvenient way it behaves "by defualt".
>
> Not that I'm aware of. My 'by default' comment refers to a default
> Python installation, i.e. unpatched. As far as I know, the real
> culprit in this is p4. I'd argue it's a bug, since they should be
> using getcwd(), not getpwd(). Moot point - I don't want to wait for
> git-p4 until I have convinced perforce to fix this and a new p4 rolls
> around ;)
>
>>  If there is none, I think your
>> patch, even though it looks ugly, is the least evil approach.
>
> Warms the cockles of my heart ;)
>
>> Another way
>> might be to wrap callsites of system() by introducing a "run_p4" function,
>> like:
>>
>>        def run_p4(arg):
>>                os.environ['PWD'] = os.getcwd() if os.name == 'nt'
>>                return system(arg)
>
> Happy to submit a new patch with that, if that's preferred.
>
>> Thanks.  I've been waiting for an Ack from somewhere or success reports
>> from p4 users on Windows.
>
> Han-Wen seems OK with it. (BTW: Who *is* the maintainer of git-p4?)
> But hold off on applying - I'll resubmit with the run_p4 approach
> today.
>
> (Oh, and of course: Works for me ;)
I have been wondering what happened to this thread afterwards.
Junio C Hamano· Aug 16, 2008, 05:56 UTC · re: Junio C Hamano · lore

Re: Fwd: [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit

Junio C Hamano <gitster@pobox.com> writes:
Show 5 quoted lines
> "Robert Blum" <rob.blum@gmail.com> writes:
>
>> Forgot reply-all - forwarding to list....
> ...
> I have been wondering what happened to this thread afterwards.

In the meantime, here is what I am inclined to apply. The same approach as the original, taking stylistic suggestion from Han-Wen.

-- >8 --
From: Robert Blum <rob.blum@gmail.com>
Date: Fri, 1 Aug 2008 12:50:03 -0700
Subject: [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit

P4 on Windows expects the PWD environment variable to be set to the current working dir, but os.chdir in python doesn't do so.

Signed-off-by: Robert Blum <rob.blum@gmail.com>
Acked-by: Simon Hausmann <simon@lst.de>
Acked-by: Han-Wen Nienhuys <hanwen@xs4all.nl>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 contrib/fast-import/git-p4 |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
Show changes to contrib/fast-import/git-p4 +9 −4
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 6ae0429..3f2303d 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -16,6 +16,11 @@ from sets import Set;
 
 verbose = False
 
+def chdir(dir):
+    if os.name == 'nt':
+        os.environ['PWD']=dir
+    os.chdir(dir)
+
 def die(msg):
     if verbose:
         raise Exception(msg)
@@ -712,7 +717,7 @@ class P4Submit(Command):
         print "Perforce checkout for depot path %s located at %s" % (self.depotPath, self.clientPath)
         self.oldWorkingDirectory = os.getcwd()
 
-        os.chdir(self.clientPath)
+        chdir(self.clientPath)
         print "Syncronizing p4 checkout..."
         system("p4 sync ...")
 
@@ -732,7 +737,7 @@ class P4Submit(Command):
 
         if len(commits) == 0:
             print "All changes applied!"
-            os.chdir(self.oldWorkingDirectory)
+            chdir(self.oldWorkingDirectory)
 
             sync = P4Sync()
             sync.run([])
@@ -1670,7 +1675,7 @@ class P4Clone(P4Sync):
         print "Importing from %s into %s" % (', '.join(depotPaths), self.cloneDestination)
         if not os.path.exists(self.cloneDestination):
             os.makedirs(self.cloneDestination)
-        os.chdir(self.cloneDestination)
+        chdir(self.cloneDestination)
         system("git init")
         self.gitdir = os.getcwd() + "/.git"
         if not P4Sync.run(self, depotPaths):
@@ -1782,7 +1787,7 @@ def main():
                 if os.path.exists(cmd.gitdir):
                     cdup = read_pipe("git rev-parse --show-cdup").strip()
                     if len(cdup) > 0:
-                        os.chdir(cdup);
+                        chdir(cdup);
 
         if not isValidGitDir(cmd.gitdir):
             if isValidGitDir(cmd.gitdir + "/.git"):
-- 
1.6.0.rc3.11.g8134a

← back to recent threads