Patchwork [3,of,5] help: pass around ui to doc loader (API)

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 29, 2015, 3:59 p.m.
Message ID <d5f153597bd786bd50c8.1443542374@mimosa>
Download mbox | patch
Permalink /patch/10685/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 29, 2015, 3:59 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1443236790 -32400
#      Sat Sep 26 12:06:30 2015 +0900
# Node ID d5f153597bd786bd50c8fa16d11d21bcc9fa55aa
# Parent  52e2b23458b3249308d7ab277d861d452e1570ae
help: pass around ui to doc loader (API)

This is necessary to hide DEPRECATED items conditionally.

Flagged as API change because it will break "hg help git|subversion".

Patch

diff --git a/doc/check-seclevel.py b/doc/check-seclevel.py
--- a/doc/check-seclevel.py
+++ b/doc/check-seclevel.py
@@ -79,7 +79,7 @@  def checkhghelps(ui):
     errorcnt = 0
     for names, sec, doc in helptable:
         if callable(doc):
-            doc = doc()
+            doc = doc(ui)
         errorcnt += checkseclevel(ui, doc,
                                   '%s help topic' % names[0],
                                   initlevel_topic)
diff --git a/doc/gendoc.py b/doc/gendoc.py
--- a/doc/gendoc.py
+++ b/doc/gendoc.py
@@ -138,7 +138,7 @@  def helpprinter(ui, helptable, sectionfu
         if sectionfunc:
             ui.write(sectionfunc(sec))
         if callable(doc):
-            doc = doc()
+            doc = doc(ui)
         ui.write(doc)
         ui.write("\n")
 
diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -34,8 +34,8 @@  def listexts(header, exts, indent=1, sho
             rst.append('%s:%s: %s\n' % (' ' * indent, name, desc))
     return rst
 
-def extshelp():
-    rst = loaddoc('extensions')().splitlines(True)
+def extshelp(ui):
+    rst = loaddoc('extensions')(ui).splitlines(True)
     rst.extend(listexts(
         _('enabled extensions:'), extensions.enabled(), showdeprecated=True))
     rst.extend(listexts(_('disabled extensions:'), extensions.disabled()))
@@ -83,7 +83,7 @@  def indicateomitted(rst, omitted, notomi
     if notomitted:
         rst.append('\n\n.. container:: notomitted\n\n    %s\n\n' % notomitted)
 
-def topicmatch(kw):
+def topicmatch(ui, kw):
     """Return help topics matching kw.
 
     Returns {'section': [(name, summary), ...], ...} where section is
@@ -101,7 +101,7 @@  def topicmatch(kw):
         # Old extensions may use a str as doc.
         if (sum(map(lowercontains, names))
             or lowercontains(header)
-            or (callable(doc) and lowercontains(doc()))):
+            or (callable(doc) and lowercontains(doc(ui)))):
             results['topics'].append((names[0], header))
     import commands # avoid cycle
     for cmd, entry in commands.table.iteritems():
@@ -139,7 +139,7 @@  def topicmatch(kw):
 def loaddoc(topic):
     """Return a delayed loader for help/topic.txt."""
 
-    def loader():
+    def loader(ui):
         docdir = os.path.join(util.datapath, 'help')
         path = os.path.join(docdir, topic + ".txt")
         doc = gettext(util.readfile(path))
@@ -415,7 +415,7 @@  def help_(ui, name, unknowncmd=False, fu
         if not doc:
             rst.append("    %s\n" % _("(no help text available)"))
         if callable(doc):
-            rst += ["    %s\n" % l for l in doc().splitlines()]
+            rst += ["    %s\n" % l for l in doc(ui).splitlines()]
 
         if not ui.verbose:
             omitted = _('(some details hidden, use --verbose'
@@ -482,7 +482,7 @@  def help_(ui, name, unknowncmd=False, fu
     rst = []
     kw = opts.get('keyword')
     if kw:
-        matches = topicmatch(name)
+        matches = topicmatch(ui, name)
         helpareas = []
         if opts.get('extension'):
             helpareas += [('extensions', _('Extensions'))]
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -1105,7 +1105,7 @@  Test omit indicating for help
   > def extsetup(ui):
   >     help.helptable.append((["topic-containing-verbose"],
   >                            "This is the topic to test omit indicating.",
-  >                            lambda : testtopic))
+  >                            lambda ui: testtopic))
   > EOF
   $ echo '[extensions]' >> $HGRCPATH
   $ echo "addverboseitems = `pwd`/addverboseitems.py" >> $HGRCPATH