Comments
Patch
@@ -1507,16 +1507,16 @@
Test indent with empty first line
$ hg version -T "{indent('', '>> ')}\n"
- >>
+
$ hg version -T "{indent('
> second', '>> ')}\n"
- >>
+
>> second
$ hg version -T "{indent('
> second', '>> ', ' > ')}\n"
- >
+
>> second
Test with non-strings like dates
@@ -6,6 +6,9 @@
== Bug Fixes ==
+ * The `indent()` template function was documented to not indent empty lines,
+ but it still indented the first line even if it was empty. It no longer does
+ that.
== Backwards Compatibility Changes ==
@@ -310,13 +310,11 @@
text = evalstring(context, mapping, args[0])
indent = evalstring(context, mapping, args[1])
+ firstline = indent
if len(args) == 3:
firstline = evalstring(context, mapping, args[2])
- else:
- firstline = indent
- # the indent function doesn't indent the first line, so we do it here
- return templatefilters.indent(firstline + text, indent)
+ return templatefilters.indent(text, indent, firstline=firstline)
@templatefunc(b'get(dict, key)')
@@ -299,7 +299,7 @@
return dateutil.datestr(text, b'%Y-%m-%d %H:%M:%S %1%2')
-def indent(text, prefix):
+def indent(text, prefix, firstline=b''):
'''indent each non-empty line of text after first with prefix.'''
lines = text.splitlines()
num_lines = len(lines)
@@ -308,8 +308,8 @@
def indenter():
for i in pycompat.xrange(num_lines):
l = lines[i]
- if i and l.strip():
- yield prefix
+ if l.strip():
+ yield prefix if i else firstline
yield l
if i < num_lines - 1 or endswithnewline:
yield b'\n'