[PATCH [V2][RFC]] file_browser: properly handle subrepos using relative paths

Angel Ezquerra angel.ezquerra at gmail.com
Sun Feb 28 10:43:12 UTC 2016


On Sun, Feb 28, 2016 at 11:39 AM, Angel Ezquerra
<angel.ezquerra at gmail.com> wrote:
> # HG changeset patch
> # User Angel Ezquerra <angel.ezquerra at gmail.com>
> # Date 1456619241 -3600
> #      Sun Feb 28 01:27:21 2016 +0100
> # Branch stable
> # Node ID b5464b657fc1d4e02d06d191d56cb8abbd3b0fb8
> # Parent  9303d22fa788628d9f441477f8d1d70c026578bf
> file_browser: properly handle subrepos using relative paths
>
> Mercurial subrepos can point to relative or absolute paths. It is usually
> recommended that Mercurial subrepos should be "simple", which means that they
> must be declared as follows in their .hgsub file:
>
> path = path
>
> Where path is the relative path of the subrepo to the root of the repository.
> Up until now Kallithea did not really support subrepos with relative paths. This
> revision tries to fix that.
>
> # NOTES:
>
> This version is RFC because the link that is created for relative subrepos seems
> correct but does not work for me (on Firefox on windows) when I left click on
> it. It _does_ work if I right click it and select "Open Link in New Window" or
> "Open Link in New Tab".
>
> diff --git a/kallithea/templates/files/files_browser.html b/kallithea/templates/files/files_browser.html
> --- a/kallithea/templates/files/files_browser.html
> +++ b/kallithea/templates/files/files_browser.html
> @@ -1,3 +1,4 @@
> +<%! import os %>
>  <%def name="file_class(node)">
>      %if node.is_file():
>          <%return "browser-file" %>
> @@ -9,7 +10,13 @@
>  </%def>
>  <%def name="file_url(node, c)">
>      %if node.is_submodule():
> -        <%return node.url or '#'%>
> +        %if '://' in node.url or os.path.isabs(node.url):
> +            ## submodule pointing to an absolute URL
> +            <%return node.url or '#'%>
> +        %else:
> +            ## submodule pointing to a relative URL (as is recommended for Mercurial subrepos
> +            <%return h.url('changeset_home', repo_name=(c.db_repo.repo_name + '/' + node.url), revision=node.changeset.raw_id)%>
> +        %endif
>      %else:
>          <%return h.url('files_home', repo_name=c.repo_name, revision=c.changeset.raw_id, f_path=h.safe_unicode(node.path))%>
>      %endif

I realized that subrepos can also be "linked" to local repositories by
pointing to an absolute local path. This is a really bad idea if you
plan to ever share your repository with someone else but mercurial
allows it so we must support it. That's the reason for V2 of this
patch.

I'm not sure that the new "<%! import os %>" line which I added is the
best way to go about this. Please let me know if there is a better way
to handle this. I guess I could add a new helper function to helpers
or utils but since this is the only way where this is being used at
the moment I thought it was overkill.

Cheers,

Angel


More information about the kallithea-general mailing list