Show More
@@ -29,7 +29,7 b" VERSION = (0, 5, 0, 'dev')" | |||
|
29 | 29 | __version__ = '.'.join((str(each) for each in VERSION[:4])) |
|
30 | 30 | |
|
31 | 31 | __all__ = [ |
|
32 |
'get_version', 'get_ |
|
|
32 | 'get_version', 'get_vcs_instance', 'get_backend', | |
|
33 | 33 | 'VCSError', 'RepositoryError', 'CommitError' |
|
34 | 34 | ] |
|
35 | 35 | |
@@ -44,7 +44,7 b' import Pyro4' | |||
|
44 | 44 | from Pyro4.errors import CommunicationError |
|
45 | 45 | |
|
46 | 46 | from rhodecode.lib.vcs.conf import settings |
|
47 |
from rhodecode.lib.vcs.backends import get_ |
|
|
47 | from rhodecode.lib.vcs.backends import get_vcs_instance, get_backend | |
|
48 | 48 | from rhodecode.lib.vcs.exceptions import ( |
|
49 | 49 | VCSError, RepositoryError, CommitError) |
|
50 | 50 |
@@ -22,7 +22,8 b'' | |||
|
22 | 22 | VCS Backends module |
|
23 | 23 | """ |
|
24 | 24 | |
|
25 |
import |
|
|
25 | import logging | |
|
26 | ||
|
26 | 27 | from pprint import pformat |
|
27 | 28 | |
|
28 | 29 | from rhodecode.lib.vcs.conf import settings |
@@ -31,31 +32,29 b' from rhodecode.lib.vcs.utils.helpers imp' | |||
|
31 | 32 | from rhodecode.lib.vcs.utils.imports import import_class |
|
32 | 33 | |
|
33 | 34 | |
|
34 | def get_repo(path=None, alias=None, create=False): | |
|
35 | log = logging.getLogger(__name__) | |
|
36 | ||
|
37 | ||
|
38 | def get_vcs_instance(repo_path, *args, **kwargs): | |
|
35 | 39 | """ |
|
36 | Returns ``Repository`` object of type linked with given ``alias`` at | |
|
37 | the specified ``path``. If ``alias`` is not given it will try to guess it | |
|
38 | using get_scm method | |
|
40 | Given a path to a repository an instance of the corresponding vcs backend | |
|
41 | repository class is created and returned. If no repository can be found | |
|
42 | for the path it returns None. Arguments and keyword arguments are passed | |
|
43 | to the vcs backend repository class. | |
|
39 | 44 | """ |
|
40 | if create: | |
|
41 | if not (path or alias): | |
|
42 | raise TypeError( | |
|
43 | "If create is specified, we need path and scm type") | |
|
44 | return get_backend(alias)(path, create=True) | |
|
45 | if path is None: | |
|
46 | path = os.path.abspath(os.path.curdir) | |
|
47 | 45 | try: |
|
48 | scm, path = get_scm(path, search_path_up=True) | |
|
49 | path = os.path.abspath(path) | |
|
50 | alias = scm | |
|
46 | vcs_alias = get_scm(repo_path)[0] | |
|
47 | log.debug( | |
|
48 | 'Creating instance of %s repository from %s', vcs_alias, repo_path) | |
|
49 | backend = get_backend(vcs_alias) | |
|
51 | 50 | except VCSError: |
|
52 | raise VCSError("No scm found at %s" % path) | |
|
53 | if alias is None: | |
|
54 | alias = get_scm(path)[0] | |
|
51 | log.exception( | |
|
52 | 'Perhaps this repository is in db and not in ' | |
|
53 | 'filesystem run rescan repositories with ' | |
|
54 | '"destroy old data" option from admin panel') | |
|
55 | return None | |
|
55 | 56 | |
|
56 | backend = get_backend(alias) | |
|
57 | repo = backend(path, create=create) | |
|
58 | return repo | |
|
57 | return backend(repo_path=repo_path, *args, **kwargs) | |
|
59 | 58 | |
|
60 | 59 | |
|
61 | 60 | def get_backend(alias): |
General Comments 0
You need to be logged in to leave comments.
Login now