Patchwork [STABLE] annotate: do not poorly split lines at CR (issue5798)

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 21, 2018, 12:49 p.m.
Message ID <24b17a714a92c8fe860d.1519217381@mimosa>
Download mbox | patch
Permalink /patch/28181/
State Accepted
Headers show

Comments

Yuya Nishihara - Feb. 21, 2018, 12:49 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1519215245 -32400
#      Wed Feb 21 21:14:05 2018 +0900
# Branch stable
# Node ID 24b17a714a92c8fe860db5f6d0d49c23293deec6
# Parent  c19e66dacaa184feba31136c18a369ba995ddfe4
annotate: do not poorly split lines at CR (issue5798)

mdiff and lines(text) take only LF as a line separator, but str.splitlines()
breaks our assumption. Use mdiff.splitnewlines() consistently.

It's hard to read \r in tests, so \r is replaced with [CR]. I had to wrap
sed by a shell function to silence check-code warning.
Augie Fackler - March 2, 2018, 12:52 a.m.
> On Feb 21, 2018, at 07:49, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1519215245 -32400
> #      Wed Feb 21 21:14:05 2018 +0900
> # Branch stable
> # Node ID 24b17a714a92c8fe860db5f6d0d49c23293deec6
> # Parent  c19e66dacaa184feba31136c18a369ba995ddfe4
> annotate: do not poorly split lines at CR (issue5798)

queued, thanks

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1121,7 +1121,8 @@  class basefilectx(object):
                 hist[f] = curr
                 del pcache[f]
 
-        return pycompat.ziplist(hist[base][0], hist[base][1].splitlines(True))
+        lineattrs, text = hist[base]
+        return pycompat.ziplist(lineattrs, mdiff.splitnewlines(text))
 
     def ancestors(self, followfirst=False):
         visit = {}
diff --git a/tests/test-annotate.t b/tests/test-annotate.t
--- a/tests/test-annotate.t
+++ b/tests/test-annotate.t
@@ -895,6 +895,38 @@  Annotate with --ignore-blank-lines (simi
 
   $ cd ..
 
+Annotate with orphaned CR (issue5798)
+-------------------------------------
+
+  $ hg init repo-cr
+  $ cd repo-cr
+
+  $ substcr() {
+  > sed 's/\r/[CR]/g'
+  > }
+
+  >>> with open('a', 'wb') as f:
+  ...     f.write(b'0a\r0b\r\n0c\r0d\r\n0e\n0f\n0g')
+  $ hg ci -qAm0
+  >>> with open('a', 'wb') as f:
+  ...     f.write(b'0a\r0b\r\n1c\r1d\r\n0e\n1f\n0g')
+  $ hg ci -m1
+
+  $ hg annotate -r0 a | substcr
+  0: 0a[CR]0b[CR]
+  0: 0c[CR]0d[CR]
+  0: 0e
+  0: 0f
+  0: 0g
+  $ hg annotate -r1 a | substcr
+  0: 0a[CR]0b[CR]
+  1: 1c[CR]1d[CR]
+  0: 0e
+  1: 1f
+  0: 0g
+
+  $ cd ..
+
 Annotate with linkrev pointing to another branch
 ------------------------------------------------