diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py +++ b/mercurial/hgweb/hgweb_mod.py @@ -24,6 +24,30 @@ perms = { '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 @@ class hgweb(object): "header": header, "footer": footer, "motd": motd, - "sessionvars": sessionvars + "sessionvars": sessionvars, + "pathdef": makebreadcrumb(req.url), }) return tmpl diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py --- a/mercurial/hgweb/hgwebdir_mod.py +++ b/mercurial/hgweb/hgwebdir_mod.py @@ -12,7 +12,7 @@ from mercurial import ui, hg, scmutil, u 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 @@ class hgwebdir(object): self.updatereqenv(req.env) return tmpl("index", entries=entries, subdir=subdir, + pathdef=makebreadcrumb('/' + subdir), sortcolumn=sortcolumn, descending=descending, **dict(sort)) diff --git a/mercurial/templates/coal/map b/mercurial/templates/coal/map --- a/mercurial/templates/coal/map +++ b/mercurial/templates/coal/map @@ -223,3 +223,4 @@ notfound = ../paper/notfound.tmpl error = ../paper/error.tmpl urlparameter = '{separator}{name}={value|urlescape}' hiddenformentry = '' +breadcrumb = '> {name} ' diff --git a/mercurial/templates/gitweb/bookmarks.tmpl b/mercurial/templates/gitweb/bookmarks.tmpl --- a/mercurial/templates/gitweb/bookmarks.tmpl +++ b/mercurial/templates/gitweb/bookmarks.tmpl @@ -8,7 +8,8 @@