# HG changeset patch # User Mads Kiilerich # Date 2012-07-05 22:30:18 # Node ID 01d847e0fdc9578ae2f94b42291bcb6a6e5bf89e # Parent 2e13c1bd34dc6afda8fc7cfa22a8cd658276724f 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. diff --git a/hgext/graphlog.py b/hgext/graphlog.py --- a/hgext/graphlog.py +++ b/hgext/graphlog.py @@ -471,7 +471,9 @@ def generate(ui, dag, displayer, showpar 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: diff --git a/tests/test-glog.t b/tests/test-glog.t --- a/tests/test-glog.t +++ b/tests/test-glog.t @@ -2060,4 +2060,30 @@ Test --hidden [] [] +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 ..