# HG changeset patch # User Mads Kiilerich # Date 2019-07-31 02:09:04 # Node ID b118e9ffc85cae980ef74ea70962249766e2ed51 # Parent 67962f489ddda4ebea7f308f9c70c0ba6a6a67e8 clone_url: simplify the logic - move summary handling of different URLs with/without id to db Drop the half-baked concept of a separate "clone_uri_by_id" - just always use a single template and change back and forth between {repo} and _{repoid} as necessary. Make it clear that clone_uri_tmpl always is passed as argument. diff --git a/kallithea/controllers/summary.py b/kallithea/controllers/summary.py --- a/kallithea/controllers/summary.py +++ b/kallithea/controllers/summary.py @@ -117,17 +117,8 @@ class SummaryController(BaseRepoControll username = '' else: username = safe_str(request.authuser.username) - - _def_clone_uri = _def_clone_uri_by_id = c.clone_uri_tmpl - if '{repo}' in _def_clone_uri_by_id: - _def_clone_uri_by_id = _def_clone_uri_by_id.replace('{repo}', '_{repoid}') - elif '_{repoid}' in _def_clone_uri: - _def_clone_uri = _def_clone_uri.replace('_{repoid}', '{repo}') - else: - log.error("Configured clone_uri_tmpl %r has no '{repo}' or '_{repoid}' and cannot toggle to use repo id URLs", c.clone_uri_tmpl) - - c.clone_repo_url = c.db_repo.clone_url(clone_uri_tmpl=_def_clone_uri, username=username) - c.clone_repo_url_id = c.db_repo.clone_url(clone_uri_tmpl=_def_clone_uri_by_id, username=username) + c.clone_repo_url = c.db_repo.clone_url(clone_uri_tmpl=c.clone_uri_tmpl, with_id=False, username=username) + c.clone_repo_url_id = c.db_repo.clone_url(clone_uri_tmpl=c.clone_uri_tmpl, with_id=True, username=username) if c.db_repo.enable_statistics: c.show_stats = True diff --git a/kallithea/model/db.py b/kallithea/model/db.py --- a/kallithea/model/db.py +++ b/kallithea/model/db.py @@ -963,7 +963,6 @@ class Repository(Base, BaseDbModel): ) DEFAULT_CLONE_URI = '{scheme}://{user}@{netloc}/{repo}' - DEFAULT_CLONE_URI_ID = '{scheme}://{user}@{netloc}/_{repoid}' STATE_CREATED = u'repo_state_created' STATE_PENDING = u'repo_state_pending' @@ -1260,15 +1259,13 @@ class Repository(Base, BaseDbModel): clone_uri = url_obj.with_password('*****') return clone_uri - def clone_url(self, **override): - clone_uri_tmpl = None - if 'with_id' in override: - clone_uri_tmpl = self.DEFAULT_CLONE_URI_ID - del override['with_id'] - - if 'clone_uri_tmpl' in override: - clone_uri_tmpl = override['clone_uri_tmpl'] - del override['clone_uri_tmpl'] + def clone_url(self, clone_uri_tmpl, with_id=False, **override): + if '{repo}' not in clone_uri_tmpl and '_{repoid}' not in clone_uri_tmpl: + log.error("Configured clone_uri_tmpl %r has no '{repo}' or '_{repoid}' and cannot toggle to use repo id URLs", clone_uri_tmpl) + elif with_id: + clone_uri_tmpl = clone_uri_tmpl.replace('{repo}', '_{repoid}') + else: + clone_uri_tmpl = clone_uri_tmpl.replace('_{repoid}', '{repo}') import kallithea.lib.helpers as h prefix_url = h.canonical_url('home')