Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/debugcommands.py @ 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 | e2697acd9381 |
children | 4f37af86d5d5 |
comparison
equal
deleted
inserted
replaced
40173:b797150a1ab9 | 40174:64360202d5b2 |
---|---|
2827 ui.warn("%s\n" % res2) | 2827 ui.warn("%s\n" % res2) |
2828 | 2828 |
2829 def _parsewirelangblocks(fh): | 2829 def _parsewirelangblocks(fh): |
2830 activeaction = None | 2830 activeaction = None |
2831 blocklines = [] | 2831 blocklines = [] |
2832 lastindent = 0 | |
2832 | 2833 |
2833 for line in fh: | 2834 for line in fh: |
2834 line = line.rstrip() | 2835 line = line.rstrip() |
2835 if not line: | 2836 if not line: |
2836 continue | 2837 continue |
2843 if activeaction: | 2844 if activeaction: |
2844 yield activeaction, blocklines | 2845 yield activeaction, blocklines |
2845 | 2846 |
2846 activeaction = line | 2847 activeaction = line |
2847 blocklines = [] | 2848 blocklines = [] |
2849 lastindent = 0 | |
2848 continue | 2850 continue |
2849 | 2851 |
2850 # Else we start with an indent. | 2852 # Else we start with an indent. |
2851 | 2853 |
2852 if not activeaction: | 2854 if not activeaction: |
2853 raise error.Abort(_('indented line outside of block')) | 2855 raise error.Abort(_('indented line outside of block')) |
2854 | 2856 |
2855 blocklines.append(line) | 2857 indent = len(line) - len(line.lstrip()) |
2858 | |
2859 # If this line is indented more than the last line, concatenate it. | |
2860 if indent > lastindent and blocklines: | |
2861 blocklines[-1] += line.lstrip() | |
2862 else: | |
2863 blocklines.append(line) | |
2864 lastindent = indent | |
2856 | 2865 |
2857 # Flush last block. | 2866 # Flush last block. |
2858 if activeaction: | 2867 if activeaction: |
2859 yield activeaction, blocklines | 2868 yield activeaction, blocklines |
2860 | 2869 |