changeset 1526:5adfb81c4680

util: add method for forcing unicode objects back to utf8 bytes Use this to force all filenames to be bytes, even when underlying svn bindings really want to give us unicodes instead.
author Augie Fackler <raf@durin42.com>
date Thu, 31 Aug 2017 00:45:27 -0400
parents 3476b7a945fb
children d03995e69785
files hgsubversion/replay.py hgsubversion/stupid.py hgsubversion/util.py
diffstat 3 files changed, 17 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/replay.py
+++ b/hgsubversion/replay.py
@@ -186,7 +186,7 @@ def _convert_rev(ui, meta, svn, r, tbdel
         current_ctx = context.memctx(meta.repo,
                                      parents,
                                      meta.getmessage(rev),
-                                     files.keys(),
+                                     [util.forceutf8(f) for f in files.keys()],
                                      filectxfn,
                                      meta.authors[rev.author],
                                      date,
@@ -226,7 +226,7 @@ def _convert_rev(ui, meta, svn, r, tbdel
         current_ctx = context.memctx(meta.repo,
                                      (ha, node.nullid),
                                      meta.getmessage(rev),
-                                     files,
+                                     [util.forceutf8(f) for f in files],
                                      del_all_files,
                                      meta.authors[rev.author],
                                      date,
--- a/hgsubversion/stupid.py
+++ b/hgsubversion/stupid.py
@@ -780,14 +780,15 @@ def convert_rev(ui, meta, svn, r, tbdelt
 
         origbranch = extra.get('branch', None)
         meta.mapbranch(extra)
-        current_ctx = context.memctx(meta.repo,
-                                     [parentctx.node(), revlog.nullid],
-                                     meta.getmessage(r),
-                                     files_touched,
-                                     filectxfn,
-                                     meta.authors[r.author],
-                                     date,
-                                     extra)
+        current_ctx = context.memctx(
+            meta.repo,
+            [parentctx.node(), revlog.nullid],
+            meta.getmessage(r),
+            [util.forceutf8(f) for f in files_touched],
+            filectxfn,
+            meta.authors[r.author],
+            date,
+            extra)
         ha = meta.repo.svn_commitctx(current_ctx)
 
         if not tag:
--- a/hgsubversion/util.py
+++ b/hgsubversion/util.py
@@ -422,3 +422,9 @@ def get_contexts(repo, fromrev=0):
             yield repo[rev]
         except error.RepoLookupError:
             pass
+
+_unitype = type(u'')
+def forceutf8(s):
+    if isinstance(s, _unitype):
+        return s.encode('utf-8')
+    return s