Patchwork [5,of,7] help: reorder section filtering flow to not format help text twice

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 22, 2018, 12:19 p.m.
Message ID <7ba0774e0bbdb9ed5b87.1534940393@mimosa>
Download mbox | patch
Permalink /patch/33971/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 22, 2018, 12:19 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1533439243 -32400
#      Sun Aug 05 12:20:43 2018 +0900
# Node ID 7ba0774e0bbdb9ed5b87a9e27bef443adab09c85
# Parent  f2a08652109f187a75d00dd2af76ba51fb7494e1
help: reorder section filtering flow to not format help text twice

Patch

diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -673,16 +673,6 @@  def formattedhelp(ui, commands, name, ke
                  subtopic=subtopic, unknowncmd=unknowncmd, full=full, **opts)
 
     blocks, pruned = minirst.parse(text, keep=keep)
-    if section:
-        blocks = minirst.filtersections(blocks, section)
-    formatted = minirst.formatplain(blocks, textwidth)
-
-    # We could have been given a weird ".foo" section without a name
-    # to look for, or we could have simply failed to found "foo.bar"
-    # because bar isn't a section of foo
-    if section and not (formatted and name):
-        raise error.Abort(_("help section not found: %s") % fullname)
-
     if 'verbose' in pruned:
         keep.append('omitted')
     else:
@@ -690,4 +680,11 @@  def formattedhelp(ui, commands, name, ke
     blocks, pruned = minirst.parse(text, keep=keep)
     if section:
         blocks = minirst.filtersections(blocks, section)
+
+    # We could have been given a weird ".foo" section without a name
+    # to look for, or we could have simply failed to found "foo.bar"
+    # because bar isn't a section of foo
+    if section and not (blocks and name):
+        raise error.Abort(_("help section not found: %s") % fullname)
+
     return minirst.formatplain(blocks, textwidth)