Mercurial > hg-stable
changeset 14318:1f46be4689ed
help: consolidate topic hooks in help.py
This removes loops like cmdutil->revset->help->extensions->cmdutil and
simplifies the code.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 13 May 2011 12:57:27 -0500 |
parents | 660b0c1b6196 |
children | b33f3e35efb0 |
files | mercurial/commands.py mercurial/extensions.py mercurial/help.py mercurial/revset.py mercurial/templatefilters.py mercurial/templatekw.py |
diffstat | 6 files changed, 16 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Fri May 13 11:04:51 2011 -0500 +++ b/mercurial/commands.py Fri May 13 12:57:27 2011 -0500 @@ -13,7 +13,7 @@ import patch, help, url, encoding, templatekw, discovery import archival, changegroup, cmdutil, sshserver, hbisect, hgweb, hgweb.server import merge as mergemod -import minirst, revset, templatefilters +import minirst, revset import dagparser, context, simplemerge import random, setdiscovery, treediscovery, dagutil @@ -2758,10 +2758,6 @@ ui.write(_('use "hg help extensions" for information on enabling ' 'extensions\n')) - help.addtopichook('revsets', revset.makedoc) - help.addtopichook('templates', templatekw.makedoc) - help.addtopichook('templates', templatefilters.makedoc) - if name and name != 'shortlist': i = None if unknowncmd:
--- a/mercurial/extensions.py Fri May 13 11:04:51 2011 -0500 +++ b/mercurial/extensions.py Fri May 13 12:57:27 2011 -0500 @@ -248,7 +248,7 @@ except IOError: return else: - doc = moduledoc(file) + doc = _moduledoc(file) file.close() if doc: # extracting localized synopsis
--- a/mercurial/help.py Fri May 13 11:04:51 2011 -0500 +++ b/mercurial/help.py Fri May 13 12:57:27 2011 -0500 @@ -7,7 +7,7 @@ from i18n import gettext, _ import sys, os -import extensions +import extensions, revset, templatekw, templatefilters import util def listexts(header, exts, indent=1): @@ -76,8 +76,7 @@ # Map topics to lists of callable taking the current topic help and # returning the updated version -helphooks = { -} +helphooks = {} def addtopichook(topic, rewriter): helphooks.setdefault(topic, []).append(rewriter) @@ -97,3 +96,12 @@ entries.append('\n'.join(lines)) entries = '\n\n'.join(entries) return doc.replace(marker, entries) + +def addtopicsymbols(topic, marker, symbols): + def add(topic, doc): + return makeitemsdoc(topic, doc, marker, symbols) + addtopichook(topic, add) + +addtopicsymbols('revsets', '.. predicatesmarker', revset.symbols) +addtopicsymbols('templates', '.. keywordsmarker', templatekw.keywords) +addtopicsymbols('templates', '.. filtersmarker', templatefilters.filters)
--- a/mercurial/revset.py Fri May 13 11:04:51 2011 -0500 +++ b/mercurial/revset.py Fri May 13 12:57:27 2011 -0500 @@ -6,7 +6,7 @@ # GNU General Public License version 2 or any later version. import re -import parser, util, error, discovery, help, hbisect +import parser, util, error, discovery, hbisect import bookmarks as bookmarksmod import match as matchmod from i18n import _ @@ -981,8 +981,5 @@ return getset(repo, subset, tree) return mfunc -def makedoc(topic, doc): - return help.makeitemsdoc(topic, doc, '.. predicatesmarker', symbols) - # tell hggettext to extract docstrings from these functions: i18nfunctions = symbols.values()
--- a/mercurial/templatefilters.py Fri May 13 11:04:51 2011 -0500 +++ b/mercurial/templatefilters.py Fri May 13 12:57:27 2011 -0500 @@ -6,7 +6,7 @@ # GNU General Public License version 2 or any later version. import cgi, re, os, time, urllib -import encoding, node, util, help +import encoding, node, util def addbreaks(text): """:addbreaks: Any text. Add an XHTML "<br />" tag before the end of @@ -358,8 +358,5 @@ "xmlescape": xmlescape, } -def makedoc(topic, doc): - return help.makeitemsdoc(topic, doc, '.. filtersmarker', filters) - # tell hggettext to extract docstrings from these functions: i18nfunctions = filters.values()
--- a/mercurial/templatekw.py Fri May 13 11:04:51 2011 -0500 +++ b/mercurial/templatekw.py Fri May 13 12:57:27 2011 -0500 @@ -6,7 +6,7 @@ # GNU General Public License version 2 or any later version. from node import hex -import patch, util, error, help +import patch, util, error def showlist(name, values, plural=None, **args): '''expand set of values. @@ -313,8 +313,5 @@ 'tags': showtags, } -def makedoc(topic, doc): - return help.makeitemsdoc(topic, doc, '.. keywordsmarker', keywords) - # tell hggettext to extract docstrings from these functions: i18nfunctions = keywords.values()