[PATCH] annotate: append newline after non newline-terminated file listings

Ion Savin comp_ at gmx.net
Tue Jan 10 08:30:42 UTC 2012


> On Mon, 2012-01-09 at 00:27 +0200, Ion Savin wrote:
> > # HG changeset patch
> > # User Ion Savin <comp_ at gmx.net>
> > # Date 1326061171 -7200
> > # Node ID afadfd2e74bf5325aa115710c728f425e6b9cd96
> > # Parent  f15c646bffc7187c357f3dcc12761513c1ed6609
> > annotate: append newline after non newline-terminated file listings
> > 
> > The last line of a non newline-terminated file would mix with the first 
> > line of
> > the next file in multiple-file listings before this patch.
> 
> 
> > +            if not lines[-1][1].endswith('\n'):
> > +                ui.write('\n')
> 
> I bet this breaks if there are zero lines.

It shouldn't break as the condition is evaluated only when "pieces" is not-empty and this is non-empty when "lines" is non-empty. Hope I'm not missing something.

Resending with empty file testcase (which passes for the previous patch also) and a more robust condition.

# HG changeset patch
# User Ion Savin <ion.savin at tora.com>
# Date 1326183499 -7200
# Node ID 77e105251e224468999c45506fb25d3999fcd61d
# Parent  94a4748db392c2bd03b05db64151fe7bea8bd102
annotate: append newline after non newline-terminated file listings

The last line of a non newline-terminated file would mix with the first line of
the next file in multiple-file listings before this patch.

Possible compatibility issue: no longer possible to tell from the annotate
output if the file is terminated by new line or not.

diff -r 94a4748db392 -r 77e105251e22 mercurial/commands.py
--- a/mercurial/commands.py     Sat Jan 07 17:03:33 2012 +0100
+++ b/mercurial/commands.py     Tue Jan 10 10:18:19 2012 +0200
@@ -299,6 +299,9 @@
             for p, l in zip(zip(*pieces), lines):
                 ui.write("%s: %s" % ("".join(p), l[1]))
 
+            if lines and not lines[-1][1].endswith('\n'):
+                ui.write('\n')
+
 @command('archive',
     [('', 'no-decode', None, _('do not pass files through decoders')),
     ('p', 'prefix', '', _('directory prefix for files in archive'),
diff -r 94a4748db392 -r 77e105251e22 tests/test-annotate.t
--- a/tests/test-annotate.t     Sat Jan 07 17:03:33 2012 +0100
+++ b/tests/test-annotate.t     Tue Jan 10 10:18:19 2012 +0200
@@ -255,6 +255,18 @@
   abort: nosuchfile: no such file in rev e9e6b4fa872f
   [255]
 
+annotate file without '\n' on last line
+
+  $ printf "" > c
+  $ hg ci -A -m test -u nobody -d '1 0'
+  adding c
+  $ hg annotate c
+  $ printf "a\nb" > c
+  $ hg ci -m test
+  $ hg annotate c
+  [0-9]+: a (re)
+  [0-9]+: b (re)
+
 Test annotate with whitespace options
 
   $ cd ..
-- 
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!		
Jetzt informieren: http://www.gmx.net/de/go/freephone



More information about the Mercurial-devel mailing list