Changeset - aee4c451566f
[Not reviewed]
default
0 5 0
Mads Kiilerich (mads) - 5 years ago 2020-11-01 06:18:48
mads@kiilerich.com
vcs: cleanup around get_backend and get_repo
5 files changed with 12 insertions and 28 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/vcs/backends/__init__.py
Show inline comments
 
@@ -14,13 +14,13 @@ from kallithea.lib.vcs.conf import setti
 
from kallithea.lib.vcs.exceptions import VCSError
 
from kallithea.lib.vcs.utils.helpers import get_scm
 
from kallithea.lib.vcs.utils.imports import import_class
 
from kallithea.lib.vcs.utils.paths import abspath
 

	
 

	
 
def get_repo(path=None, alias=None, create=False):
 
def get_repo(path=None, alias=None, create=False, baseui=None):
 
    """
 
    Returns ``Repository`` object of type linked with given ``alias`` at
 
    the specified ``path``. If ``alias`` is not given it will try to guess it
 
    using get_scm method
 
    """
 
    if create:
 
@@ -36,13 +36,13 @@ def get_repo(path=None, alias=None, crea
 
    except VCSError:
 
        raise VCSError("No scm found at %s" % path)
 
    if alias is None:
 
        alias = get_scm(path)[0]
 

	
 
    backend = get_backend(alias)
 
    repo = backend(path, create=create)
 
    repo = backend(path, create=create, baseui=baseui)
 
    return repo
 

	
 

	
 
def get_backend(alias):
 
    """
 
    Returns ``Repository`` class identified by the given alias or raises
kallithea/lib/vcs/backends/base.py
Show inline comments
 
@@ -1023,13 +1023,13 @@ class EmptyChangeset(BaseChangeset):
 
    @LazyProperty
 
    def branch(self):
 
        return get_backend(self.alias).DEFAULT_BRANCH_NAME
 

	
 
    @LazyProperty
 
    def branches(self):
 
        return [get_backend(self.alias).DEFAULT_BRANCH_NAME]
 
        return [self.branch]
 

	
 
    @LazyProperty
 
    def short_id(self):
 
        return self.raw_id[:12]
 

	
 
    def get_file_changeset(self, path):
kallithea/lib/vcs/backends/git/repository.py
Show inline comments
 
@@ -49,14 +49,14 @@ class GitRepository(BaseRepository):
 
    Git repository backend.
 
    """
 
    DEFAULT_BRANCH_NAME = 'master'
 
    scm = 'git'
 

	
 
    def __init__(self, repo_path, create=False, src_url=None,
 
                 update_after_clone=False, bare=False):
 

	
 
                 update_after_clone=False, bare=False, baseui=None):
 
        baseui  # unused
 
        self.path = abspath(repo_path)
 
        self.repo = self._get_repo(create, src_url, update_after_clone, bare)
 
        self.bare = self.repo.bare
 

	
 
    @property
 
    def _config_files(self):
kallithea/model/db.py
Show inline comments
 
@@ -45,16 +45,15 @@ from tg.i18n import lazy_ugettext as _
 
from webob.exc import HTTPNotFound
 

	
 
import kallithea
 
from kallithea.lib import ext_json, ssh, webutils
 
from kallithea.lib.exceptions import DefaultUserException
 
from kallithea.lib.utils2 import asbool, ascii_bytes, aslist, get_changeset_safe, get_clone_url, remove_prefix, safe_bytes, safe_int, safe_str, urlreadable
 
from kallithea.lib.vcs import get_backend, get_repo
 
from kallithea.lib.vcs import get_repo
 
from kallithea.lib.vcs.backends.base import BaseChangeset, EmptyChangeset
 
from kallithea.lib.vcs.utils import author_email, author_name
 
from kallithea.lib.vcs.utils.helpers import get_scm
 
from kallithea.model import meta
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 
#==============================================================================
 
@@ -1328,22 +1327,14 @@ class Repository(meta.Base, BaseDbModel)
 
        if self._scm_instance is None:
 
            return self.scm_instance_no_cache()  # will populate self._scm_instance
 
        return self._scm_instance
 

	
 
    def scm_instance_no_cache(self):
 
        repo_full_path = self.repo_full_path
 
        alias = get_scm(repo_full_path)[0]
 
        log.debug('Creating instance of %s repository from %s',
 
                  alias, self.repo_full_path)
 
        backend = get_backend(alias)
 

	
 
        if alias == 'hg':
 
            self._scm_instance = backend(repo_full_path, create=False, baseui=self._ui)
 
        else:
 
            self._scm_instance = backend(repo_full_path, create=False)
 

	
 
        log.debug('Creating instance of repository at %s', repo_full_path)
 
        self._scm_instance = get_repo(repo_full_path, baseui=self._ui)
 
        return self._scm_instance
 

	
 
    def __json__(self):
 
        return dict(
 
            repo_id=self.repo_id,
 
            repo_name=self.repo_name,
kallithea/model/scm.py
Show inline comments
 
@@ -38,15 +38,15 @@ from tg.i18n import ugettext as _
 
import kallithea
 
from kallithea.lib.auth import HasPermissionAny, HasRepoGroupPermissionLevel, HasRepoPermissionLevel, HasUserGroupPermissionLevel
 
from kallithea.lib.exceptions import IMCCommitError, NonRelativePathError
 
from kallithea.lib.hooks import process_pushed_raw_ids
 
from kallithea.lib.utils import action_logger, get_filesystem_repos, make_ui
 
from kallithea.lib.utils2 import safe_bytes, set_hook_environment
 
from kallithea.lib.vcs import get_backend
 
from kallithea.lib.vcs import get_repo
 
from kallithea.lib.vcs.backends.base import EmptyChangeset
 
from kallithea.lib.vcs.exceptions import RepositoryError
 
from kallithea.lib.vcs.exceptions import RepositoryError, VCSError
 
from kallithea.lib.vcs.nodes import FileNode
 
from kallithea.lib.vcs.utils.lazy import LazyProperty
 
from kallithea.model import db, meta
 

	
 

	
 
log = logging.getLogger(__name__)
 
@@ -181,21 +181,14 @@ class ScmModel(object):
 

	
 
            try:
 
                if name in repos:
 
                    raise RepositoryError('Duplicate repository name %s '
 
                                          'found in %s' % (name, path))
 
                else:
 

	
 
                    klass = get_backend(path[0])
 

	
 
                    if path[0] == 'hg' and path[0] in kallithea.BACKENDS:
 
                        repos[name] = klass(path[1], baseui=baseui)
 

	
 
                    if path[0] == 'git' and path[0] in kallithea.BACKENDS:
 
                        repos[name] = klass(path[1])
 
            except OSError:
 
                    repos[name] = get_repo(path[1], baseui=baseui)
 
            except (OSError, VCSError):
 
                continue
 
        log.debug('found %s paths with repositories', len(repos))
 
        return repos
 

	
 
    def get_repos(self, repos):
 
        """Return the repos the user has access to"""
0 comments (0 inline, 0 general)