[PATCH] web: add a help view for getting hg help output
Augie Fackler
durin42 at gmail.com
Sat Oct 9 08:27:28 CDT 2010
# HG changeset patch
# User Augie Fackler <durin42 at gmail.com>
# Date 1286630741 18000
# Node ID 1d85ff07f3d9ebe02538a9914ba612e8806248d4
# Parent 7178f6fedb9db000300abda8168d36a890a686c2
web: add a help view for getting hg help output
diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -13,6 +13,8 @@
from common import paritygen, staticfile, get_contact, ErrorResponse
from common import HTTP_OK, HTTP_FORBIDDEN, HTTP_NOT_FOUND
from mercurial import graphmod
+from mercurial import help as helpmod
+from mercurial import ui
# __all__ is populated with the allowed commands. Be sure to add to it if
# you're adding a new command, or the new command won't work.
@@ -20,7 +22,7 @@
__all__ = [
'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev',
'manifest', 'tags', 'branches', 'summary', 'filediff', 'diff', 'annotate',
- 'filelog', 'archive', 'static', 'graph',
+ 'filelog', 'archive', 'static', 'graph', 'help',
]
def log(web, req, tmpl):
@@ -724,3 +726,61 @@
lessvars=lessvars, morevars=morevars, downrev=downrev,
canvasheight=canvasheight, jsdata=data, bg_height=bg_height,
node=revnode_hex, changenav=changenav)
+
+def _getdoc(e):
+ doc = e[0].__doc__
+ if doc:
+ doc = doc.split('\n')[0]
+ else:
+ doc = ('(no help text available)')
+ return doc
+
+def help(web, req, tmpl):
+ from mercurial import commands # avoid cycle
+
+ topicname = req.form.get('node', [None])[0]
+ if not topicname:
+ topic = []
+
+ def topics(**map):
+ for entries, summary, _ in helpmod.helptable:
+ entries = sorted(entries, key=len)
+ yield {'topic': entries[-1], 'summary': summary}
+
+ deprecatedcmds, early, other = [], [], []
+ primary = lambda s: s.split('|')[0]
+ for c, e in commands.table.iteritems():
+ cmd = primary(c)
+ doc = _getdoc(e)
+ if 'DEPRECATED' in doc:
+ deprecatedcmds.append((cmd.lstrip('^'), doc))
+ elif cmd.startswith('^'):
+ early.append((cmd[1:], doc))
+ else:
+ other.append((cmd, doc))
+
+ deprecatedcmds.sort()
+ early.sort()
+ other.sort()
+
+ def earlycommands(**map):
+ for c, doc in early:
+ yield {'topic': c, 'summary': doc}
+
+ def othercommands(**map):
+ for c, doc in other:
+ yield {'topic': c, 'summary': doc}
+
+ def deprecated(**map):
+ for c, doc in deprecatedcmds:
+ yield {'topic': c, 'summary': doc}
+
+ return tmpl('helptopics', topics=topics, earlycommands=earlycommands,
+ othercommands=othercommands, deprecated=deprecated,
+ title='Index')
+
+ u = ui.ui()
+ u.pushbuffer()
+ commands.help_(u, topicname)
+ doc = u.popbuffer()
+ return tmpl('help', topic=topicname, doc=doc)
diff --git a/mercurial/templates/paper/changeset.tmpl b/mercurial/templates/paper/changeset.tmpl
--- a/mercurial/templates/paper/changeset.tmpl
+++ b/mercurial/templates/paper/changeset.tmpl
@@ -13,6 +13,7 @@
<li><a href="{url}graph/{node|short}{sessionvars%urlparameter}">graph</a></li>
<li><a href="{url}tags{sessionvars%urlparameter}">tags</a></li>
<li><a href="{url}branches{sessionvars%urlparameter}">branches</a></li>
+ <li><a href="{url}help{sessionvars%urlparameter}">help</a></li>
</ul>
<ul>
<li class="active">changeset</li>
diff --git a/mercurial/templates/paper/graph.tmpl b/mercurial/templates/paper/graph.tmpl
--- a/mercurial/templates/paper/graph.tmpl
+++ b/mercurial/templates/paper/graph.tmpl
@@ -19,6 +19,7 @@
<li class="active">graph</li>
<li><a href="{url}tags{sessionvars%urlparameter}">tags</a></li>
<li><a href="{url}branches{sessionvars%urlparameter}">branches</a></li>
+<li><a href="{url}help{sessionvars%urlparameter}">help</a></li>
</ul>
<ul>
<li><a href="{url}rev/{node|short}{sessionvars%urlparameter}">changeset</a></li>
diff --git a/mercurial/templates/paper/branches.tmpl b/mercurial/templates/paper/help.tmpl
copy from mercurial/templates/paper/branches.tmpl
copy to mercurial/templates/paper/help.tmpl
--- a/mercurial/templates/paper/branches.tmpl
+++ b/mercurial/templates/paper/help.tmpl
@@ -1,5 +1,5 @@
{header}
-<title>{repo|escape}: branches</title>
+<title>Help: {topic}</title>
<link rel="alternate" type="application/atom+xml"
href="{url}atom-tags" title="Atom feed for {repo|escape}: branches" />
<link rel="alternate" type="application/rss+xml"
@@ -17,13 +17,14 @@
<li><a href="{url}shortlog{sessionvars%urlparameter}">log</a></li>
<li><a href="{url}graph{sessionvars%urlparameter}">graph</a></li>
<li><a href="{url}tags{sessionvars%urlparameter}">tags</a></li>
-<li class="active">branches</li>
+<li><a href="{url}branches{sessionvars%urlparameter}">branches</a></li>
+<li class="active"><a href="{url}help{sessionvars%urlparameter}">help</a></li>
</ul>
</div>
<div class="main">
<h2><a href="{url}{sessionvars%urlparameter}">{repo|escape}</a></h2>
-<h3>branches</h3>
+<h3>Help: {topic}</h3>
<form class="search" action="{url}log">
{sessionvars%hiddenformentry}
@@ -31,14 +32,9 @@
<div id="hint">find changesets by author, revision,
files, or words in the commit message</div>
</form>
-
-<table class="bigtable">
-<tr>
- <th>branch</th>
- <th>node</th>
-</tr>
-{entries%branchentry}
-</table>
+<pre>
+{doc|escape}
+</pre>
</div>
</div>
diff --git a/mercurial/templates/paper/branches.tmpl b/mercurial/templates/paper/helptopics.tmpl
copy from mercurial/templates/paper/branches.tmpl
copy to mercurial/templates/paper/helptopics.tmpl
--- a/mercurial/templates/paper/branches.tmpl
+++ b/mercurial/templates/paper/helptopics.tmpl
@@ -1,5 +1,5 @@
{header}
-<title>{repo|escape}: branches</title>
+<title>Help: {title}</title>
<link rel="alternate" type="application/atom+xml"
href="{url}atom-tags" title="Atom feed for {repo|escape}: branches" />
<link rel="alternate" type="application/rss+xml"
@@ -17,28 +17,33 @@
<li><a href="{url}shortlog{sessionvars%urlparameter}">log</a></li>
<li><a href="{url}graph{sessionvars%urlparameter}">graph</a></li>
<li><a href="{url}tags{sessionvars%urlparameter}">tags</a></li>
-<li class="active">branches</li>
+<li><a href="{url}branches{sessionvars%urlparameter}">branches</a></li>
+<li class="active"><a href="{url}help{sessionvars%urlparameter}">help</a></li>
</ul>
</div>
<div class="main">
<h2><a href="{url}{sessionvars%urlparameter}">{repo|escape}</a></h2>
-<h3>branches</h3>
-
<form class="search" action="{url}log">
{sessionvars%hiddenformentry}
<p><input name="rev" id="search1" type="text" size="30" /></p>
<div id="hint">find changesets by author, revision,
files, or words in the commit message</div>
</form>
+<table class="bigtable">
+<tr><td colspan="2"><h2>Topics</h2></td></tr>
+{topics % helpentry}
-<table class="bigtable">
-<tr>
- <th>branch</th>
- <th>node</th>
-</tr>
-{entries%branchentry}
+<tr><td colspan="2"><h2>Main Commands</h2></td></tr>
+{earlycommands % helpentry}
+
+<tr><td colspan="2"><h2>Other Commands</h2></td></tr>
+{othercommands % helpentry}
+
+<tr><td colspan="2"><h2>Deprecated Commands</h2></td></tr>
+{deprecated % helpentry}
</table>
+
</div>
</div>
diff --git a/mercurial/templates/paper/manifest.tmpl b/mercurial/templates/paper/manifest.tmpl
--- a/mercurial/templates/paper/manifest.tmpl
+++ b/mercurial/templates/paper/manifest.tmpl
@@ -14,6 +14,7 @@
<li><a href="{url}graph/{node|short}{sessionvars%urlparameter}">graph</a></li>
<li><a href="{url}tags{sessionvars%urlparameter}">tags</a></li>
<li><a href="{url}branches{sessionvars%urlparameter}">branches</a></li>
+<li><a href="{url}help{sessionvars%urlparameter}">help</a></li>
</ul>
<ul>
<li><a href="{url}rev/{node|short}{sessionvars%urlparameter}">changeset</a></li>
diff --git a/mercurial/templates/paper/map b/mercurial/templates/paper/map
--- a/mercurial/templates/paper/map
+++ b/mercurial/templates/paper/map
@@ -9,6 +9,10 @@
shortlog = shortlog.tmpl
shortlogentry = shortlogentry.tmpl
graph = graph.tmpl
+help = help.tmpl
+helptopics = helptopics.tmpl
+
+helpentry = '<tr><td><a href="{url}help/{topic|escape}{sessionvars%urlparameter}">{topic|escape}</a></td><td>{summary|escape}</td></tr>'
naventry = '<a href="{url}log/{node|short}{sessionvars%urlparameter}">{label|escape}</a> '
navshortentry = '<a href="{url}shortlog/{node|short}{sessionvars%urlparameter}">{label|escape}</a> '
diff --git a/mercurial/templates/paper/shortlog.tmpl b/mercurial/templates/paper/shortlog.tmpl
--- a/mercurial/templates/paper/shortlog.tmpl
+++ b/mercurial/templates/paper/shortlog.tmpl
@@ -18,6 +18,7 @@
<li><a href="{url}graph/{node|short}{sessionvars%urlparameter}">graph</a></li>
<li><a href="{url}tags{sessionvars%urlparameter}">tags</a></li>
<li><a href="{url}branches{sessionvars%urlparameter}">branches</a></li>
+<li><a href="{url}help{sessionvars%urlparameter}">help</a></li>
</ul>
<ul>
<li><a href="{url}rev/{node|short}{sessionvars%urlparameter}">changeset</a></li>
diff --git a/mercurial/templates/paper/tags.tmpl b/mercurial/templates/paper/tags.tmpl
--- a/mercurial/templates/paper/tags.tmpl
+++ b/mercurial/templates/paper/tags.tmpl
@@ -18,6 +18,7 @@
<li><a href="{url}graph{sessionvars%urlparameter}">graph</a></li>
<li class="active">tags</li>
<li><a href="{url}branches{sessionvars%urlparameter}">branches</a></li>
+<li><a href="{url}help{sessionvars%urlparameter}">help</a></li>
</ul>
</div>
More information about the Mercurial-devel
mailing list