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

Angel Ezquerra angel.ezquerra at gmail.com
Sun Feb 28 10:39:41 UTC 2016


# 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kallithea.patch
Type: text/x-patch
Size: 2008 bytes
Desc: not available
URL: <http://lists.sfconservancy.org/pipermail/kallithea-general/attachments/20160228/bf372023/attachment.bin>


More information about the kallithea-general mailing list