[PATCH STABLE] color: don't crash on invalid status codes (issue2036)

Brodie Rao dackze at gmail.com
Sun Feb 14 15:15:27 CST 2010


# HG changeset patch
# User Brodie Rao <me+hg at dackz.net>
# Date 1266182042 18000
# Branch stable
# Node ID 1bfe425ee57ac88f53a66f0df560b3f308ccdf0c
# Parent  634b0e7561eca044e37ac9643578f1c044eec64d
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 --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -117,10 +117,14 @@ def _colorstatuslike(abbreviations, effe
 
     # 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:
+            pass
+        else:
+            effects = effectdefs[status]
+            if effects:
+                lines[i] = render_effects(lines[i], effects)
         ui.write(lines[i] + delimiter)
     return retval
 
diff --git a/tests/test-issue2036 b/tests/test-issue2036
new file mode 100755
--- /dev/null
+++ b/tests/test-issue2036
@@ -0,0 +1,17 @@
+#!/bin/sh
+# http://mercurial.selenic.com/bts/issue2036
+
+"$TESTDIR/hghave" eol-in-paths || exit 80
+
+echo "[extensions]" >> $HGRCPATH
+echo "color=" >> $HGRCPATH
+
+hg init foo
+cd foo
+
+touch "foo
+bar"
+touch "foo
+bar.baz"
+
+hg status --color=always
diff --git a/tests/test-issue2036.out b/tests/test-issue2036.out
new file mode 100644
--- /dev/null
+++ b/tests/test-issue2036.out
@@ -0,0 +1,4 @@
+? foo
+bar
+? foo
+bar.baz


More information about the Mercurial-devel mailing list