Mercurial > kallithea
comparison rhodecode/lib/vcs/backends/git/repository.py @ 3376:e67b2ef07a8e beta
git executable is now configurable via .ini files
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 17 Feb 2013 22:58:09 +0100 |
parents | a64e663abda3 |
children | 3faf7a7eebb3 |
comparison
equal
deleted
inserted
replaced
3375:7000fc4aa569 | 3376:e67b2ef07a8e |
---|---|
18 import urllib | 18 import urllib |
19 import urllib2 | 19 import urllib2 |
20 from dulwich.repo import Repo, NotGitRepository | 20 from dulwich.repo import Repo, NotGitRepository |
21 from dulwich.objects import Tag | 21 from dulwich.objects import Tag |
22 from string import Template | 22 from string import Template |
23 from subprocess import Popen, PIPE | 23 |
24 import rhodecode | |
24 from rhodecode.lib.vcs.backends.base import BaseRepository | 25 from rhodecode.lib.vcs.backends.base import BaseRepository |
25 from rhodecode.lib.vcs.exceptions import BranchDoesNotExistError | 26 from rhodecode.lib.vcs.exceptions import BranchDoesNotExistError |
26 from rhodecode.lib.vcs.exceptions import ChangesetDoesNotExistError | 27 from rhodecode.lib.vcs.exceptions import ChangesetDoesNotExistError |
27 from rhodecode.lib.vcs.exceptions import EmptyRepositoryError | 28 from rhodecode.lib.vcs.exceptions import EmptyRepositoryError |
28 from rhodecode.lib.vcs.exceptions import RepositoryError | 29 from rhodecode.lib.vcs.exceptions import RepositoryError |
89 Returns list of revisions' ids, in ascending order. Being lazy | 90 Returns list of revisions' ids, in ascending order. Being lazy |
90 attribute allows external tools to inject shas from cache. | 91 attribute allows external tools to inject shas from cache. |
91 """ | 92 """ |
92 return self._get_all_revisions() | 93 return self._get_all_revisions() |
93 | 94 |
94 def run_git_command(self, cmd): | 95 @classmethod |
96 def _run_git_command(cls, cmd, **opts): | |
95 """ | 97 """ |
96 Runs given ``cmd`` as git command and returns tuple | 98 Runs given ``cmd`` as git command and returns tuple |
97 (returncode, stdout, stderr). | 99 (stdout, stderr). |
98 | |
99 .. note:: | |
100 This method exists only until log/blame functionality is implemented | |
101 at Dulwich (see https://bugs.launchpad.net/bugs/645142). Parsing | |
102 os command's output is road to hell... | |
103 | 100 |
104 :param cmd: git command to be executed | 101 :param cmd: git command to be executed |
102 :param opts: env options to pass into Subprocess command | |
105 """ | 103 """ |
106 | 104 |
107 _copts = ['-c', 'core.quotepath=false', ] | 105 _copts = ['-c', 'core.quotepath=false', ] |
108 _str_cmd = False | 106 _str_cmd = False |
109 if isinstance(cmd, basestring): | 107 if isinstance(cmd, basestring): |
114 # need to clean fix GIT_DIR ! | 112 # need to clean fix GIT_DIR ! |
115 if 'GIT_DIR' in gitenv: | 113 if 'GIT_DIR' in gitenv: |
116 del gitenv['GIT_DIR'] | 114 del gitenv['GIT_DIR'] |
117 gitenv['GIT_CONFIG_NOGLOBAL'] = '1' | 115 gitenv['GIT_CONFIG_NOGLOBAL'] = '1' |
118 | 116 |
119 cmd = ['git'] + _copts + cmd | 117 _git_path = rhodecode.CONFIG.get('git_path', 'git') |
118 cmd = [_git_path] + _copts + cmd | |
120 if _str_cmd: | 119 if _str_cmd: |
121 cmd = ' '.join(cmd) | 120 cmd = ' '.join(cmd) |
122 try: | 121 try: |
123 opts = dict( | 122 _opts = dict( |
124 env=gitenv, | 123 env=gitenv, |
125 shell=False, | 124 shell=False, |
126 ) | 125 ) |
127 if os.path.isdir(self.path): | 126 _opts.update(opts) |
128 opts['cwd'] = self.path | 127 p = subprocessio.SubprocessIOChunker(cmd, **_opts) |
129 p = subprocessio.SubprocessIOChunker(cmd, **opts) | |
130 except (EnvironmentError, OSError), err: | 128 except (EnvironmentError, OSError), err: |
131 log.error(traceback.format_exc()) | 129 log.error(traceback.format_exc()) |
132 raise RepositoryError("Couldn't run git command (%s).\n" | 130 raise RepositoryError("Couldn't run git command (%s).\n" |
133 "Original error was:%s" % (cmd, err)) | 131 "Original error was:%s" % (cmd, err)) |
134 | 132 |
135 return ''.join(p.output), ''.join(p.error) | 133 return ''.join(p.output), ''.join(p.error) |
134 | |
135 def run_git_command(self, cmd): | |
136 opts = {} | |
137 if os.path.isdir(self.path): | |
138 opts['cwd'] = self.path | |
139 return self._run_git_command(cmd, **opts) | |
136 | 140 |
137 @classmethod | 141 @classmethod |
138 def _check_url(cls, url): | 142 def _check_url(cls, url): |
139 """ | 143 """ |
140 Functon will check given url and try to verify if it's a valid | 144 Functon will check given url and try to verify if it's a valid |