changeset 4767:2d0a823cbba5

convert: gitcmd wrapper for os.popen
author Brendan Cully <brendan@kublai.com>
date Sun, 01 Jul 2007 21:09:08 -0700
parents 95cbb6b74790
children f52bfe566583
files hgext/convert/git.py
diffstat 1 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/git.py	Sun Jul 01 20:30:04 2007 -0700
+++ b/hgext/convert/git.py	Sun Jul 01 21:09:08 2007 -0700
@@ -5,6 +5,9 @@
 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))
+
     def __init__(self, ui, path, rev=None):
         if os.path.isdir(path + "/.git"):
             path += "/.git"
@@ -18,13 +21,12 @@
 
     def getheads(self):
         rev = self.rev or 'HEAD'
-        fh = os.popen("GIT_DIR=%s git-rev-parse --verify %s" % (self.path, rev))
+        fh = self.gitcmd("git-rev-parse --verify %s" % rev)
         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):
@@ -35,8 +37,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
@@ -84,7 +85,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()