Mercurial > hg
comparison hgext/highlight/__init__.py @ 25602:85fb416f2fa7
hgweb: provide symrev (symbolic revision) property to the templates
One of the features of hgweb is that current position in repo history is
remembered between separate requests. That is, links from /rev/<node_hash> lead
to /file/<node_hash> or /log/<node_hash>, so it's easy to dig deep into the
history. However, such links could only use node hashes and local revision
numbers, so while staying at one exact revision is easy, staying on top of the
changes is not, because hashes presumably can't change (local revision numbers
can, but probably not in a way you'd find useful for navigating).
So while you could use 'tip' or 'default' in a url, links on that page would be
permanent. This is not always desired (think /rev/tip or /graph/stable or
/log/@) and is sometimes just confusing (i.e. /log/<not the tip hash>, when
recent history is not displayed). And if user changed url deliberately to say
default instead of <some node hash>, the page ignores that fact and uses node
hash in its links, which means that navigation is, in a way, broken.
This new property, symrev, is used for storing current revision the way it was
specified, so then templates can use it in links and thus "not dereference" the
symbolic revision. It is an additional way to produce links, so not every link
needs to drop {node|short} in favor of {symrev}, many will still use node hash
(log and filelog entries, annotate lines, etc).
Some pages (e.g. summary, tags) always use the tip changeset for their context,
in such cases symrev is set to 'tip'. This is needed in case the pages want to
provide archive links.
highlight extension needs to be updated, since _filerevision now takes an
additional positional argument (signature "web, req, tmpl" is used by most of
webcommands.py functions).
More references to symbolic revisions and related gripes: issue2296, issue2826,
issue3594, issue3634.
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Tue, 16 Jun 2015 02:07:25 +0800 |
parents | 80c5b2666a96 |
children | 3166bcc0c538 |
comparison
equal
deleted
inserted
replaced
25601:3ec8351fa6ed | 25602:85fb416f2fa7 |
---|---|
28 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | 28 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
29 # be specifying the version(s) of Mercurial they are tested with, or | 29 # be specifying the version(s) of Mercurial they are tested with, or |
30 # leave the attribute unspecified. | 30 # leave the attribute unspecified. |
31 testedwith = 'internal' | 31 testedwith = 'internal' |
32 | 32 |
33 def filerevision_highlight(orig, web, tmpl, fctx): | 33 def filerevision_highlight(orig, web, req, tmpl, fctx): |
34 mt = ''.join(tmpl('mimetype', encoding=encoding.encoding)) | 34 mt = ''.join(tmpl('mimetype', encoding=encoding.encoding)) |
35 # only pygmentize for mimetype containing 'html' so we both match | 35 # only pygmentize for mimetype containing 'html' so we both match |
36 # 'text/html' and possibly 'application/xhtml+xml' in the future | 36 # 'text/html' and possibly 'application/xhtml+xml' in the future |
37 # so that we don't have to touch the extension when the mimetype | 37 # so that we don't have to touch the extension when the mimetype |
38 # for a template changes; also hgweb optimizes the case that a | 38 # for a template changes; also hgweb optimizes the case that a |
40 # can't clash with the file's content-type here in case we | 40 # can't clash with the file's content-type here in case we |
41 # pygmentize a html file | 41 # pygmentize a html file |
42 if 'html' in mt: | 42 if 'html' in mt: |
43 style = web.config('web', 'pygments_style', 'colorful') | 43 style = web.config('web', 'pygments_style', 'colorful') |
44 highlight.pygmentize('fileline', fctx, style, tmpl) | 44 highlight.pygmentize('fileline', fctx, style, tmpl) |
45 return orig(web, tmpl, fctx) | 45 return orig(web, req, tmpl, fctx) |
46 | 46 |
47 def annotate_highlight(orig, web, req, tmpl): | 47 def annotate_highlight(orig, web, req, tmpl): |
48 mt = ''.join(tmpl('mimetype', encoding=encoding.encoding)) | 48 mt = ''.join(tmpl('mimetype', encoding=encoding.encoding)) |
49 if 'html' in mt: | 49 if 'html' in mt: |
50 fctx = webutil.filectx(web.repo, req) | 50 fctx = webutil.filectx(web.repo, req) |