[PATCH] convert: don't hide leaking unicode objects

Mads Kiilerich mads at kiilerich.com
Tue Aug 31 15:17:19 CDT 2010


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1283285781 -7200
# Node ID 3633b561fcca8212737a86dec05042da17bc2f57
# Parent  36a65283c3afd6f957da54817b3b8c577aa78ec4
convert: don't hide leaking unicode objects

No converter source should ever yield unicode strings, and if it happens anyway
then we would rather crash than hide the problem. Right???

This would have helped debugging issue2354.

diff --git a/hgext/convert/convcmd.py b/hgext/convert/convcmd.py
--- a/hgext/convert/convcmd.py
+++ b/hgext/convert/convcmd.py
@@ -23,12 +23,6 @@
 
 orig_encoding = 'ascii'
 
-def recode(s):
-    if isinstance(s, unicode):
-        return s.encode(orig_encoding, 'replace')
-    else:
-        return s.decode('utf-8').encode(orig_encoding, 'replace')
-
 source_converters = [
     ('cvs', convert_cvs, 'branchsort'),
     ('git', convert_git, 'branchsort'),
@@ -241,7 +235,7 @@
                     pendings[c].remove(n)
                 except ValueError:
                     raise util.Abort(_('cycle detected between %s and %s')
-                                       % (recode(c), recode(n)))
+                                       % (c, n))
                 if not pendings[c]:
                     # Parents are converted, node is eligible
                     actives.insert(0, c)
@@ -352,8 +346,8 @@
                 # convert log message to local encoding without using
                 # tolocal() because encoding.encoding conver() use it as
                 # 'utf-8'
-                self.ui.status("%d %s\n" % (num, recode(desc)))
-                self.ui.note(_("source: %s\n") % recode(c))
+                self.ui.status("%d %s\n" % (num, desc))
+                self.ui.note(_("source: %s\n") % c)
                 self.ui.progress(_('converting'), i, unit=_('revisions'),
                                  total=len(t))
                 self.copy(c)


More information about the Mercurial-devel mailing list