Kallithea issues archive

Issue #336: Clone URL on repository landing page not functioning as expected

Reported by: Brandon Jones
State: resolved
Created on: 2019-03-18 14:56
Updated on: 2019-03-26 20:53

Description

On the landing page for a repository in Kallithea I noticed a few things about the Clone URL.

First, it is showing http, when my instance is hosted with a https URL.

Second, there is no underscore before the actual repo ID (should be /_1780 not /1780)

Third, the show by name/show by id button does not appear to have any effect.

Attachments

cloneurl.png

Comments

Comment by Brandon Jones, on 2019-03-18 17:03

So the first issue is irrelevant - I am behind a reverse proxy. I was unaware that the clone_uri is configurable from settings.

However, I think there is a small issue with the code below (summary.py)

        _def_clone_uri = _def_clone_uri_by_id = c.clone_uri_tmpl
        if '{repo}' in _def_clone_uri:
            _def_clone_uri_by_id = _def_clone_uri.replace('{repo}', '_{repoid}')
        elif '{repoid}' in _def_clone_uri:
            _def_clone_uri_by_id = _def_clone_uri.replace('_{repoid}', '{repo}')

It is checking for '{repoid}' but then replacing '_{repoid}', which may not be found. In my case, the template was defaulted to /{repoid} with no underscore before it.

Comment by Thomas De Schampheleire, on 2019-03-18 20:05

Yes, I tried reproducing based on a default installation, and failed.

I don't really understand the 'elif' branch in the code you pasted. It originates from the original RhodeCode codebase. I also don't really see why this template needs to be configurable. The code seems to assume/require the leading underscore for repoid, but does not actually enforce it. Is it to differentiate a repo called '123' from the repo with id '123' ?

You mentioned "In my case, the template was defaulted to {repoid} with no underscore before it.". What exactly do you mean? I think you must have changed it manually, no? And what was your intention / expectation for changing it?

@kiilerix Do you know more about this?

Comment by Brandon Jones, on 2019-03-18 20:11

I upgraded from 0.3.2, and did not modify my settings during the upgrade, and it did not have the underscore before it in the settings. So, assuming that the Clone URI existed in 0.3.2, then no, I did not modify that. I would assume that the default value is what I saw, but I could be wrong. Either way that side of things is working now on my end.

Comment by Thomas De Schampheleire, on 2019-03-18 20:17

The value of 'DEFAULT_CLONE_URI' and 'DEFAULT_CLONE_URI_BY_ID' has not changed between these two releases (and not in the history of Kallithea) but I will test the same upgrade from 0.3.2 to 0.4.0rc1 and report back.

Is there anything else of the issues you reported in this ticket that remains? At my side, the button does have effect and toggles between displaying the repo path by name and by id.

Comment by Thomas De Schampheleire, on 2019-03-18 20:28

I checked, in Kallithea 0.3.2, starting from an empty database and populating it with 'paster setup-db my.ini', the clone URI is set to the same value as the default in Kallithea 0.4.0rc1: {scheme}://{user}@{netloc}/{repo}.

Comment by Brandon Jones, on 2019-03-18 20:33

It must have been carryover then, it's just strange because I know for a fact that there was an underscore there before, but when I upgraded the underscore went away.

Perhaps in 0.3.2 {repoid} resolved to _1780, and in 0.4.0rc1 {repoid} resolves to just 1780?

Comment by Thomas De Schampheleire, on 2019-03-18 20:53

Strange indeed. {repoid} is replaced by the numeric ID in both cases, there is no underscore in that part (see kallithea/model/db.py, function 'clone_url' ).

If you can reproduce this scenario, perhaps in a test scenario, please let me know.

Does the button correctly toggle at your end? If not, are you sure you executed 'kallithea-cli front-end-build' ?

Comment by Mads Kiilerich, on 2019-03-19 02:26

For the configurable clone_uri and reverse proxies, note https://kallithea.readthedocs.io/en/0.4.0rc1/setup.html#https-support .

Comment by Mads Kiilerich, on 2019-03-19 02:36

I guess the code was supposed to allow configuration in one way and let it be used the other way, so it should look like

        _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}')

Does that make sense?

Comment by Brandon Jones, on 2019-03-19 14:01

Yes that makes sense.

Since the button is toggling successfully for me now when formatted properly, I suppose the only change here is the one you proposed adding the underscore in front of {repoid}

Comment by Thomas De Schampheleire, on 2019-03-19 15:07

But, if someone has set the default clone uri based on {repoid} without leading underscore, then there will not be a valid clone uri by name, right? I think that there may need to be a second replacement of {repoid} by {repo} if the first replacement did not succeed. Or alternatively, enforce the leading underscore.

Comment by Mads Kiilerich, on 2019-03-20 00:54

I'm confused about what actual problem we are trying to solve. What was the old Admin » Settings » Visual » Clone URL? Did it really work in 0.3.2, both for name and id URLs?

I guess it was something like {scheme}://{user}@{netloc}/{repoid} ... and that is wrong; there should be a _ before {repoid}. But in either case, the name URLs must have been broken? It is much better to just leave it at the default {scheme}://{user}@{netloc}/{repo}. Or is there a special use case for specifying repoid?

The handling of these repo id URLs is very hardcoded in a odd call chain that ends in utils.py get_repo_by_id . I doubt there are good use cases for specifying repoid explicitly. We should probably just simplify the code.

Comment by Thomas De Schampheleire, on 2019-03-26 20:53

Fixed with commit c0b8d016cc3e. Thanks for reporting!