changeset 17120:01d847e0fdc9

graphlog: don't truncate template value at last \n Most uses of templates requires a trailing newline to get vertical output. Graphlog with a template without trailing newline did however not just create horisontal output like other commands would but truncated the output at the last \n. Template values without any \n were ignored completely. Graphlog will now only eat one trailing newline before it lets the flow of the graph add the necessary vertical space.
author Mads Kiilerich <mads@kiilerich.com>
date Fri, 06 Jul 2012 00:30:18 +0200
parents 2e13c1bd34dc
children 5d6cbfa975bf
files hgext/graphlog.py tests/test-glog.t
diffstat 2 files changed, 29 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/graphlog.py	Wed Jul 04 17:29:49 2012 +0200
+++ b/hgext/graphlog.py	Fri Jul 06 00:30:18 2012 +0200
@@ -471,7 +471,9 @@
         if filematcher is not None:
             revmatchfn = filematcher(ctx.rev())
         displayer.show(ctx, copies=copies, matchfn=revmatchfn)
-        lines = displayer.hunk.pop(rev).split('\n')[:-1]
+        lines = displayer.hunk.pop(rev).split('\n')
+        if not lines[-1]:
+            del lines[-1]
         displayer.flush(rev)
         edges = edgefn(type, char, lines, seen, rev, parents)
         for type, char, lines, coldata in edges:
--- a/tests/test-glog.t	Wed Jul 04 17:29:49 2012 +0200
+++ b/tests/test-glog.t	Fri Jul 06 00:30:18 2012 +0200
@@ -2060,4 +2060,30 @@
   []
   []
 
+A template without trailing newline should do something sane
+
+  $ hg glog -r ::2 --template '{rev} {desc}'
+  o  2 mv b dir/b
+  |
+  o  1 copy a b
+  |
+
+Extra newlines must be preserved
+
+  $ hg glog -r ::2 --template '\n{rev} {desc}\n\n'
+  o
+  |  2 mv b dir/b
+  |
+  o
+  |  1 copy a b
+  |
+
+The almost-empty template should do something sane too ...
+
+  $ hg glog -r ::2 --template '\n'
+  o
+  |
+  o
+  |
+
   $ cd ..