Changeset - aee4c451566f
[Not reviewed]
default
0 5 0
Mads Kiilerich - 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
 
@@ -17,7 +17,7 @@ from kallithea.lib.vcs.utils.imports imp
 
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
 
@@ -39,7 +39,7 @@ def get_repo(path=None, alias=None, crea
 
        alias = get_scm(path)[0]
 

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

	
 

	
kallithea/lib/vcs/backends/base.py
Show inline comments
 
@@ -1026,7 +1026,7 @@ class EmptyChangeset(BaseChangeset):
 

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

	
 
    @LazyProperty
 
    def short_id(self):
kallithea/lib/vcs/backends/git/repository.py
Show inline comments
 
@@ -52,8 +52,8 @@ class GitRepository(BaseRepository):
 
    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
kallithea/model/db.py
Show inline comments
 
@@ -48,10 +48,9 @@ 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
 

	
 

	
 
@@ -1331,16 +1330,8 @@ class Repository(meta.Base, BaseDbModel)
 

	
 
    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):
kallithea/model/scm.py
Show inline comments
 
@@ -41,9 +41,9 @@ from kallithea.lib.exceptions import IMC
 
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
 
@@ -184,15 +184,8 @@ class ScmModel(object):
 
                    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
0 comments (0 inline, 0 general)