# HG changeset patch # User Angel Ezquerra # Date 1354130486 -3600 # Node ID bebb05a7e249a3f24bd4f2fdce18aee1658f053d # Parent a35d0128545e01ff5889ece515844d9ae84f5c39 hgweb: add a "URL breadcrumb" to the index and repository pages The purpose of this change is to make it much easier to navigate up the repository tree when the hg web server is used to serve more than one repository. A "URL breadcrumb" is a path where each of the path items can be clicked to go to the corresponding path page. This lets you go up the folder hierarchy very quickly. For example, when showing the list of repositories in http://myserver/myteams/myprojects, the following "breadcrumb" will be shown: Mercurial > myteams > myprojects Clicking on "myprojects" reloads the page. Clicking on "myteams" goes up one folder. Clicking on the leftmost "Mercurial" goes to the server root. This "breadcrumb" also appears on all repository pages. For example on the summary page of the repository at http://myserver/myteams/myprojects/myrepo the following will be shown: Mercurial > myteams > myprojects > myrepo / summary This change has been applied to all templates that already had a link to the main repository page (i.e. gitweb, monoblue, paper and coal) plus to the index page of the spartan template. In order to make the breadcumb links stand out the some of the template styles have been customized. diff -r a35d0128545e -r bebb05a7e249 mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py Tue Jan 08 04:15:46 2013 +0100 +++ b/mercurial/hgweb/hgweb_mod.py Wed Nov 28 20:21:26 2012 +0100 @@ -24,6 +24,30 @@ 'pushkey': 'push', } +def makebreadcrumb(url): + '''Return a 'URL breadcrumb' list + + A 'URL breadcrumb' is a list of URL-name pairs, + corresponding to each of the path items on a URL. + This can be used to create path navigation entries. + ''' + if url.endswith('/'): + url = url[:-1] + relpath = url + if relpath.startswith('/'): + relpath = relpath[1:] + + breadcrumb = [] + urlel = url + pathitems = [''] + relpath.split('/') + for pathel in reversed(pathitems): + if not pathel or not urlel: + break + breadcrumb.append({'url': urlel, 'name': pathel}) + urlel = os.path.dirname(urlel) + return reversed(breadcrumb) + + class hgweb(object): def __init__(self, repo, name=None, baseui=None): if isinstance(repo, str): @@ -285,7 +309,8 @@ "header": header, "footer": footer, "motd": motd, - "sessionvars": sessionvars + "sessionvars": sessionvars, + "pathdef": makebreadcrumb(req.url), }) return tmpl diff -r a35d0128545e -r bebb05a7e249 mercurial/hgweb/hgwebdir_mod.py --- a/mercurial/hgweb/hgwebdir_mod.py Tue Jan 08 04:15:46 2013 +0100 +++ b/mercurial/hgweb/hgwebdir_mod.py Wed Nov 28 20:21:26 2012 +0100 @@ -12,7 +12,7 @@ from mercurial import error, encoding from common import ErrorResponse, get_mtime, staticfile, paritygen, \ get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR -from hgweb_mod import hgweb +from hgweb_mod import hgweb, makebreadcrumb from request import wsgirequest import webutil @@ -395,6 +395,7 @@ self.updatereqenv(req.env) return tmpl("index", entries=entries, subdir=subdir, + pathdef=makebreadcrumb('/' + subdir), sortcolumn=sortcolumn, descending=descending, **dict(sort)) diff -r a35d0128545e -r bebb05a7e249 mercurial/templates/coal/map --- a/mercurial/templates/coal/map Tue Jan 08 04:15:46 2013 +0100 +++ b/mercurial/templates/coal/map Wed Nov 28 20:21:26 2012 +0100 @@ -223,3 +223,4 @@ error = ../paper/error.tmpl urlparameter = '{separator}{name}={value|urlescape}' hiddenformentry = '' +breadcrumb = '> {name} ' diff -r a35d0128545e -r bebb05a7e249 mercurial/templates/gitweb/bookmarks.tmpl --- a/mercurial/templates/gitweb/bookmarks.tmpl Tue Jan 08 04:15:46 2013 +0100 +++ b/mercurial/templates/gitweb/bookmarks.tmpl Wed Nov 28 20:21:26 2012 +0100 @@ -8,7 +8,8 @@