~edwargix/git.sr.ht

65f39f7c52f6a9674fdb1bc051b7ecd7d28811fb — наб 4 years ago 8f88443
Add Repository.git_repo and GitRepository.default_branch_name(), use them for util.html#breadcrumb()
3 files changed, 17 insertions(+), 2 deletions(-)

M gitsrht/git.py
M gitsrht/templates/utils.html
M gitsrht/types/__init__.py
M gitsrht/git.py => gitsrht/git.py +7 -0
@@ 60,6 60,13 @@ class Repository(GitRepository):
            branch = self.branches.get(branch)
        return branch

    def default_branch_name(self):
        branch = self.default_branch()
        if branch:
            return branch.name[len("refs/heads/"):]
        else:
            return None

    @property
    def is_empty(self):
        return len(list(self.branches.local)) == 0

M gitsrht/templates/utils.html => gitsrht/templates/utils.html +1 -2
@@ 1,6 1,5 @@
{% macro breadcrumb(ref, repo, path, path_join) %}
{# TODO: Default branches other than master #}
{% if ref != "master" %}
{% if ref != repo.git_repo.default_branch_name() %}
<span style="margin-right: 1rem">
  <span class="text-muted">ref:</span> {{ ref }}
</span>

M gitsrht/types/__init__.py => gitsrht/types/__init__.py +9 -0
@@ 3,6 3,7 @@ import sqlalchemy as sa
from sqlalchemy import event
from srht.database import Base
from srht.oauth import ExternalUserMixin, ExternalOAuthTokenMixin
from gitsrht.git import Repository as GitRepository
from scmsrht.repos import BaseAccessMixin, BaseRedirectMixin
from scmsrht.repos import BaseRepositoryMixin, RepoVisibility



@@ 19,6 20,8 @@ class Redirect(Base, BaseRedirectMixin):
    pass

class Repository(Base, BaseRepositoryMixin):
    _git_repo = None

    def update_visibility(self):
        if not os.path.exists(self.path):
            # Repo dir not initialized yet


@@ 34,6 37,12 @@ class Repository(Base, BaseRepositoryMixin):
        elif not should_exist and os.path.exists(path):
            os.unlink(path)

    @property
    def git_repo(self):
        if not self._git_repo:
            self._git_repo = GitRepository(self.path)
        return self._git_repo

def update_visibility_event(mapper, connection, target):
    target.update_visibility()