changeset 40174:64360202d5b2

debugcommands: support wrapping long lines If a line within a block is indented more than the line that came before, we automatically concatenate it with the previous line. This allows us to pretty format data. This will make tests easier to read. At some point we may just want to evaluate entire blocks as Python code or something, as even with this change, things aren't perfect, as we can't e.g. have formatting like: foo eval:[ True ] But this is strictly better than before, where we couldn't wrap long lines. Differential Revision: https://phab.mercurial-scm.org/D4977
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 11 Oct 2018 09:47:52 +0200
parents b797150a1ab9
children 6c42409691ec
files mercurial/debugcommands.py
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/debugcommands.py	Wed Oct 03 13:17:00 2018 -0700
+++ b/mercurial/debugcommands.py	Thu Oct 11 09:47:52 2018 +0200
@@ -2829,6 +2829,7 @@
 def _parsewirelangblocks(fh):
     activeaction = None
     blocklines = []
+    lastindent = 0
 
     for line in fh:
         line = line.rstrip()
@@ -2845,6 +2846,7 @@
 
             activeaction = line
             blocklines = []
+            lastindent = 0
             continue
 
         # Else we start with an indent.
@@ -2852,7 +2854,14 @@
         if not activeaction:
             raise error.Abort(_('indented line outside of block'))
 
-        blocklines.append(line)
+        indent = len(line) - len(line.lstrip())
+
+        # If this line is indented more than the last line, concatenate it.
+        if indent > lastindent and blocklines:
+            blocklines[-1] += line.lstrip()
+        else:
+            blocklines.append(line)
+            lastindent = indent
 
     # Flush last block.
     if activeaction: