Changeset - 7e7489e1672d
[Not reviewed]
default
0 3 0
Mads Kiilerich - 5 years ago 2020-10-30 00:50:38
mads@kiilerich.com
Grafted from: e41f05275054
lib: move link_to_ref from helpers to utils2

Less reason to import the messy helpers.
3 files changed with 33 insertions and 32 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/helpers.py
Show inline comments
 
@@ -38,8 +38,8 @@ from kallithea.lib.auth import HasPermis
 
from kallithea.lib.diffs import BIN_FILENODE, CHMOD_FILENODE, DEL_FILENODE, MOD_FILENODE, NEW_FILENODE, RENAMED_FILENODE
 
from kallithea.lib.markup_renderer import url_re
 
from kallithea.lib.pygmentsutils import get_custom_lexer
 
from kallithea.lib.utils2 import (MENTIONS_REGEX, AttributeDict, age, asbool, credentials_filter, fmt_date, safe_bytes, safe_int, safe_str, shorter,
 
                                  time_to_datetime)
 
from kallithea.lib.utils2 import (MENTIONS_REGEX, AttributeDict, age, asbool, credentials_filter, fmt_date, link_to_ref, safe_bytes, safe_int, safe_str,
 
                                  shorter, time_to_datetime)
 
from kallithea.lib.vcs.backends.base import BaseChangeset, EmptyChangeset
 
from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError
 
#==============================================================================
 
@@ -82,6 +82,7 @@ assert HasRepoPermissionLevel
 
# from utils2
 
assert age
 
assert fmt_date
 
assert link_to_ref
 
assert shorter
 
assert time_to_datetime
 
# from vcs
 
@@ -1128,30 +1129,6 @@ def render_w_mentions(source, repo_name=
 
    return literal('<div class="formatted-fixed">%s</div>' % s)
 

	
 

	
 
def short_ref(ref_type, ref_name):
 
    if ref_type == 'rev':
 
        return short_id(ref_name)
 
    return ref_name
 

	
 

	
 
def link_to_ref(repo_name, ref_type, ref_name, rev=None):
 
    """
 
    Return full markup for a href to changeset_home for a changeset.
 
    If ref_type is branch it will link to changelog.
 
    ref_name is shortened if ref_type is 'rev'.
 
    if rev is specified show it too, explicitly linking to that revision.
 
    """
 
    txt = short_ref(ref_type, ref_name)
 
    if ref_type == 'branch':
 
        u = url('changelog_home', repo_name=repo_name, branch=ref_name)
 
    else:
 
        u = url('changeset_home', repo_name=repo_name, revision=ref_name)
 
    l = link_to(repo_name + '#' + txt, u)
 
    if rev and ref_type != 'rev':
 
        l = literal('%s (%s)' % (l, link_to(short_id(rev), url('changeset_home', repo_name=repo_name, revision=rev))))
 
    return l
 

	
 

	
 
def changeset_status(repo, revision):
 
    return ChangesetStatusModel().get_status(repo, revision)
 

	
kallithea/lib/utils2.py
Show inline comments
 
@@ -45,6 +45,7 @@ from tg.support.converters import asbool
 
from webhelpers2.text import collapse, remove_formatting, strip_tags
 

	
 
import kallithea
 
from kallithea.lib import webutils
 
from kallithea.lib.vcs.backends.base import BaseRepository, EmptyChangeset
 
from kallithea.lib.vcs.exceptions import RepositoryError
 
from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, safe_bytes, safe_str  # re-export
 
@@ -345,6 +346,31 @@ def get_clone_url(clone_uri_tmpl, prefix
 
    return str(url_obj)
 

	
 

	
 
def short_ref_name(ref_type, ref_name):
 
    """Return short description of PR ref - revs will be truncated"""
 
    if ref_type == 'rev':
 
        return ref_name[:12]
 
    return ref_name
 

	
 

	
 
def link_to_ref(repo_name, ref_type, ref_name, rev=None):
 
    """
 
    Return full markup for a PR ref to changeset_home for a changeset.
 
    If ref_type is 'branch', it will link to changelog.
 
    ref_name is shortened if ref_type is 'rev'.
 
    if rev is specified, show it too, explicitly linking to that revision.
 
    """
 
    txt = short_ref_name(ref_type, ref_name)
 
    if ref_type == 'branch':
 
        u = webutils.url('changelog_home', repo_name=repo_name, branch=ref_name)
 
    else:
 
        u = webutils.url('changeset_home', repo_name=repo_name, revision=ref_name)
 
    l = webutils.link_to(repo_name + '#' + txt, u)
 
    if rev and ref_type != 'rev':
 
        l = webutils.literal('%s (%s)' % (l, webutils.link_to(rev[:12], webutils.url('changeset_home', repo_name=repo_name, revision=rev))))
 
    return l
 

	
 

	
 
def get_changeset_safe(repo, rev):
 
    """
 
    Safe version of get_changeset if this changeset doesn't exists for a
kallithea/model/pull_request.py
Show inline comments
 
@@ -32,12 +32,10 @@ import re
 
from tg import request
 
from tg.i18n import ugettext as _
 

	
 
from kallithea.lib import auth
 
from kallithea.lib import helpers as h
 
from kallithea.lib import webutils
 
from kallithea.lib import auth, webutils
 
from kallithea.lib.hooks import log_create_pullrequest
 
from kallithea.lib.utils import extract_mentioned_users
 
from kallithea.lib.utils2 import ascii_bytes, shorter
 
from kallithea.lib.utils2 import ascii_bytes, short_ref_name, shorter
 
from kallithea.model import db, meta
 
from kallithea.model.notification import NotificationModel
 

	
 
@@ -199,7 +197,7 @@ class CreatePullRequestAction(object):
 
        (org_ref_type,
 
         org_ref_name,
 
         org_rev) = org_ref.split(':')
 
        org_display = h.short_ref(org_ref_type, org_ref_name)
 
        org_display = short_ref_name(org_ref_type, org_ref_name)
 
        if org_ref_type == 'rev':
 
            cs = org_repo.scm_instance.get_changeset(org_rev)
 
            org_ref = 'branch:%s:%s' % (cs.branch, cs.raw_id)
 
@@ -211,7 +209,7 @@ class CreatePullRequestAction(object):
 
            cs = other_repo.scm_instance.get_changeset(other_rev)
 
            other_ref_name = cs.raw_id[:12]
 
            other_ref = '%s:%s:%s' % (other_ref_type, other_ref_name, cs.raw_id)
 
        other_display = h.short_ref(other_ref_type, other_ref_name)
 
        other_display = short_ref_name(other_ref_type, other_ref_name)
 

	
 
        cs_ranges, _cs_ranges_not, ancestor_revs = \
 
            org_repo.scm_instance.get_diff_changesets(other_rev, org_repo.scm_instance, org_rev) # org and other "swapped"
0 comments (0 inline, 0 general)