bookmarks: use UTF-8 storage
authorMatt Mackall <mpm@selenic.com>
Wed, 24 Nov 2010 16:04:33 -0600
changeset 13048 e298cca2d53a
parent 13047 6c375e07d673
child 13049 d588326f6321
bookmarks: use UTF-8 storage This uses tolocal/fromlocal to translate bookmark metadata to UTF-8 for storage. Existing bookmarks in ASCII, UTF-8 or Latin1 will continue to work, others may need to set HGENCODINGFALLBACK to transition.
hgext/bookmarks.py
--- a/hgext/bookmarks.py	Wed Nov 24 15:56:32 2010 -0600
+++ b/hgext/bookmarks.py	Wed Nov 24 16:04:33 2010 -0600
@@ -31,7 +31,7 @@
 from mercurial.i18n import _
 from mercurial.node import nullid, nullrev, bin, hex, short
 from mercurial import util, commands, repair, extensions, pushkey, hg, url
-from mercurial import revset
+from mercurial import revset, encoding
 import os
 
 def write(repo):
@@ -52,7 +52,7 @@
     try:
         file = repo.opener('bookmarks', 'w', atomictemp=True)
         for refspec, node in refs.iteritems():
-            file.write("%s %s\n" % (hex(node), refspec))
+            file.write("%s %s\n" % (hex(node), encoding.fromlocal(refspec)))
         file.rename()
 
         # touch 00changelog.i so hgweb reloads bookmarks (no lock needed)
@@ -233,6 +233,7 @@
                 bookmarks = {}
                 for line in self.opener('bookmarks'):
                     sha, refspec = line.strip().split(' ', 1)
+                    refspec = encoding.tolocal(refspec)
                     bookmarks[refspec] = self.changelog.lookup(sha)
             except:
                 pass