[Bug 5798] New: annotate output is broken if the file contains multiple CR in a line

mercurial-bugs at mercurial-scm.org mercurial-bugs at mercurial-scm.org
Tue Feb 20 09:59:09 EST 2018


https://bz.mercurial-scm.org/show_bug.cgi?id=5798

            Bug ID: 5798
           Summary: annotate output is broken if the file contains
                    multiple CR in a line
           Product: Mercurial
           Version: default branch
          Hardware: PC
                OS: Linux
            Status: UNCONFIRMED
          Severity: bug
          Priority: wish
         Component: Mercurial
          Assignee: bugzilla at mercurial-scm.org
          Reporter: hdk_2 at users.sourceforge.net
                CC: mercurial-devel at mercurial-scm.org

I found an incorrect output from hg annotate when I wrote a shell
script with multiple CR in a line, for example:

------------------------------------------------------------
echo -n Wait
sleep 1
echo -n '^M    ^M'
# Note: ^M is CR ('\r')
------------------------------------------------------------

The following bash script reproduces the bug:

------------------------------------------------------------
hg init
echo -e 'line0 \rtest\rtest' > a
echo line2 >> a
echo line3 >> a
hg add a
hg commit -m a -u a
hg annotate a | sed -n l
------------------------------------------------------------

The sed command is for looking at the CR in the output.  The output
is:

------------------------------------------------------------
0: line0 \r0: test\r0: test$
------------------------------------------------------------

The file a contains 3 lines, but the 'hg annotate a' outputs only the
first line.  The line2 and line3 are gone.  It seems that the annotate
command shows revision number 0 at every CR.

After the above command, the following command creates a next commit:

------------------------------------------------------------
echo -e 'line0 \rtest\rtest' > a
echo line1 >> a
echo line2 >> a
echo line3 >> a
hg commit -m b -u a
hg annotate a | sed -n l
------------------------------------------------------------

The command inserts the line1 between line0 and line2.  The output is:

------------------------------------------------------------
0: line0 \r1: test\r0: test$
0: line1$
------------------------------------------------------------

Interestingly, the 'hg annotate a' outputs revision 1 at the first CR,
and the new line1 as revision 0.  The line2 and line3 are still gone.

I guess that a revision number for each line is searched based on the
LF newline, but the annotate counts lines based on not only LF but CR
as a newline.  Both should use the same newline code to avoid such
broken output.  If both uses LF only, the expected output is:

------------------------------------------------------------
0: line0 \rtest\rtest$
1: line1$
0: line2$
0: line3$
------------------------------------------------------------

If both uses CR and LF for newline, the expected output is:

------------------------------------------------------------
0: line0 \r0: test\r0: test$
1: line1$
0: line2$
0: line3$
------------------------------------------------------------

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Mercurial-devel mailing list