840 return self._svncommand(['cat'], name)[0] |
840 return self._svncommand(['cat'], name)[0] |
841 |
841 |
842 |
842 |
843 class gitsubrepo(abstractsubrepo): |
843 class gitsubrepo(abstractsubrepo): |
844 def __init__(self, ctx, path, state): |
844 def __init__(self, ctx, path, state): |
845 # TODO add git version check. |
|
846 self._state = state |
845 self._state = state |
847 self._ctx = ctx |
846 self._ctx = ctx |
848 self._path = path |
847 self._path = path |
849 self._relpath = os.path.join(reporelpath(ctx._repo), path) |
848 self._relpath = os.path.join(reporelpath(ctx._repo), path) |
850 self._abspath = ctx._repo.wjoin(path) |
849 self._abspath = ctx._repo.wjoin(path) |
851 self._subparent = ctx._repo |
850 self._subparent = ctx._repo |
852 self._ui = ctx._repo.ui |
851 self._ui = ctx._repo.ui |
|
852 self._ensuregit() |
|
853 |
|
854 def _ensuregit(self): |
|
855 try: |
|
856 self._gitexecutable = 'git' |
|
857 out, err = self._gitnodir(['--version']) |
|
858 except OSError, e: |
|
859 if e.errno != 2 or os.name != 'nt': |
|
860 raise |
|
861 self._gitexecutable = 'git.cmd' |
|
862 out, err = self._gitnodir(['--version']) |
|
863 m = re.search(r'^git version (\d+)\.(\d+)\.(\d+)', out) |
|
864 if not m: |
|
865 self._ui.warn(_('cannot retrieve git version')) |
|
866 return |
|
867 version = (int(m.group(1)), m.group(2), m.group(3)) |
|
868 # git 1.4.0 can't work at all, but 1.5.X can in at least some cases, |
|
869 # despite the docstring comment. For now, error on 1.4.0, warn on |
|
870 # 1.5.0 but attempt to continue. |
|
871 if version < (1, 5, 0): |
|
872 raise util.Abort(_('git subrepo requires at least 1.6.0 or later')) |
|
873 elif version < (1, 6, 0): |
|
874 self._ui.warn(_('git subrepo requires at least 1.6.0 or later')) |
853 |
875 |
854 def _gitcommand(self, commands, env=None, stream=False): |
876 def _gitcommand(self, commands, env=None, stream=False): |
855 return self._gitdir(commands, env=env, stream=stream)[0] |
877 return self._gitdir(commands, env=env, stream=stream)[0] |
856 |
878 |
857 def _gitdir(self, commands, env=None, stream=False): |
879 def _gitdir(self, commands, env=None, stream=False): |
868 # unless ui.quiet is set, print git's stderr, |
890 # unless ui.quiet is set, print git's stderr, |
869 # which is mostly progress and useful info |
891 # which is mostly progress and useful info |
870 errpipe = None |
892 errpipe = None |
871 if self._ui.quiet: |
893 if self._ui.quiet: |
872 errpipe = open(os.devnull, 'w') |
894 errpipe = open(os.devnull, 'w') |
873 p = subprocess.Popen(['git'] + commands, bufsize=-1, cwd=cwd, env=env, |
895 p = subprocess.Popen([self._gitexecutable] + commands, bufsize=-1, |
874 close_fds=util.closefds, |
896 cwd=cwd, env=env, close_fds=util.closefds, |
875 stdout=subprocess.PIPE, stderr=errpipe) |
897 stdout=subprocess.PIPE, stderr=errpipe) |
876 if stream: |
898 if stream: |
877 return p.stdout, None |
899 return p.stdout, None |
878 |
900 |
879 retdata = p.stdout.read().strip() |
901 retdata = p.stdout.read().strip() |