Changeset - b118e9ffc85c
[Not reviewed]
default
0 2 0
Mads Kiilerich - 6 years ago 2019-07-31 02:09:04
mads@kiilerich.com
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.
2 files changed with 9 insertions and 21 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/summary.py
Show inline comments
 
@@ -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
kallithea/model/db.py
Show inline comments
 
@@ -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')
0 comments (0 inline, 0 general)