diff hgext/convert/git.py @ 5232:7d3dcdd92a1a

Merge with crew-stable
author Patrick Mezard <pmezard@gmail.com>
date Sun, 26 Aug 2007 16:49:26 +0200
parents ef338e34a906 149742a628fd
children 20770c5d41e0
line wrap: on
line diff
--- a/hgext/convert/git.py
+++ b/hgext/convert/git.py
@@ -5,8 +5,23 @@ import os
 from common import NoRepo, commit, converter_source
 
 class convert_git(converter_source):
-    def gitcmd(self, s):
-        return os.popen('GIT_DIR=%s %s' % (self.path, s))
+    # Windows does not support GIT_DIR= construct while other systems
+    # cannot remove environment variable. Just assume none have
+    # both issues.
+    if hasattr(os, 'unsetenv'):
+        def gitcmd(self, s):
+            prevgitdir = os.environ.get('GIT_DIR')
+            os.environ['GIT_DIR'] = self.path
+            try:
+                return os.popen(s)
+            finally:
+                if prevgitdir is None:
+                    del os.environ['GIT_DIR']
+                else:
+                    os.environ['GIT_DIR'] = prevgitdir
+    else:
+        def gitcmd(self, s):
+            return os.popen('GIT_DIR=%s %s' % (self.path, s))
 
     def __init__(self, ui, path, rev=None):
         super(convert_git, self).__init__(ui, path, rev=rev)