Mercurial > kallithea
annotate rhodecode/lib/vcs/backends/git/repository.py @ 2706:22f79562836c beta
Fixed validators for remote repos
- use proper httppeer repo for mercurial 2.3
- validate git repos for remote auth
- docs updates
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 08 Aug 2012 22:37:40 +0200 |
parents | 959d0daa44da |
children | fd5f2b217488 |
rev | line source |
---|---|
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 vcs.backends.git |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 ~~~~~~~~~~~~~~~~ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 Git backend implementation. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 :created_on: Apr 8, 2010 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 :copyright: (c) 2010-2011 by Marcin Kuzminski, Lukasz Balcerzak. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 import os |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 import re |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 import time |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 import posixpath |
2676
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
16 import logging |
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
17 import traceback |
2704
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
18 import urllib |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
19 import urllib2 |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 from dulwich.repo import Repo, NotGitRepository |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 #from dulwich.config import ConfigFile |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 from string import Template |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 from subprocess import Popen, PIPE |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 from rhodecode.lib.vcs.backends.base import BaseRepository |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 from rhodecode.lib.vcs.exceptions import BranchDoesNotExistError |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 from rhodecode.lib.vcs.exceptions import ChangesetDoesNotExistError |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 from rhodecode.lib.vcs.exceptions import EmptyRepositoryError |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 from rhodecode.lib.vcs.exceptions import RepositoryError |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 from rhodecode.lib.vcs.exceptions import TagAlreadyExistError |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 from rhodecode.lib.vcs.exceptions import TagDoesNotExistError |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 from rhodecode.lib.vcs.utils import safe_unicode, makedate, date_fromtimestamp |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 from rhodecode.lib.vcs.utils.lazy import LazyProperty |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 from rhodecode.lib.vcs.utils.ordered_dict import OrderedDict |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 from rhodecode.lib.vcs.utils.paths import abspath |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 from rhodecode.lib.vcs.utils.paths import get_user_home |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 from .workdir import GitWorkdir |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 from .changeset import GitChangeset |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 from .inmemory import GitInMemoryChangeset |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 from .config import ConfigFile |
2676
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
40 from rhodecode.lib import subprocessio |
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
41 |
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
42 |
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
43 log = logging.getLogger(__name__) |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 class GitRepository(BaseRepository): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 Git repository backend. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 DEFAULT_BRANCH_NAME = 'master' |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 scm = 'git' |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 def __init__(self, repo_path, create=False, src_url=None, |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 update_after_clone=False, bare=False): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 self.path = abspath(repo_path) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 self._repo = self._get_repo(create, src_url, update_after_clone, bare) |
2209
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
58 #temporary set that to now at later we will move it to constructor |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
59 baseui = None |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
60 if baseui is None: |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
61 from mercurial.ui import ui |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
62 baseui = ui() |
2235
b6adef467e23
changelog update + whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2233
diff
changeset
|
63 # patch the instance of GitRepo with an "FAKE" ui object to add |
2209
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
64 # compatibility layer with Mercurial |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
65 setattr(self._repo, 'ui', baseui) |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
66 |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 try: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 self.head = self._repo.head() |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
69 except KeyError: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 self.head = None |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
72 self._config_files = [ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
73 bare and abspath(self.path, 'config') or abspath(self.path, '.git', |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 'config'), |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 abspath(get_user_home(), '.gitconfig'), |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 ] |
2320
48d93ea1e245
fixed issues with support of bare-repos by vcs lib
Marcin Kuzminski <marcin@python-works.com>
parents:
2235
diff
changeset
|
77 self.bare = self._repo.bare |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 @LazyProperty |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 def revisions(self): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
81 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 Returns list of revisions' ids, in ascending order. Being lazy |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 attribute allows external tools to inject shas from cache. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 return self._get_all_revisions() |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
87 def run_git_command(self, cmd): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
88 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
89 Runs given ``cmd`` as git command and returns tuple |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
90 (returncode, stdout, stderr). |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
91 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
92 .. note:: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
93 This method exists only until log/blame functionality is implemented |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
94 at Dulwich (see https://bugs.launchpad.net/bugs/645142). Parsing |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
95 os command's output is road to hell... |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
96 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
97 :param cmd: git command to be executed |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
98 """ |
2183
9d27481228a1
Extend GIT command wrapper with GIT_CONFIG_NOGLOBAL=1 to bypass gitconfig global
Marcin Kuzminski <marcin@python-works.com>
parents:
2047
diff
changeset
|
99 |
2199
31ebf7010566
various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents:
2198
diff
changeset
|
100 _copts = ['-c', 'core.quotepath=false', ] |
2200
d7a4c7e3528e
fixed git-command wrapper
Marcin Kuzminski <marcin@python-works.com>
parents:
2199
diff
changeset
|
101 _str_cmd = False |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
102 if isinstance(cmd, basestring): |
2199
31ebf7010566
various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents:
2198
diff
changeset
|
103 cmd = [cmd] |
2200
d7a4c7e3528e
fixed git-command wrapper
Marcin Kuzminski <marcin@python-works.com>
parents:
2199
diff
changeset
|
104 _str_cmd = True |
2367
86aa4f1f130b
white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2325
diff
changeset
|
105 |
2325
18d34a56a736
fix for issue #417, git execution was broken on windows for certain commands.
Marcin Kuzminski <marcin@python-works.com>
parents:
2320
diff
changeset
|
106 gitenv = os.environ |
2616
bab7eaa2cd7d
Remove GIT_DIT from environ on calling git_command, it can break a lot of stuff
Marcin Kuzminski <marcin@python-works.com>
parents:
2539
diff
changeset
|
107 # need to clean fix GIT_DIR ! |
bab7eaa2cd7d
Remove GIT_DIT from environ on calling git_command, it can break a lot of stuff
Marcin Kuzminski <marcin@python-works.com>
parents:
2539
diff
changeset
|
108 if 'GIT_DIR' in gitenv: |
bab7eaa2cd7d
Remove GIT_DIT from environ on calling git_command, it can break a lot of stuff
Marcin Kuzminski <marcin@python-works.com>
parents:
2539
diff
changeset
|
109 del gitenv['GIT_DIR'] |
2325
18d34a56a736
fix for issue #417, git execution was broken on windows for certain commands.
Marcin Kuzminski <marcin@python-works.com>
parents:
2320
diff
changeset
|
110 gitenv['GIT_CONFIG_NOGLOBAL'] = '1' |
2199
31ebf7010566
various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents:
2198
diff
changeset
|
111 |
2325
18d34a56a736
fix for issue #417, git execution was broken on windows for certain commands.
Marcin Kuzminski <marcin@python-works.com>
parents:
2320
diff
changeset
|
112 cmd = ['git'] + _copts + cmd |
2200
d7a4c7e3528e
fixed git-command wrapper
Marcin Kuzminski <marcin@python-works.com>
parents:
2199
diff
changeset
|
113 if _str_cmd: |
d7a4c7e3528e
fixed git-command wrapper
Marcin Kuzminski <marcin@python-works.com>
parents:
2199
diff
changeset
|
114 cmd = ' '.join(cmd) |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
115 try: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
116 opts = dict( |
2325
18d34a56a736
fix for issue #417, git execution was broken on windows for certain commands.
Marcin Kuzminski <marcin@python-works.com>
parents:
2320
diff
changeset
|
117 env=gitenv, |
18d34a56a736
fix for issue #417, git execution was broken on windows for certain commands.
Marcin Kuzminski <marcin@python-works.com>
parents:
2320
diff
changeset
|
118 ) |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
119 if os.path.isdir(self.path): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
120 opts['cwd'] = self.path |
2676
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
121 p = subprocessio.SubprocessIOChunker(cmd, **opts) |
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
122 except (EnvironmentError, OSError), err: |
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
123 log.error(traceback.format_exc()) |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
124 raise RepositoryError("Couldn't run git command (%s).\n" |
2676
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
125 "Original error was:%s" % (cmd, err)) |
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
126 |
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
127 so = ''.join(p) |
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
128 se = None |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
129 return so, se |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
130 |
2704
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
131 @classmethod |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
132 def _check_url(cls, url): |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
133 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
134 Functon will check given url and try to verify if it's a valid |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
135 link. Sometimes it may happened that mercurial will issue basic |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
136 auth request that can cause whole API to hang when used from python |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
137 or other external calls. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
138 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
139 On failures it'll raise urllib2.HTTPError |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
140 """ |
2704
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
141 from mercurial.util import url as Url |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
142 |
2704
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
143 # those authnadlers are patched for python 2.6.5 bug an |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
144 # infinit looping when given invalid resources |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
145 from mercurial.url import httpbasicauthhandler, httpdigestauthhandler |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
146 |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
147 # check first if it's not an local url |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
148 if os.path.isdir(url) or url.startswith('file:'): |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
149 return True |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
150 |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
151 if('+' in url[:url.find('://')]): |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
152 url = url[url.find('+') + 1:] |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
153 |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
154 handlers = [] |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
155 test_uri, authinfo = Url(url).authinfo() |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
156 if not test_uri.endswith('info/refs'): |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
157 test_uri = test_uri.rstrip('/') + '/info/refs' |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
158 if authinfo: |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
159 #create a password manager |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
160 passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm() |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
161 passmgr.add_password(*authinfo) |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
162 |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
163 handlers.extend((httpbasicauthhandler(passmgr), |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
164 httpdigestauthhandler(passmgr))) |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
165 |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
166 o = urllib2.build_opener(*handlers) |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
167 o.addheaders = [('User-Agent', 'git/1.7.8.0')] # fake some git |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
168 |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
169 q = {"service": 'git-upload-pack'} |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
170 qs = '?%s' % urllib.urlencode(q) |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
171 cu = "%s%s" % (test_uri, qs) |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
172 req = urllib2.Request(cu, None, {}) |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
173 |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
174 try: |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
175 resp = o.open(req) |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
176 return resp.code == 200 |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
177 except Exception, e: |
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
178 # means it cannot be cloned |
2706
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2704
diff
changeset
|
179 raise urllib2.URLError("[%s] %s" % (url, e)) |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
180 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
181 def _get_repo(self, create, src_url=None, update_after_clone=False, |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
182 bare=False): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
183 if create and os.path.exists(self.path): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
184 raise RepositoryError("Location already exist") |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
185 if src_url and not create: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
186 raise RepositoryError("Create should be set to True if src_url is " |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
187 "given (clone operation creates repository)") |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
188 try: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
189 if create and src_url: |
2704
959d0daa44da
Added url validator for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2676
diff
changeset
|
190 GitRepository._check_url(src_url) |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
191 self.clone(src_url, update_after_clone, bare) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
192 return Repo(self.path) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
193 elif create: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
194 os.mkdir(self.path) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
195 if bare: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
196 return Repo.init_bare(self.path) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
197 else: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
198 return Repo.init(self.path) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
199 else: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
200 return Repo(self.path) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
201 except (NotGitRepository, OSError), err: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
202 raise RepositoryError(err) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
203 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
204 def _get_all_revisions(self): |
2676
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
205 # we must check if this repo is not empty, since later command |
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
206 # fails if it is. And it's cheaper to ask than throw the subprocess |
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
207 # errors |
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
208 try: |
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
209 self._repo.head() |
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
210 except KeyError: |
1f4d4b8d72f5
switched git_command to subprocession for non-blocking Popen.
Marcin Kuzminski <marcin@python-works.com>
parents:
2616
diff
changeset
|
211 return [] |
2535
b24b1f0fa505
Get tags and branches using _parsed_refs
Marcin Kuzminski <marcin@python-works.com>
parents:
2453
diff
changeset
|
212 cmd = 'rev-list --all --reverse --date-order' |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
213 try: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
214 so, se = self.run_git_command(cmd) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
215 except RepositoryError: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
216 # Can be raised for empty repositories |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
217 return [] |
2535
b24b1f0fa505
Get tags and branches using _parsed_refs
Marcin Kuzminski <marcin@python-works.com>
parents:
2453
diff
changeset
|
218 return so.splitlines() |
b24b1f0fa505
Get tags and branches using _parsed_refs
Marcin Kuzminski <marcin@python-works.com>
parents:
2453
diff
changeset
|
219 |
b24b1f0fa505
Get tags and branches using _parsed_refs
Marcin Kuzminski <marcin@python-works.com>
parents:
2453
diff
changeset
|
220 def _get_all_revisions2(self): |
b24b1f0fa505
Get tags and branches using _parsed_refs
Marcin Kuzminski <marcin@python-works.com>
parents:
2453
diff
changeset
|
221 #alternate implementation using dulwich |
b24b1f0fa505
Get tags and branches using _parsed_refs
Marcin Kuzminski <marcin@python-works.com>
parents:
2453
diff
changeset
|
222 includes = [x[1][0] for x in self._parsed_refs.iteritems() |
b24b1f0fa505
Get tags and branches using _parsed_refs
Marcin Kuzminski <marcin@python-works.com>
parents:
2453
diff
changeset
|
223 if x[1][1] != 'T'] |
b24b1f0fa505
Get tags and branches using _parsed_refs
Marcin Kuzminski <marcin@python-works.com>
parents:
2453
diff
changeset
|
224 return [c.commit.id for c in self._repo.get_walker(include=includes)] |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
225 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
226 def _get_revision(self, revision): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
227 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
228 For git backend we always return integer here. This way we ensure |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
229 that changset's revision attribute would become integer. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
230 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
231 pattern = re.compile(r'^[[0-9a-fA-F]{12}|[0-9a-fA-F]{40}]$') |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
232 is_bstr = lambda o: isinstance(o, (str, unicode)) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
233 is_null = lambda o: len(o) == revision.count('0') |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
234 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
235 if len(self.revisions) == 0: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
236 raise EmptyRepositoryError("There are no changesets yet") |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
237 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
238 if revision in (None, '', 'tip', 'HEAD', 'head', -1): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
239 revision = self.revisions[-1] |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
240 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
241 if ((is_bstr(revision) and revision.isdigit() and len(revision) < 12) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
242 or isinstance(revision, int) or is_null(revision)): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
243 try: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
244 revision = self.revisions[int(revision)] |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
245 except: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
246 raise ChangesetDoesNotExistError("Revision %r does not exist " |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
247 "for this repository %s" % (revision, self)) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
248 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
249 elif is_bstr(revision): |
2536
aaa41736ae51
Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents:
2535
diff
changeset
|
250 # get by branch/tag name |
2449
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
251 _ref_revision = self._parsed_refs.get(revision) |
2536
aaa41736ae51
Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents:
2535
diff
changeset
|
252 _tags_shas = self.tags.values() |
2449
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
253 if _ref_revision: # and _ref_revision[1] in ['H', 'RH', 'T']: |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
254 return _ref_revision[0] |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
255 |
2536
aaa41736ae51
Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents:
2535
diff
changeset
|
256 # maybe it's a tag ? we don't have them in self.revisions |
aaa41736ae51
Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents:
2535
diff
changeset
|
257 elif revision in _tags_shas: |
aaa41736ae51
Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents:
2535
diff
changeset
|
258 return _tags_shas[_tags_shas.index(revision)] |
aaa41736ae51
Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents:
2535
diff
changeset
|
259 |
2449
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
260 elif not pattern.match(revision) or revision not in self.revisions: |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
261 raise ChangesetDoesNotExistError("Revision %r does not exist " |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
262 "for this repository %s" % (revision, self)) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
263 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
264 # Ensure we return full id |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
265 if not pattern.match(str(revision)): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
266 raise ChangesetDoesNotExistError("Given revision %r not recognized" |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
267 % revision) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
268 return revision |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
269 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
270 def _get_archives(self, archive_name='tip'): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
271 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
272 for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
273 yield {"type": i[0], "extension": i[1], "node": archive_name} |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
274 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
275 def _get_url(self, url): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
276 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
277 Returns normalized url. If schema is not given, would fall to |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
278 filesystem (``file:///``) schema. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
279 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
280 url = str(url) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
281 if url != 'default' and not '://' in url: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
282 url = ':///'.join(('file', url)) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
283 return url |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
284 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
285 @LazyProperty |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
286 def name(self): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
287 return os.path.basename(self.path) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
288 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
289 @LazyProperty |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
290 def last_change(self): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
291 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
292 Returns last change made on this repository as datetime object |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
293 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
294 return date_fromtimestamp(self._get_mtime(), makedate()[1]) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
295 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
296 def _get_mtime(self): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
297 try: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
298 return time.mktime(self.get_changeset().date.timetuple()) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
299 except RepositoryError: |
2320
48d93ea1e245
fixed issues with support of bare-repos by vcs lib
Marcin Kuzminski <marcin@python-works.com>
parents:
2235
diff
changeset
|
300 idx_loc = '' if self.bare else '.git' |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
301 # fallback to filesystem |
2320
48d93ea1e245
fixed issues with support of bare-repos by vcs lib
Marcin Kuzminski <marcin@python-works.com>
parents:
2235
diff
changeset
|
302 in_path = os.path.join(self.path, idx_loc, "index") |
48d93ea1e245
fixed issues with support of bare-repos by vcs lib
Marcin Kuzminski <marcin@python-works.com>
parents:
2235
diff
changeset
|
303 he_path = os.path.join(self.path, idx_loc, "HEAD") |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
304 if os.path.exists(in_path): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
305 return os.stat(in_path).st_mtime |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
306 else: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
307 return os.stat(he_path).st_mtime |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
308 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
309 @LazyProperty |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
310 def description(self): |
2320
48d93ea1e245
fixed issues with support of bare-repos by vcs lib
Marcin Kuzminski <marcin@python-works.com>
parents:
2235
diff
changeset
|
311 idx_loc = '' if self.bare else '.git' |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
312 undefined_description = u'unknown' |
2320
48d93ea1e245
fixed issues with support of bare-repos by vcs lib
Marcin Kuzminski <marcin@python-works.com>
parents:
2235
diff
changeset
|
313 description_path = os.path.join(self.path, idx_loc, 'description') |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
314 if os.path.isfile(description_path): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
315 return safe_unicode(open(description_path).read()) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
316 else: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
317 return undefined_description |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
318 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
319 @LazyProperty |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
320 def contact(self): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
321 undefined_contact = u'Unknown' |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
322 return undefined_contact |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
323 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
324 @property |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
325 def branches(self): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
326 if not self.revisions: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
327 return {} |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
328 sortkey = lambda ctx: ctx[0] |
2535
b24b1f0fa505
Get tags and branches using _parsed_refs
Marcin Kuzminski <marcin@python-works.com>
parents:
2453
diff
changeset
|
329 _branches = [(x[0], x[1][0]) |
b24b1f0fa505
Get tags and branches using _parsed_refs
Marcin Kuzminski <marcin@python-works.com>
parents:
2453
diff
changeset
|
330 for x in self._parsed_refs.iteritems() if x[1][1] == 'H'] |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
331 return OrderedDict(sorted(_branches, key=sortkey, reverse=False)) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
332 |
2449
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
333 @LazyProperty |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
334 def tags(self): |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
335 return self._get_tags() |
2198
9784a54a0f5b
display current heads of branches for git in changelog and shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
2183
diff
changeset
|
336 |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
337 def _get_tags(self): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
338 if not self.revisions: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
339 return {} |
2535
b24b1f0fa505
Get tags and branches using _parsed_refs
Marcin Kuzminski <marcin@python-works.com>
parents:
2453
diff
changeset
|
340 |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
341 sortkey = lambda ctx: ctx[0] |
2535
b24b1f0fa505
Get tags and branches using _parsed_refs
Marcin Kuzminski <marcin@python-works.com>
parents:
2453
diff
changeset
|
342 _tags = [(x[0], x[1][0]) |
b24b1f0fa505
Get tags and branches using _parsed_refs
Marcin Kuzminski <marcin@python-works.com>
parents:
2453
diff
changeset
|
343 for x in self._parsed_refs.iteritems() if x[1][1] == 'T'] |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
344 return OrderedDict(sorted(_tags, key=sortkey, reverse=True)) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
345 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
346 def tag(self, name, user, revision=None, message=None, date=None, |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
347 **kwargs): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
348 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
349 Creates and returns a tag for the given ``revision``. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
350 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
351 :param name: name for new tag |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
352 :param user: full username, i.e.: "Joe Doe <joe.doe@example.com>" |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
353 :param revision: changeset id for which new tag would be created |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
354 :param message: message of the tag's commit |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
355 :param date: date of tag's commit |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
356 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
357 :raises TagAlreadyExistError: if tag with same name already exists |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
358 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
359 if name in self.tags: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
360 raise TagAlreadyExistError("Tag %s already exists" % name) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
361 changeset = self.get_changeset(revision) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
362 message = message or "Added tag %s for commit %s" % (name, |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
363 changeset.raw_id) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
364 self._repo.refs["refs/tags/%s" % name] = changeset._commit.id |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
365 |
2539
da18c423b100
Invalidate gits parsed_refs cache after commit, tagging or tag remove
Marcin Kuzminski <marcin@python-works.com>
parents:
2536
diff
changeset
|
366 self._parsed_refs = self._get_parsed_refs() |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
367 self.tags = self._get_tags() |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
368 return changeset |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
369 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
370 def remove_tag(self, name, user, message=None, date=None): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
371 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
372 Removes tag with the given ``name``. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
373 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
374 :param name: name of the tag to be removed |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
375 :param user: full username, i.e.: "Joe Doe <joe.doe@example.com>" |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
376 :param message: message of the tag's removal commit |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
377 :param date: date of tag's removal commit |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
378 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
379 :raises TagDoesNotExistError: if tag with given name does not exists |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
380 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
381 if name not in self.tags: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
382 raise TagDoesNotExistError("Tag %s does not exist" % name) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
383 tagpath = posixpath.join(self._repo.refs.path, 'refs', 'tags', name) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
384 try: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
385 os.remove(tagpath) |
2539
da18c423b100
Invalidate gits parsed_refs cache after commit, tagging or tag remove
Marcin Kuzminski <marcin@python-works.com>
parents:
2536
diff
changeset
|
386 self._parsed_refs = self._get_parsed_refs() |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
387 self.tags = self._get_tags() |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
388 except OSError, e: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
389 raise RepositoryError(e.strerror) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
390 |
2449
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
391 @LazyProperty |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
392 def _parsed_refs(self): |
2539
da18c423b100
Invalidate gits parsed_refs cache after commit, tagging or tag remove
Marcin Kuzminski <marcin@python-works.com>
parents:
2536
diff
changeset
|
393 return self._get_parsed_refs() |
da18c423b100
Invalidate gits parsed_refs cache after commit, tagging or tag remove
Marcin Kuzminski <marcin@python-works.com>
parents:
2536
diff
changeset
|
394 |
da18c423b100
Invalidate gits parsed_refs cache after commit, tagging or tag remove
Marcin Kuzminski <marcin@python-works.com>
parents:
2536
diff
changeset
|
395 def _get_parsed_refs(self): |
2449
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
396 refs = self._repo.get_refs() |
2453
d2a528b60e50
whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2449
diff
changeset
|
397 keys = [('refs/heads/', 'H'), |
2449
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
398 ('refs/remotes/origin/', 'RH'), |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
399 ('refs/tags/', 'T')] |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
400 _refs = {} |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
401 for ref, sha in refs.iteritems(): |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
402 for k, type_ in keys: |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
403 if ref.startswith(k): |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
404 _key = ref[len(k):] |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
405 _refs[_key] = [sha, type_] |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
406 break |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
407 return _refs |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
408 |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
409 def _heads(self, reverse=False): |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
410 refs = self._repo.get_refs() |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
411 heads = {} |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
412 |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
413 for key, val in refs.items(): |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
414 for ref_key in ['refs/heads/', 'refs/remotes/origin/']: |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
415 if key.startswith(ref_key): |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
416 n = key[len(ref_key):] |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
417 if n not in ['HEAD']: |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
418 heads[n] = val |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
419 |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
420 return heads if reverse else dict((y, x) for x, y in heads.iteritems()) |
08fc67c1c948
added discovery by branches and tags for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
421 |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
422 def get_changeset(self, revision=None): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
423 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
424 Returns ``GitChangeset`` object representing commit from git repository |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
425 at the given revision or head (most recent commit) if None given. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
426 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
427 if isinstance(revision, GitChangeset): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
428 return revision |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
429 revision = self._get_revision(revision) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
430 changeset = GitChangeset(repository=self, revision=revision) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
431 return changeset |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
432 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
433 def get_changesets(self, start=None, end=None, start_date=None, |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
434 end_date=None, branch_name=None, reverse=False): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
435 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
436 Returns iterator of ``GitChangeset`` objects from start to end (both |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
437 are inclusive), in ascending date order (unless ``reverse`` is set). |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
438 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
439 :param start: changeset ID, as str; first returned changeset |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
440 :param end: changeset ID, as str; last returned changeset |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
441 :param start_date: if specified, changesets with commit date less than |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
442 ``start_date`` would be filtered out from returned set |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
443 :param end_date: if specified, changesets with commit date greater than |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
444 ``end_date`` would be filtered out from returned set |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
445 :param branch_name: if specified, changesets not reachable from given |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
446 branch would be filtered out from returned set |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
447 :param reverse: if ``True``, returned generator would be reversed |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
448 (meaning that returned changesets would have descending date order) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
449 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
450 :raise BranchDoesNotExistError: If given ``branch_name`` does not |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
451 exist. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
452 :raise ChangesetDoesNotExistError: If changeset for given ``start`` or |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
453 ``end`` could not be found. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
454 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
455 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
456 if branch_name and branch_name not in self.branches: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
457 raise BranchDoesNotExistError("Branch '%s' not found" \ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
458 % branch_name) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
459 # %H at format means (full) commit hash, initial hashes are retrieved |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
460 # in ascending date order |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
461 cmd_template = 'log --date-order --reverse --pretty=format:"%H"' |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
462 cmd_params = {} |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
463 if start_date: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
464 cmd_template += ' --since "$since"' |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
465 cmd_params['since'] = start_date.strftime('%m/%d/%y %H:%M:%S') |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
466 if end_date: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
467 cmd_template += ' --until "$until"' |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
468 cmd_params['until'] = end_date.strftime('%m/%d/%y %H:%M:%S') |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
469 if branch_name: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
470 cmd_template += ' $branch_name' |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
471 cmd_params['branch_name'] = branch_name |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
472 else: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
473 cmd_template += ' --all' |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
474 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
475 cmd = Template(cmd_template).safe_substitute(**cmd_params) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
476 revs = self.run_git_command(cmd)[0].splitlines() |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
477 start_pos = 0 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
478 end_pos = len(revs) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
479 if start: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
480 _start = self._get_revision(start) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
481 try: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
482 start_pos = revs.index(_start) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
483 except ValueError: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
484 pass |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
485 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
486 if end is not None: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
487 _end = self._get_revision(end) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
488 try: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
489 end_pos = revs.index(_end) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
490 except ValueError: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
491 pass |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
492 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
493 if None not in [start, end] and start_pos > end_pos: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
494 raise RepositoryError('start cannot be after end') |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
495 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
496 if end_pos is not None: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
497 end_pos += 1 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
498 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
499 revs = revs[start_pos:end_pos] |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
500 if reverse: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
501 revs = reversed(revs) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
502 for rev in revs: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
503 yield self.get_changeset(rev) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
504 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
505 def get_diff(self, rev1, rev2, path=None, ignore_whitespace=False, |
2233
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2210
diff
changeset
|
506 context=3): |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
507 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
508 Returns (git like) *diff*, as plain text. Shows changes introduced by |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
509 ``rev2`` since ``rev1``. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
510 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
511 :param rev1: Entry point from which diff is shown. Can be |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
512 ``self.EMPTY_CHANGESET`` - in this case, patch showing all |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
513 the changes since empty state of the repository until ``rev2`` |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
514 :param rev2: Until which revision changes should be shown. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
515 :param ignore_whitespace: If set to ``True``, would not show whitespace |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
516 changes. Defaults to ``False``. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
517 :param context: How many lines before/after changed lines should be |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
518 shown. Defaults to ``3``. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
519 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
520 flags = ['-U%s' % context] |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
521 if ignore_whitespace: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
522 flags.append('-w') |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
523 |
2384
5563af834d92
Added diff option into git and hg changeset objects, representing git formated patch against parent1
Marcin Kuzminski <marcin@python-works.com>
parents:
2383
diff
changeset
|
524 if hasattr(rev1, 'raw_id'): |
5563af834d92
Added diff option into git and hg changeset objects, representing git formated patch against parent1
Marcin Kuzminski <marcin@python-works.com>
parents:
2383
diff
changeset
|
525 rev1 = getattr(rev1, 'raw_id') |
5563af834d92
Added diff option into git and hg changeset objects, representing git formated patch against parent1
Marcin Kuzminski <marcin@python-works.com>
parents:
2383
diff
changeset
|
526 |
5563af834d92
Added diff option into git and hg changeset objects, representing git formated patch against parent1
Marcin Kuzminski <marcin@python-works.com>
parents:
2383
diff
changeset
|
527 if hasattr(rev2, 'raw_id'): |
5563af834d92
Added diff option into git and hg changeset objects, representing git formated patch against parent1
Marcin Kuzminski <marcin@python-works.com>
parents:
2383
diff
changeset
|
528 rev2 = getattr(rev2, 'raw_id') |
5563af834d92
Added diff option into git and hg changeset objects, representing git formated patch against parent1
Marcin Kuzminski <marcin@python-works.com>
parents:
2383
diff
changeset
|
529 |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
530 if rev1 == self.EMPTY_CHANGESET: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
531 rev2 = self.get_changeset(rev2).raw_id |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
532 cmd = ' '.join(['show'] + flags + [rev2]) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
533 else: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
534 rev1 = self.get_changeset(rev1).raw_id |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
535 rev2 = self.get_changeset(rev2).raw_id |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
536 cmd = ' '.join(['diff'] + flags + [rev1, rev2]) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
537 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
538 if path: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
539 cmd += ' -- "%s"' % path |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
540 stdout, stderr = self.run_git_command(cmd) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
541 # If we used 'show' command, strip first few lines (until actual diff |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
542 # starts) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
543 if rev1 == self.EMPTY_CHANGESET: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
544 lines = stdout.splitlines() |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
545 x = 0 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
546 for line in lines: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
547 if line.startswith('diff'): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
548 break |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
549 x += 1 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
550 # Append new line just like 'diff' command do |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
551 stdout = '\n'.join(lines[x:]) + '\n' |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
552 return stdout |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
553 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
554 @LazyProperty |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
555 def in_memory_changeset(self): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
556 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
557 Returns ``GitInMemoryChangeset`` object for this repository. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
558 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
559 return GitInMemoryChangeset(self) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
560 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
561 def clone(self, url, update_after_clone=True, bare=False): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
562 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
563 Tries to clone changes from external location. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
564 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
565 :param update_after_clone: If set to ``False``, git won't checkout |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
566 working directory |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
567 :param bare: If set to ``True``, repository would be cloned into |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
568 *bare* git repository (no working directory at all). |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
569 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
570 url = self._get_url(url) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
571 cmd = ['clone'] |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
572 if bare: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
573 cmd.append('--bare') |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
574 elif not update_after_clone: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
575 cmd.append('--no-checkout') |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
576 cmd += ['--', '"%s"' % url, '"%s"' % self.path] |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
577 cmd = ' '.join(cmd) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
578 # If error occurs run_git_command raises RepositoryError already |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
579 self.run_git_command(cmd) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
580 |
2209
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
581 def pull(self, url): |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
582 """ |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
583 Tries to pull changes from external location. |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
584 """ |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
585 url = self._get_url(url) |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
586 cmd = ['pull'] |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
587 cmd.append("--ff-only") |
2210
7b458dd6f40d
pass in url for remote pull in git
Marcin Kuzminski <marcin@python-works.com>
parents:
2209
diff
changeset
|
588 cmd.append(url) |
2209
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
589 cmd = ' '.join(cmd) |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
590 # If error occurs run_git_command raises RepositoryError already |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
591 self.run_git_command(cmd) |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2200
diff
changeset
|
592 |
2383
e576410f911d
Don't do git pull on remote repos since they are bare now, we need to use git fetch on them
Marcin Kuzminski <marcin@python-works.com>
parents:
2367
diff
changeset
|
593 def fetch(self, url): |
e576410f911d
Don't do git pull on remote repos since they are bare now, we need to use git fetch on them
Marcin Kuzminski <marcin@python-works.com>
parents:
2367
diff
changeset
|
594 """ |
e576410f911d
Don't do git pull on remote repos since they are bare now, we need to use git fetch on them
Marcin Kuzminski <marcin@python-works.com>
parents:
2367
diff
changeset
|
595 Tries to pull changes from external location. |
e576410f911d
Don't do git pull on remote repos since they are bare now, we need to use git fetch on them
Marcin Kuzminski <marcin@python-works.com>
parents:
2367
diff
changeset
|
596 """ |
e576410f911d
Don't do git pull on remote repos since they are bare now, we need to use git fetch on them
Marcin Kuzminski <marcin@python-works.com>
parents:
2367
diff
changeset
|
597 url = self._get_url(url) |
e576410f911d
Don't do git pull on remote repos since they are bare now, we need to use git fetch on them
Marcin Kuzminski <marcin@python-works.com>
parents:
2367
diff
changeset
|
598 cmd = ['fetch'] |
e576410f911d
Don't do git pull on remote repos since they are bare now, we need to use git fetch on them
Marcin Kuzminski <marcin@python-works.com>
parents:
2367
diff
changeset
|
599 cmd.append(url) |
e576410f911d
Don't do git pull on remote repos since they are bare now, we need to use git fetch on them
Marcin Kuzminski <marcin@python-works.com>
parents:
2367
diff
changeset
|
600 cmd = ' '.join(cmd) |
e576410f911d
Don't do git pull on remote repos since they are bare now, we need to use git fetch on them
Marcin Kuzminski <marcin@python-works.com>
parents:
2367
diff
changeset
|
601 # If error occurs run_git_command raises RepositoryError already |
e576410f911d
Don't do git pull on remote repos since they are bare now, we need to use git fetch on them
Marcin Kuzminski <marcin@python-works.com>
parents:
2367
diff
changeset
|
602 self.run_git_command(cmd) |
e576410f911d
Don't do git pull on remote repos since they are bare now, we need to use git fetch on them
Marcin Kuzminski <marcin@python-works.com>
parents:
2367
diff
changeset
|
603 |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
604 @LazyProperty |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
605 def workdir(self): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
606 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
607 Returns ``Workdir`` instance for this repository. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
608 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
609 return GitWorkdir(self) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
610 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
611 def get_config_value(self, section, name, config_file=None): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
612 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
613 Returns configuration value for a given [``section``] and ``name``. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
614 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
615 :param section: Section we want to retrieve value from |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
616 :param name: Name of configuration we want to retrieve |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
617 :param config_file: A path to file which should be used to retrieve |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
618 configuration from (might also be a list of file paths) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
619 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
620 if config_file is None: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
621 config_file = [] |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
622 elif isinstance(config_file, basestring): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
623 config_file = [config_file] |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
624 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
625 def gen_configs(): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
626 for path in config_file + self._config_files: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
627 try: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
628 yield ConfigFile.from_path(path) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
629 except (IOError, OSError, ValueError): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
630 continue |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
631 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
632 for config in gen_configs(): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
633 try: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
634 return config.get(section, name) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
635 except KeyError: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
636 continue |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
637 return None |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
638 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
639 def get_user_name(self, config_file=None): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
640 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
641 Returns user's name from global configuration file. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
642 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
643 :param config_file: A path to file which should be used to retrieve |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
644 configuration from (might also be a list of file paths) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
645 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
646 return self.get_config_value('user', 'name', config_file) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
647 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
648 def get_user_email(self, config_file=None): |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
649 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
650 Returns user's email from global configuration file. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
651 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
652 :param config_file: A path to file which should be used to retrieve |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
653 configuration from (might also be a list of file paths) |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
654 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
655 return self.get_config_value('user', 'email', config_file) |