# HG changeset patch # User Augie Fackler # Date 1504154727 14400 # Node ID 5adfb81c46806e811a9552f7929d5c81938879ea # Parent 3476b7a945fbc9603bb3de16316cf063b33c6ae5 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. diff --git a/hgsubversion/replay.py b/hgsubversion/replay.py --- 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, diff --git a/hgsubversion/stupid.py b/hgsubversion/stupid.py --- 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: diff --git a/hgsubversion/util.py b/hgsubversion/util.py --- 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