# HG changeset patch # User Brendan Cully # Date 1183349348 25200 # Node ID 39e6deaa8b81d3a4b15faeaef28f6b88490fa9ce # Parent 74723744d8e0c664c90c0ac4f6392c63aabe2b6e convert: gitcmd wrapper for os.popen diff --git a/hgext/convert/git.py b/hgext/convert/git.py --- a/hgext/convert/git.py +++ b/hgext/convert/git.py @@ -14,6 +14,9 @@ def recode(s): 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 @@ class convert_git(converter_source): 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 @@ class convert_git(converter_source): 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 @@ class convert_git(converter_source): 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()