2006-12-06 01:06:13 +03:00
|
|
|
# help.py - help data for mercurial
|
|
|
|
#
|
|
|
|
# Copyright 2006 Matt Mackall <mpm@selenic.com>
|
|
|
|
#
|
2009-04-26 03:08:54 +04:00
|
|
|
# This software may be used and distributed according to the terms of the
|
2010-01-20 07:20:08 +03:00
|
|
|
# GNU General Public License version 2 or any later version.
|
2006-12-06 01:06:13 +03:00
|
|
|
|
2009-10-04 11:59:13 +04:00
|
|
|
from i18n import gettext, _
|
2012-05-13 13:27:08 +04:00
|
|
|
import itertools, sys, os
|
2012-02-12 16:38:12 +04:00
|
|
|
import extensions, revset, fileset, templatekw, templatefilters, filemerge
|
2012-05-23 00:08:41 +04:00
|
|
|
import encoding, util, minirst
|
2009-06-20 22:55:43 +04:00
|
|
|
|
2011-05-13 20:04:51 +04:00
|
|
|
def listexts(header, exts, indent=1):
|
2009-06-21 19:52:30 +04:00
|
|
|
'''return a text listing of the given extensions'''
|
2012-06-02 13:22:33 +04:00
|
|
|
rst = []
|
|
|
|
if exts:
|
|
|
|
rst.append('\n%s\n\n' % header)
|
|
|
|
for name, desc in sorted(exts.iteritems()):
|
|
|
|
rst.append('%s:%s: %s\n' % (' ' * indent, name, desc))
|
|
|
|
return rst
|
2009-06-20 22:55:49 +04:00
|
|
|
|
2009-06-21 19:52:30 +04:00
|
|
|
def extshelp():
|
2012-06-02 13:22:33 +04:00
|
|
|
rst = loaddoc('extensions')().splitlines(True)
|
|
|
|
rst.extend(listexts(_('enabled extensions:'), extensions.enabled()))
|
|
|
|
rst.extend(listexts(_('disabled extensions:'), extensions.disabled()))
|
|
|
|
doc = ''.join(rst)
|
2009-06-20 22:55:43 +04:00
|
|
|
return doc
|
2008-09-09 23:32:39 +04:00
|
|
|
|
2012-05-23 00:08:41 +04:00
|
|
|
def optrst(options, verbose):
|
|
|
|
data = []
|
|
|
|
multioccur = False
|
|
|
|
for option in options:
|
|
|
|
if len(option) == 5:
|
|
|
|
shortopt, longopt, default, desc, optlabel = option
|
|
|
|
else:
|
|
|
|
shortopt, longopt, default, desc = option
|
|
|
|
optlabel = _("VALUE") # default label
|
|
|
|
|
|
|
|
if _("DEPRECATED") in desc and not verbose:
|
|
|
|
continue
|
|
|
|
|
|
|
|
so = ''
|
|
|
|
if shortopt:
|
|
|
|
so = '-' + shortopt
|
|
|
|
lo = '--' + longopt
|
|
|
|
if default:
|
|
|
|
desc += _(" (default: %s)") % default
|
|
|
|
|
|
|
|
if isinstance(default, list):
|
|
|
|
lo += " %s [+]" % optlabel
|
|
|
|
multioccur = True
|
|
|
|
elif (default is not None) and not isinstance(default, bool):
|
|
|
|
lo += " %s" % optlabel
|
|
|
|
|
|
|
|
data.append((so, lo, desc))
|
|
|
|
|
|
|
|
rst = minirst.maketable(data, 1)
|
|
|
|
|
|
|
|
if multioccur:
|
2012-06-01 13:58:23 +04:00
|
|
|
rst.append(_("\n[+] marked option can be specified multiple times\n"))
|
2012-05-23 00:08:41 +04:00
|
|
|
|
2012-06-01 13:58:23 +04:00
|
|
|
return ''.join(rst)
|
2012-05-23 00:08:41 +04:00
|
|
|
|
help: indicate help omitting if help document is not fully displayed
Before this patch, there is no information about whether help document
is fully displayed or not.
So, some users seem to misunderstand "-v" for "hg help" just as "the
option to show list of global options": experience on "hg help -v" for
some commands not containing verbose containers may strengthen this
misunderstanding.
Such users have less opportunity for noticing omitted help document,
and this may cause insufficient understanding about Mercurial.
This patch indicates help omitting, if help document is not fully
displayed.
For command help, the message below is displayed at the end of help
output, if help document is not fully displayed:
use "hg -v help xxxx" to show more complete help and the global
options
and otherwise:
use "hg -v help xxxx" to show the global options
For topics and extensions help, the message below is displayed, only
if help document is not fully displayed:
use "hg help -v xxxx" to show more complete help
This allows users to know whether there is any omitted information or
not exactly, and can trigger "hg help -v" invocation.
This patch causes formatting help document twice, to switch messages
one for omitted help, and another for not omitted. This decreases
performance of help document formatting, but it is not mainly focused
at help command invocation, so this wouldn't become problem.
2012-10-18 05:31:15 +04:00
|
|
|
def indicateomitted(rst, omitted, notomitted=None):
|
|
|
|
rst.append('\n\n.. container:: omitted\n\n %s\n\n' % omitted)
|
|
|
|
if notomitted:
|
|
|
|
rst.append('\n\n.. container:: notomitted\n\n %s\n\n' % notomitted)
|
|
|
|
|
2012-05-13 13:27:08 +04:00
|
|
|
def topicmatch(kw):
|
|
|
|
"""Return help topics matching kw.
|
|
|
|
|
|
|
|
Returns {'section': [(name, summary), ...], ...} where section is
|
|
|
|
one of topics, commands, extensions, or extensioncommands.
|
|
|
|
"""
|
|
|
|
kw = encoding.lower(kw)
|
|
|
|
def lowercontains(container):
|
2012-06-04 10:45:56 +04:00
|
|
|
return kw in encoding.lower(container) # translated in helptable
|
2012-05-13 13:27:08 +04:00
|
|
|
results = {'topics': [],
|
|
|
|
'commands': [],
|
|
|
|
'extensions': [],
|
|
|
|
'extensioncommands': [],
|
|
|
|
}
|
|
|
|
for names, header, doc in helptable:
|
|
|
|
if (sum(map(lowercontains, names))
|
|
|
|
or lowercontains(header)
|
|
|
|
or lowercontains(doc())):
|
|
|
|
results['topics'].append((names[0], header))
|
|
|
|
import commands # avoid cycle
|
|
|
|
for cmd, entry in commands.table.iteritems():
|
|
|
|
if cmd.startswith('debug'):
|
|
|
|
continue
|
|
|
|
if len(entry) == 3:
|
|
|
|
summary = entry[2]
|
|
|
|
else:
|
|
|
|
summary = ''
|
2012-06-04 10:45:56 +04:00
|
|
|
# translate docs *before* searching there
|
|
|
|
docs = _(getattr(entry[0], '__doc__', None)) or ''
|
2012-05-13 13:27:08 +04:00
|
|
|
if kw in cmd or lowercontains(summary) or lowercontains(docs):
|
2012-06-04 10:45:56 +04:00
|
|
|
doclines = docs.splitlines()
|
2012-05-13 13:27:08 +04:00
|
|
|
if doclines:
|
|
|
|
summary = doclines[0]
|
|
|
|
cmdname = cmd.split('|')[0].lstrip('^')
|
|
|
|
results['commands'].append((cmdname, summary))
|
|
|
|
for name, docs in itertools.chain(
|
|
|
|
extensions.enabled().iteritems(),
|
|
|
|
extensions.disabled().iteritems()):
|
|
|
|
# extensions.load ignores the UI argument
|
|
|
|
mod = extensions.load(None, name, '')
|
|
|
|
if lowercontains(name) or lowercontains(docs):
|
2012-06-04 10:45:56 +04:00
|
|
|
# extension docs are already translated
|
|
|
|
results['extensions'].append((name, docs.splitlines()[0]))
|
2012-05-13 13:27:08 +04:00
|
|
|
for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems():
|
2012-05-13 15:03:11 +04:00
|
|
|
if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])):
|
2012-05-13 13:27:08 +04:00
|
|
|
cmdname = cmd.split('|')[0].lstrip('^')
|
2012-06-07 03:42:50 +04:00
|
|
|
if entry[0].__doc__:
|
|
|
|
cmddoc = gettext(entry[0].__doc__).splitlines()[0]
|
2012-06-07 17:54:40 +04:00
|
|
|
else:
|
|
|
|
cmddoc = _('(no help text available)')
|
|
|
|
results['extensioncommands'].append((cmdname, cmddoc))
|
2012-05-13 13:27:08 +04:00
|
|
|
return results
|
|
|
|
|
2009-10-04 11:59:13 +04:00
|
|
|
def loaddoc(topic):
|
|
|
|
"""Return a delayed loader for help/topic.txt."""
|
2007-12-05 14:40:01 +03:00
|
|
|
|
2009-10-04 11:59:13 +04:00
|
|
|
def loader():
|
2011-07-26 01:14:02 +04:00
|
|
|
if util.mainfrozen():
|
2009-10-04 11:59:13 +04:00
|
|
|
module = sys.executable
|
|
|
|
else:
|
|
|
|
module = __file__
|
|
|
|
base = os.path.dirname(module)
|
2006-12-06 01:31:08 +03:00
|
|
|
|
2009-10-04 11:59:13 +04:00
|
|
|
for dir in ('.', '..'):
|
|
|
|
docdir = os.path.join(base, dir, 'help')
|
|
|
|
if os.path.isdir(docdir):
|
|
|
|
break
|
2009-01-22 21:02:50 +03:00
|
|
|
|
2009-10-04 11:59:13 +04:00
|
|
|
path = os.path.join(docdir, topic + ".txt")
|
2011-05-02 12:11:18 +04:00
|
|
|
doc = gettext(util.readfile(path))
|
2010-10-23 21:21:49 +04:00
|
|
|
for rewriter in helphooks.get(topic, []):
|
|
|
|
doc = rewriter(topic, doc)
|
|
|
|
return doc
|
|
|
|
|
2009-10-04 11:59:13 +04:00
|
|
|
return loader
|
2009-01-22 21:02:50 +03:00
|
|
|
|
2011-04-05 08:40:47 +04:00
|
|
|
helptable = sorted([
|
2010-09-02 14:53:28 +04:00
|
|
|
(["config", "hgrc"], _("Configuration Files"), loaddoc('config')),
|
2009-10-04 11:59:13 +04:00
|
|
|
(["dates"], _("Date Formats"), loaddoc('dates')),
|
|
|
|
(["patterns"], _("File Name Patterns"), loaddoc('patterns')),
|
2010-01-25 09:05:27 +03:00
|
|
|
(['environment', 'env'], _('Environment Variables'),
|
|
|
|
loaddoc('environment')),
|
2012-08-01 16:59:15 +04:00
|
|
|
(['revisions', 'revs'], _('Specifying Single Revisions'),
|
2010-01-25 09:05:27 +03:00
|
|
|
loaddoc('revisions')),
|
2012-08-01 16:59:15 +04:00
|
|
|
(['multirevs', 'mrevs'], _('Specifying Multiple Revisions'),
|
2010-01-25 09:05:27 +03:00
|
|
|
loaddoc('multirevs')),
|
2012-08-01 16:59:15 +04:00
|
|
|
(['revsets', 'revset'], _("Specifying Revision Sets"), loaddoc('revsets')),
|
|
|
|
(['filesets', 'fileset'], _("Specifying File Sets"), loaddoc('filesets')),
|
2009-10-04 11:59:13 +04:00
|
|
|
(['diffs'], _('Diff Formats'), loaddoc('diffs')),
|
2012-08-01 02:20:10 +04:00
|
|
|
(['merge-tools', 'mergetools'], _('Merge Tools'), loaddoc('merge-tools')),
|
2012-05-02 01:14:51 +04:00
|
|
|
(['templating', 'templates', 'template', 'style'], _('Template Usage'),
|
2010-01-25 09:05:27 +03:00
|
|
|
loaddoc('templates')),
|
2009-10-04 11:59:13 +04:00
|
|
|
(['urls'], _('URL Paths'), loaddoc('urls')),
|
2012-04-30 13:51:24 +04:00
|
|
|
(["extensions"], _("Using Additional Features"), extshelp),
|
2012-08-01 16:59:15 +04:00
|
|
|
(["subrepos", "subrepo"], _("Subrepositories"), loaddoc('subrepos')),
|
2012-08-01 02:18:23 +04:00
|
|
|
(["hgweb"], _("Configuring hgweb"), loaddoc('hgweb')),
|
|
|
|
(["glossary"], _("Glossary"), loaddoc('glossary')),
|
|
|
|
(["hgignore", "ignore"], _("Syntax for Mercurial Ignore Files"),
|
|
|
|
loaddoc('hgignore')),
|
|
|
|
(["phases"], _("Working with Phases"), loaddoc('phases')),
|
2011-04-05 08:40:47 +04:00
|
|
|
])
|
2010-10-23 21:21:49 +04:00
|
|
|
|
|
|
|
# Map topics to lists of callable taking the current topic help and
|
|
|
|
# returning the updated version
|
2011-05-13 21:57:27 +04:00
|
|
|
helphooks = {}
|
2010-10-23 21:21:49 +04:00
|
|
|
|
|
|
|
def addtopichook(topic, rewriter):
|
|
|
|
helphooks.setdefault(topic, []).append(rewriter)
|
2011-03-12 14:46:31 +03:00
|
|
|
|
|
|
|
def makeitemsdoc(topic, doc, marker, items):
|
|
|
|
"""Extract docstring from the items key to function mapping, build a
|
|
|
|
.single documentation block and use it to overwrite the marker in doc
|
|
|
|
"""
|
|
|
|
entries = []
|
|
|
|
for name in sorted(items):
|
|
|
|
text = (items[name].__doc__ or '').rstrip()
|
|
|
|
if not text:
|
|
|
|
continue
|
|
|
|
text = gettext(text)
|
|
|
|
lines = text.splitlines()
|
2012-03-10 01:54:17 +04:00
|
|
|
doclines = [(lines[0])]
|
|
|
|
for l in lines[1:]:
|
|
|
|
# Stop once we find some Python doctest
|
|
|
|
if l.strip().startswith('>>>'):
|
|
|
|
break
|
|
|
|
doclines.append(' ' + l.strip())
|
|
|
|
entries.append('\n'.join(doclines))
|
2011-03-12 14:46:31 +03:00
|
|
|
entries = '\n\n'.join(entries)
|
|
|
|
return doc.replace(marker, entries)
|
2011-05-13 21:57:27 +04:00
|
|
|
|
|
|
|
def addtopicsymbols(topic, marker, symbols):
|
|
|
|
def add(topic, doc):
|
|
|
|
return makeitemsdoc(topic, doc, marker, symbols)
|
|
|
|
addtopichook(topic, add)
|
|
|
|
|
2011-06-19 01:53:49 +04:00
|
|
|
addtopicsymbols('filesets', '.. predicatesmarker', fileset.symbols)
|
2012-02-12 16:38:12 +04:00
|
|
|
addtopicsymbols('merge-tools', '.. internaltoolsmarker', filemerge.internals)
|
2011-05-13 21:57:27 +04:00
|
|
|
addtopicsymbols('revsets', '.. predicatesmarker', revset.symbols)
|
2012-07-10 20:11:53 +04:00
|
|
|
addtopicsymbols('templates', '.. keywordsmarker', templatekw.dockeywords)
|
2011-05-13 21:57:27 +04:00
|
|
|
addtopicsymbols('templates', '.. filtersmarker', templatefilters.filters)
|