'Support for sharable URL for a specified repository revision, e.g. http://example.org/view/owner/name/changeset_revision.'

@web.expose
def sharable_repository_revision(self, trans, owner, name, changeset_revision):

    try:
        repository = repository_util.get_repository_by_name_and_owner(trans.app, name, owner)
    except:
        repository = None
    if repository:
        repository_id = trans.security.encode_id(repository.id)
        repository_metadata = metadata_util.get_repository_metadata_by_repository_id_changeset_revision(trans.app, repository_id, changeset_revision)
        if (not repository_metadata):
            repo = hg_util.get_repo_for_repository(trans.app, repository=repository, repo_path=None, create=False)
            upper_bound_changeset_revision = metadata_util.get_next_downloadable_changeset_revision(repository, repo, changeset_revision)
            if (upper_bound_changeset_revision and (upper_bound_changeset_revision != changeset_revision)):
                changeset_revision = upper_bound_changeset_revision
                repository_metadata = metadata_util.get_repository_metadata_by_repository_id_changeset_revision(trans.app, repository_id, changeset_revision)
        if repository_metadata:
            return trans.response.send_redirect(web.url_for(controller='repository', action='index', repository_id=repository_id, changeset_revision=changeset_revision))
        else:
            message = ('The    change    log    for    the    repository    named    <b>%s</b>    owned    by    <b>%s</b>    does    not    include    revision    <b>%s</b>.' % (escape(str(name)), escape(str(owner)), escape(str(changeset_revision))))
            return trans.response.send_redirect(web.url_for(controller='repository', action='index', repository_id=repository_id, message=message, status='error'))
    else:
        return trans.response.send_redirect(web.url_for(controller='repository', action='sharable_owner', owner=owner))
