##// END OF EJS Templates
vcs: Refactor the get_repo function....
Martin Bornhold -
r483:b7e26a5f default
parent child Browse files
Show More
@@ -29,7 +29,7 b" VERSION = (0, 5, 0, 'dev')"
29 __version__ = '.'.join((str(each) for each in VERSION[:4]))
29 __version__ = '.'.join((str(each) for each in VERSION[:4]))
30
30
31 __all__ = [
31 __all__ = [
32 'get_version', 'get_repo', 'get_backend',
32 'get_version', 'get_vcs_instance', 'get_backend',
33 'VCSError', 'RepositoryError', 'CommitError'
33 'VCSError', 'RepositoryError', 'CommitError'
34 ]
34 ]
35
35
@@ -44,7 +44,7 b' import Pyro4'
44 from Pyro4.errors import CommunicationError
44 from Pyro4.errors import CommunicationError
45
45
46 from rhodecode.lib.vcs.conf import settings
46 from rhodecode.lib.vcs.conf import settings
47 from rhodecode.lib.vcs.backends import get_repo, get_backend
47 from rhodecode.lib.vcs.backends import get_vcs_instance, get_backend
48 from rhodecode.lib.vcs.exceptions import (
48 from rhodecode.lib.vcs.exceptions import (
49 VCSError, RepositoryError, CommitError)
49 VCSError, RepositoryError, CommitError)
50
50
@@ -22,7 +22,8 b''
22 VCS Backends module
22 VCS Backends module
23 """
23 """
24
24
25 import os
25 import logging
26
26 from pprint import pformat
27 from pprint import pformat
27
28
28 from rhodecode.lib.vcs.conf import settings
29 from rhodecode.lib.vcs.conf import settings
@@ -31,31 +32,29 b' from rhodecode.lib.vcs.utils.helpers imp'
31 from rhodecode.lib.vcs.utils.imports import import_class
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
40 Given a path to a repository an instance of the corresponding vcs backend
37 the specified ``path``. If ``alias`` is not given it will try to guess it
41 repository class is created and returned. If no repository can be found
38 using get_scm method
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 try:
45 try:
48 scm, path = get_scm(path, search_path_up=True)
46 vcs_alias = get_scm(repo_path)[0]
49 path = os.path.abspath(path)
47 log.debug(
50 alias = scm
48 'Creating instance of %s repository from %s', vcs_alias, repo_path)
49 backend = get_backend(vcs_alias)
51 except VCSError:
50 except VCSError:
52 raise VCSError("No scm found at %s" % path)
51 log.exception(
53 if alias is None:
52 'Perhaps this repository is in db and not in '
54 alias = get_scm(path)[0]
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 return backend(repo_path=repo_path, *args, **kwargs)
57 repo = backend(path, create=create)
58 return repo
59
58
60
59
61 def get_backend(alias):
60 def get_backend(alias):
General Comments 0
You need to be logged in to leave comments. Login now