Mercurial > kallithea
changeset 4295:20f051c5d814
helpers: introduce link_to_ref
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Fri, 18 Jul 2014 18:44:54 +0200 |
parents | e14bbd6caa34 |
children | fa4ef7f0f440 |
files | kallithea/lib/helpers.py |
diffstat | 1 files changed, 19 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/helpers.py Fri Jun 28 11:50:13 2013 +0200 +++ b/kallithea/lib/helpers.py Fri Jul 18 18:44:54 2014 +0200 @@ -1380,6 +1380,25 @@ return literal('<div class="rst-block">%s</div>' % MarkupRenderer.rst_with_mentions(source)) +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. + """ + if ref_type == 'rev': + txt = short_id(ref_name) + else: + txt = 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)