hgext/convert/git.py
branchstable
changeset 28659 197eed39e3d5
parent 26779 aaa33ec3c951
child 28660 cdda7b96afff
equal deleted inserted replaced
28658:34d43cb85de8 28659:197eed39e3d5
     9 import subprocess
     9 import subprocess
    10 from mercurial import util, config, error
    10 from mercurial import util, config, error
    11 from mercurial.node import hex, nullid
    11 from mercurial.node import hex, nullid
    12 from mercurial.i18n import _
    12 from mercurial.i18n import _
    13 
    13 
    14 from common import NoRepo, commit, converter_source, checktool
    14 from common import NoRepo, commit, converter_source, checktool, commandline
    15 
    15 
    16 class submodule(object):
    16 class submodule(object):
    17     def __init__(self, path, node, url):
    17     def __init__(self, path, node, url):
    18         self.path = path
    18         self.path = path
    19         self.node = node
    19         self.node = node
    23         return "%s = [git]%s" % (self.path, self.url)
    23         return "%s = [git]%s" % (self.path, self.url)
    24 
    24 
    25     def hgsubstate(self):
    25     def hgsubstate(self):
    26         return "%s %s" % (self.node, self.path)
    26         return "%s %s" % (self.node, self.path)
    27 
    27 
    28 class convert_git(converter_source):
    28 class convert_git(converter_source, commandline):
    29     # Windows does not support GIT_DIR= construct while other systems
    29     # Windows does not support GIT_DIR= construct while other systems
    30     # cannot remove environment variable. Just assume none have
    30     # cannot remove environment variable. Just assume none have
    31     # both issues.
    31     # both issues.
    32     if util.safehasattr(os, 'unsetenv'):
    32     if util.safehasattr(os, 'unsetenv'):
    33         def gitopen(self, s, err=None):
    33         def gitopen(self, s, err=None):
    69                 return util.popen('GIT_DIR=%s %s' % (self.path, s), 'rb')
    69                 return util.popen('GIT_DIR=%s %s' % (self.path, s), 'rb')
    70 
    70 
    71         def gitpipe(self, s):
    71         def gitpipe(self, s):
    72             return util.popen3('GIT_DIR=%s %s' % (self.path, s))
    72             return util.popen3('GIT_DIR=%s %s' % (self.path, s))
    73 
    73 
       
    74     def _gitcmd(self, cmd, *args, **kwargs):
       
    75         return cmd('--git-dir=%s' % self.path, *args, **kwargs)
       
    76 
       
    77     def gitrun0(self, *args, **kwargs):
       
    78         return self._gitcmd(self.run0, *args, **kwargs)
       
    79 
       
    80     def gitrun(self, *args, **kwargs):
       
    81         return self._gitcmd(self.run, *args, **kwargs)
       
    82 
       
    83     def gitrunlines0(self, *args, **kwargs):
       
    84         return self._gitcmd(self.runlines0, *args, **kwargs)
       
    85 
       
    86     def gitrunlines(self, *args, **kwargs):
       
    87         return self._gitcmd(self.runlines, *args, **kwargs)
       
    88 
    74     def popen_with_stderr(self, s):
    89     def popen_with_stderr(self, s):
    75         p = subprocess.Popen(s, shell=True, bufsize=-1,
    90         p = subprocess.Popen(s, shell=True, bufsize=-1,
    76                              close_fds=util.closefds,
    91                              close_fds=util.closefds,
    77                              stdin=subprocess.PIPE,
    92                              stdin=subprocess.PIPE,
    78                              stdout=subprocess.PIPE,
    93                              stdout=subprocess.PIPE,
    86         data = fh.read()
   101         data = fh.read()
    87         return data, fh.close()
   102         return data, fh.close()
    88 
   103 
    89     def __init__(self, ui, path, revs=None):
   104     def __init__(self, ui, path, revs=None):
    90         super(convert_git, self).__init__(ui, path, revs=revs)
   105         super(convert_git, self).__init__(ui, path, revs=revs)
       
   106         commandline.__init__(self, ui, 'git')
    91 
   107 
    92         if os.path.isdir(path + "/.git"):
   108         if os.path.isdir(path + "/.git"):
    93             path += "/.git"
   109             path += "/.git"
    94         if not os.path.exists(path + "/objects"):
   110         if not os.path.exists(path + "/objects"):
    95             raise NoRepo(_("%s does not look like a Git repository") % path)
   111             raise NoRepo(_("%s does not look like a Git repository") % path)