# HG changeset patch # User Brodie Rao # Date 1266185332 18000 # Node ID 2253715fde970449d762b5a2cb22352e59df6d7d # Parent 14184a2ac46ad546ad11acbe0ac45b9f4dd91e0b color: don't crash on invalid status codes (issue2036) If an unknown file with a newline appears in the status output, color shouldn't raise a KeyError trying to parse second line in the filename. diff -r 14184a2ac46a -r 2253715fde97 hgext/color.py --- a/hgext/color.py Sun Feb 14 13:28:34 2010 +0100 +++ b/hgext/color.py Sun Feb 14 17:08:52 2010 -0500 @@ -117,10 +117,16 @@ # apply color to output and display it for i in xrange(len(lines)): - status = abbreviations[lines_with_status[i][0]] - effects = effectdefs[status] - if effects: - lines[i] = render_effects(lines[i], effects) + try: + status = abbreviations[lines_with_status[i][0]] + except KeyError: + # Ignore lines with invalid codes, especially in the case of + # of unknown filenames containing newlines (issue2036). + pass + else: + effects = effectdefs[status] + if effects: + lines[i] = render_effects(lines[i], effects) ui.write(lines[i] + delimiter) return retval diff -r 14184a2ac46a -r 2253715fde97 tests/test-eolfilename --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-eolfilename Sun Feb 14 17:08:52 2010 -0500 @@ -0,0 +1,43 @@ +#!/bin/sh +# http://mercurial.selenic.com/bts/issue352 + +"$TESTDIR/hghave" eol-in-paths || exit 80 + +echo % test issue352 +hg init foo +cd foo + +A=`printf 'he\rllo'` + +echo foo > "$A" +hg add +hg ci -A -m m +rm "$A" + +echo foo > "hell +o" +hg add +hg ci -A -m m + +echo foo > "$A" +hg debugwalk + +# http://mercurial.selenic.com/bts/issue2036 +cd .. +echo % test issue2039 + +hg init bar +cd bar + +echo "[extensions]" >> $HGRCPATH +echo "color=" >> $HGRCPATH + +A=`printf 'foo\nbar'` +B=`printf 'foo\nbar.baz'` + +touch "$A" +touch "$B" + +hg status --color=always + +exit 0 diff -r 14184a2ac46a -r 2253715fde97 tests/test-eolfilename.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-eolfilename.out Sun Feb 14 17:08:52 2010 -0500 @@ -0,0 +1,20 @@ +% test issue352 +adding he llo +abort: '\n' and '\r' disallowed in filenames: 'he\rllo' +adding he llo +abort: '\n' and '\r' disallowed in filenames: 'he\rllo' +adding hell +o +abort: '\n' and '\r' disallowed in filenames: 'hell\no' +adding hell +o +abort: '\n' and '\r' disallowed in filenames: 'hell\no' +f he llo he llo +f hell +o hell +o +% test issue2039 +? foo +bar +? foo +bar.baz diff -r 14184a2ac46a -r 2253715fde97 tests/test-issue352 --- a/tests/test-issue352 Sun Feb 14 13:28:34 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -#!/bin/sh -# http://mercurial.selenic.com/bts/issue352 - -"$TESTDIR/hghave" eol-in-paths || exit 80 - -hg init foo -cd foo - -A=`printf 'he\rllo'` - -echo foo > "$A" -hg add -hg ci -A -m m -rm "$A" - -echo foo > "hell -o" -hg add -hg ci -A -m m - -echo foo > "$A" -hg debugwalk - -exit 0 diff -r 14184a2ac46a -r 2253715fde97 tests/test-issue352.out --- a/tests/test-issue352.out Sun Feb 14 13:28:34 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -adding he llo -abort: '\n' and '\r' disallowed in filenames: 'he\rllo' -adding he llo -abort: '\n' and '\r' disallowed in filenames: 'he\rllo' -adding hell -o -abort: '\n' and '\r' disallowed in filenames: 'hell\no' -adding hell -o -abort: '\n' and '\r' disallowed in filenames: 'hell\no' -f he llo he llo -f hell -o hell -o