changeset 7760:67962f489ddd

clone_url: always pass a clone_uri_tmpl, with Repository.DEFAULT_CLONE_URI as last resort clone_url() had a layering violation of using c.clone_uri_tmpl . This refactoring now makes it clear that this only was used from PullRequest.__json__(), so move the hack there and simplify it.
author Mads Kiilerich <mads@kiilerich.com>
date Tue, 30 Jul 2019 22:59:44 +0200
parents b71aedc74d7b
children b118e9ffc85c
files kallithea/lib/base.py kallithea/model/db.py kallithea/templates/admin/repos/repo_edit_settings.html kallithea/templates/pullrequests/pullrequest_show.html
diffstat 4 files changed, 7 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/base.py	Tue Jul 16 12:13:53 2019 +0200
+++ b/kallithea/lib/base.py	Tue Jul 30 22:59:44 2019 +0200
@@ -403,7 +403,7 @@
                     })();
             </script>''' % c.ga_code
         c.site_name = rc_config.get('title')
-        c.clone_uri_tmpl = rc_config.get('clone_uri_tmpl')
+        c.clone_uri_tmpl = rc_config.get('clone_uri_tmpl') or Repository.DEFAULT_CLONE_URI
 
         ## INI stored
         c.visual.allow_repo_location_change = str2bool(config.get('allow_repo_location_change', True))
--- a/kallithea/model/db.py	Tue Jul 16 12:13:53 2019 +0200
+++ b/kallithea/model/db.py	Tue Jul 30 22:59:44 2019 +0200
@@ -43,6 +43,7 @@
 
 from tg.i18n import lazy_ugettext as _
 
+import kallithea
 from kallithea.lib.exceptions import DefaultUserException
 from kallithea.lib.vcs import get_backend
 from kallithea.lib.vcs.utils.helpers import get_scm
@@ -325,7 +326,6 @@
     def get_server_info(cls):
         import pkg_resources
         import platform
-        import kallithea
         from kallithea.lib.utils import check_git_version
         mods = [(p.project_name, p.version) for p in pkg_resources.working_set]
         info = {
@@ -1270,17 +1270,6 @@
             clone_uri_tmpl = override['clone_uri_tmpl']
             del override['clone_uri_tmpl']
 
-        # we didn't override our tmpl from **overrides
-        if not clone_uri_tmpl:
-            clone_uri_tmpl = self.DEFAULT_CLONE_URI
-            try:
-                from tg import tmpl_context as c
-                clone_uri_tmpl = c.clone_uri_tmpl
-            except AttributeError:
-                # in any case if we call this outside of request context,
-                # ie, not having tmpl_context set up
-                pass
-
         import kallithea.lib.helpers as h
         prefix_url = h.canonical_url('home')
 
@@ -2092,7 +2081,6 @@
         Wrapper for generating a unique cache key for this instance and "key".
         key must / will start with a repo_name which will be stored in .cache_args .
         """
-        import kallithea
         prefix = kallithea.CONFIG.get('instance_id', '')
         return "%s%s" % (prefix, key)
 
@@ -2370,6 +2358,7 @@
         return self.__json__()
 
     def __json__(self):
+        clone_uri_tmpl = kallithea.CONFIG.get('clone_uri_tmpl') or Repository.DEFAULT_CLONE_URI
         return dict(
             pull_request_id=self.pull_request_id,
             url=self.url(),
@@ -2378,7 +2367,7 @@
             owner=self.owner.username,
             title=self.title,
             description=self.description,
-            org_repo_url=self.org_repo.clone_url(),
+            org_repo_url=self.org_repo.clone_url(clone_uri_tmpl=clone_uri_tmpl),
             org_ref_parts=self.org_ref_parts,
             other_ref_parts=self.other_ref_parts,
             status=self.status,
@@ -2479,7 +2468,6 @@
         return cls.query().filter(cls.gist_access_id == gist_access_id).scalar()
 
     def gist_url(self):
-        import kallithea
         alias_url = kallithea.CONFIG.get('gist_alias_url')
         if alias_url:
             return alias_url.replace('{gistid}', self.gist_access_id)
--- a/kallithea/templates/admin/repos/repo_edit_settings.html	Tue Jul 16 12:13:53 2019 +0200
+++ b/kallithea/templates/admin/repos/repo_edit_settings.html	Tue Jul 30 22:59:44 2019 +0200
@@ -6,7 +6,7 @@
                     ${h.text('repo_name',class_='form-control')}
                     <span class="help-block">${_('Permanent Repository ID')}: `_${c.repo_info.repo_id}` <span><a id="show_more_clone_id" href="#">${_('What is that?')}</a></span></span>
                     <span id="clone_id" class="help-block" style="display: none">
-                        ${_('URL by id')}: `${c.repo_info.clone_url(with_id=True)}`<br/>
+                        ${_('URL by id')}: `${c.repo_info.clone_url(clone_uri_tmpl=c.clone_uri_tmpl, with_id=True)}`<br/>
                         ${_('''In case this repository is renamed or moved into another group the repository URL changes.
                                Using the above permanent URL guarantees that this repository always will be accessible on that URL.
                                This is useful for CI systems, or any other cases that you need to hardcode the URL into a 3rd party service.''')}</span>
--- a/kallithea/templates/pullrequests/pullrequest_show.html	Tue Jul 16 12:13:53 2019 +0200
+++ b/kallithea/templates/pullrequests/pullrequest_show.html	Tue Jul 30 22:59:44 2019 +0200
@@ -106,9 +106,9 @@
               <div>
                ## TODO: use cs_ranges[-1] or org_ref_parts[1] in both cases?
                %if h.is_hg(c.pull_request.org_repo):
-                 <span>hg pull ${c.pull_request.org_repo.clone_url()} -r ${h.short_id(c.cs_ranges[-1].raw_id)}</span>
+                 <span>hg pull ${c.pull_request.org_repo.clone_url(clone_uri_tmpl=c.clone_uri_tmpl)} -r ${h.short_id(c.cs_ranges[-1].raw_id)}</span>
                %elif h.is_git(c.pull_request.org_repo):
-                 <span>git pull ${c.pull_request.org_repo.clone_url()} ${c.pull_request.org_ref_parts[1]}</span>
+                 <span>git pull ${c.pull_request.org_repo.clone_url(clone_uri_tmpl=c.clone_uri_tmpl)} ${c.pull_request.org_ref_parts[1]}</span>
                %endif
               </div>
             %endif