git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit
@ 2008-08-01 19:50 Robert Blum
  2008-08-03 21:13 ` Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Robert Blum @ 2008-08-01 19:50 UTC (permalink / raw)
  To: simon, shausman, marius, hanwen, gitster; +Cc: git

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(-)

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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit
  2008-08-01 19:50 [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit Robert Blum
@ 2008-08-03 21:13 ` Junio C Hamano
       [not found]   ` <bad7471c0808040601y10cceb44idcde5a4a8f415769@mail.gmail.com>
  2008-08-05  8:24   ` Simon Hausmann
  2008-08-04  3:06 ` Han-Wen Nienhuys
  2008-08-05 22:23 ` Alex Riesen
  2 siblings, 2 replies; 8+ messages in thread
From: Junio C Hamano @ 2008-08-03 21:13 UTC (permalink / raw)
  To: Robert Blum; +Cc: simon, shausman, marius, hanwen, gitster, git

"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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit
  2008-08-01 19:50 [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit Robert Blum
  2008-08-03 21:13 ` Junio C Hamano
@ 2008-08-04  3:06 ` Han-Wen Nienhuys
  2008-08-05 22:23 ` Alex Riesen
  2 siblings, 0 replies; 8+ messages in thread
From: Han-Wen Nienhuys @ 2008-08-04  3:06 UTC (permalink / raw)
  To: git

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

> +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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Fwd: [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit
       [not found]   ` <bad7471c0808040601y10cceb44idcde5a4a8f415769@mail.gmail.com>
@ 2008-08-04 13:04     ` Robert Blum
  2008-08-16  5:44       ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Robert Blum @ 2008-08-04 13:04 UTC (permalink / raw)
  To: git

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 ;)

 - Robert

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit
  2008-08-03 21:13 ` Junio C Hamano
       [not found]   ` <bad7471c0808040601y10cceb44idcde5a4a8f415769@mail.gmail.com>
@ 2008-08-05  8:24   ` Simon Hausmann
  1 sibling, 0 replies; 8+ messages in thread
From: Simon Hausmann @ 2008-08-05  8:24 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Robert Blum, shausman, marius, hanwen, git

On Sunday 03 August 2008 23:13:42 Junio C Hamano wrote:
> "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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit
  2008-08-01 19:50 [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit Robert Blum
  2008-08-03 21:13 ` Junio C Hamano
  2008-08-04  3:06 ` Han-Wen Nienhuys
@ 2008-08-05 22:23 ` Alex Riesen
  2 siblings, 0 replies; 8+ messages in thread
From: Alex Riesen @ 2008-08-05 22:23 UTC (permalink / raw)
  To: Robert Blum; +Cc: simon, shausman, marius, hanwen, gitster, git

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).

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fwd: [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit
  2008-08-04 13:04     ` Fwd: " Robert Blum
@ 2008-08-16  5:44       ` Junio C Hamano
  2008-08-16  5:56         ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2008-08-16  5:44 UTC (permalink / raw)
  To: Robert Blum; +Cc: git

"Robert Blum" <rob.blum@gmail.com> writes:

> 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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fwd: [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit
  2008-08-16  5:44       ` Junio C Hamano
@ 2008-08-16  5:56         ` Junio C Hamano
  0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2008-08-16  5:56 UTC (permalink / raw)
  To: Robert Blum; +Cc: git, Simon Hausmann, Han-Wen Nienhuys

Junio C Hamano <gitster@pobox.com> writes:

> "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(-)

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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-08-16  5:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-01 19:50 [PATCH] git-p4: chdir now properly sets PWD environment variable in msysGit Robert Blum
2008-08-03 21:13 ` Junio C Hamano
     [not found]   ` <bad7471c0808040601y10cceb44idcde5a4a8f415769@mail.gmail.com>
2008-08-04 13:04     ` Fwd: " Robert Blum
2008-08-16  5:44       ` Junio C Hamano
2008-08-16  5:56         ` Junio C Hamano
2008-08-05  8:24   ` Simon Hausmann
2008-08-04  3:06 ` Han-Wen Nienhuys
2008-08-05 22:23 ` Alex Riesen

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).