changeset 5216:39e6deaa8b81

convert: gitcmd wrapper for os.popen
author Brendan Cully <brendan@kublai.com>
date Sun, 01 Jul 2007 21:09:08 -0700
parents 74723744d8e0
children 149742a628fd
files hgext/convert/git.py
diffstat 1 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/git.py	Fri Aug 24 00:56:08 2007 +0200
+++ b/hgext/convert/git.py	Sun Jul 01 21:09:08 2007 -0700
@@ -14,6 +14,9 @@
             return s.decode("utf-8", "replace").encode("utf-8")
 
 class convert_git(converter_source):
+    def gitcmd(self, s):
+        return os.popen('GIT_DIR=%s %s' % (self.path, s))
+    
     def __init__(self, ui, path):
         if os.path.isdir(path + "/.git"):
             path += "/.git"
@@ -23,13 +26,12 @@
             raise NoRepo("couldn't open GIT repo %s" % path)
 
     def getheads(self):
-        fh = os.popen("GIT_DIR=%s git-rev-parse --verify HEAD" % self.path)
+        fh = self.gitcmd("git-rev-parse --verify HEAD")
         return [fh.read()[:-1]]
 
     def catfile(self, rev, type):
         if rev == "0" * 40: raise IOError()
-        fh = os.popen("GIT_DIR=%s git-cat-file %s %s 2>/dev/null"
-                      % (self.path, type, rev))
+        fh = self.gitcmd("git-cat-file %s %s 2>/dev/null" % (type, rev))
         return fh.read()
 
     def getfile(self, name, rev):
@@ -40,8 +42,7 @@
 
     def getchanges(self, version):
         self.modecache = {}
-        fh = os.popen("GIT_DIR=%s git-diff-tree --root -m -r %s"
-                      % (self.path, version))
+        fh = self.gitcmd("git-diff-tree --root -m -r %s" % version)
         changes = []
         for l in fh:
             if "\t" not in l: continue
@@ -89,7 +90,7 @@
 
     def gettags(self):
         tags = {}
-        fh = os.popen('git-ls-remote --tags "%s" 2>/dev/null' % self.path)
+        fh = self.gitcmd('git-ls-remote --tags "%s" 2>/dev/null' % self.path)
         prefix = 'refs/tags/'
         for line in fh:
             line = line.strip()