[PATCH 1 of 2 STABLE V2] convert: move recode() from convcmd to common

Matt Harbison mharbison72 at gmail.com
Sun Nov 26 20:38:55 EST 2017


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1511745478 18000
#      Sun Nov 26 20:17:58 2017 -0500
# Branch stable
# Node ID 7208fc36b7765c36d31d0ccddb7087081617208c
# Parent  02845f7441aff30bc01975a5881cabfa922c12d4
convert: move recode() from convcmd to common

The next patch will need 'orig_encoding' in the p4 module, but importing convcmd
there creates an import cycle.

diff --git a/hgext/convert/common.py b/hgext/convert/common.py
--- a/hgext/convert/common.py
+++ b/hgext/convert/common.py
@@ -37,6 +37,14 @@
     s = base64.decodestring(s)
     return pickle.loads(s)
 
+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')
+
 class MissingTool(Exception):
     pass
 
diff --git a/hgext/convert/convcmd.py b/hgext/convert/convcmd.py
--- a/hgext/convert/convcmd.py
+++ b/hgext/convert/convcmd.py
@@ -49,13 +49,7 @@
 svn_sink = subversion.svn_sink
 svn_source = subversion.svn_source
 
-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')
+recode = common.recode
 
 def mapbranch(branch, branchmap):
     '''


More information about the Mercurial-devel mailing list