[PATCH 2 of 3] revset: transcode revsets to UTF-8

Dan Villiom Podlaski Christiansen danchr at gmail.com
Fri Nov 12 10:40:19 CST 2010


# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
# Date 1289579971 -3600
# Node ID 0fa148bcfe7f0755236e4b9d0034c5cc7ac4771d
# Parent  bdf95be4ea789a13d088f0955ffcd072590a1eb6
revset: transcode revsets to UTF-8.

This allows updating to a branch with non-ASCII names in non-UTF-8
locales.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -152,6 +152,8 @@ def revrange(repo, revs):
                 l.append(spec)
                 continue
 
+            spec = encoding.fromlocal(spec)
+
             if revrangesep in spec:
                 start, end = spec.split(revrangesep, 1)
                 start = revfix(repo, start, 0)
diff --git a/tests/test-newbranch.t b/tests/test-newbranch.t
--- a/tests/test-newbranch.t
+++ b/tests/test-newbranch.t
@@ -335,3 +335,25 @@ 2 branch heads, implicit merge works:
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
 
+Create a branch with a UTF-8 name:
+
+  $ branchname () {
+  > python -c 'print "b\xf8b"'
+  > }
+  $ HGENCODING=iso-8859-1 hg branch `branchname`
+  marked working directory as branch b\xf8b (esc)
+  $ HGENCODING=utf-8 hg branch
+  b\xc3\xb8b (esc)
+  $ hg ci -m 'Create ugly-named branch.'
+
+Test updating to it with various locales:
+
+  $ HGENCODING=ascii hg up `branchname`
+  abort: decoding near 'b\xf8b': 'ascii' codec can't decode byte 0xf8 in position 1: ordinal not in range(128)! (esc)
+  [255]
+  $ HGENCODING=utf-8 hg up `branchname`
+  abort: decoding near 'b\xf8b': 'utf8' codec can't decode byte 0xf8 in position 1: invalid start byte! (esc)
+  [255]
+  $ HGENCODING=iso-8859-1 hg up `branchname`
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+


More information about the Mercurial-devel mailing list