# HG changeset patch # User Luke Opperman # Date 1239129005 18000 # Node ID 330f0b15d4173450465408d5ba0a8fdc8867cd9e # Parent f2c65dd3d5c055f02d823976eaee1475793df5f7 issue67: mercurial 1.3 util incompatibility with encoding swap diff --git a/fetch_command.py b/fetch_command.py --- a/fetch_command.py +++ b/fetch_command.py @@ -29,8 +29,7 @@ def fetch_revisions(ui, svn_url, hg_repo """pull new revisions from Subversion """ svn_url = util.normalize_url(svn_url) - old_encoding = merc_util._encoding - merc_util._encoding = 'UTF-8' + old_encoding = util.swap_out_encoding() skipto_rev=int(skipto_rev) have_replay = not stupid if have_replay and not callable( @@ -107,7 +106,8 @@ def fetch_revisions(ui, svn_url, hg_repo ui.status('Got a 502, retrying (%s)\n' % tries) else: raise - merc_util._encoding = old_encoding + util.swap_out_encoding(old_encoding) + fetch_revisions = util.register_subcommand('pull')(fetch_revisions) diff --git a/push_cmd.py b/push_cmd.py --- a/push_cmd.py +++ b/push_cmd.py @@ -24,8 +24,7 @@ def push_revisions_to_subversion(ui, rep stupid=False, **opts): """push revisions starting at a specified head back to Subversion. """ - oldencoding = merc_util._encoding - merc_util._encoding = 'UTF-8' + old_encoding = util.swap_out_encoding() hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, ui_=ui) svn_commit_hashes = dict(zip(hge.revmap.itervalues(), @@ -101,7 +100,7 @@ def push_revisions_to_subversion(ui, rep rebasesrc = node.bin(child.extra().get('rebase_source', node.hex(node.nullid))) hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, ui_=ui) svn_commit_hashes = dict(zip(hge.revmap.itervalues(), hge.revmap.iterkeys())) - merc_util._encoding = oldencoding + util.swap_out_encoding(old_encoding) return 0 push_revisions_to_subversion = util.register_subcommand('push')(push_revisions_to_subversion) # for git expats diff --git a/util.py b/util.py --- a/util.py +++ b/util.py @@ -4,6 +4,10 @@ import shutil from mercurial import hg from mercurial import node from mercurial import util +try: + from mercurial import encoding +except ImportError: + encoding = None svn_subcommands = { } def register_subcommand(name): @@ -135,3 +139,14 @@ def describe_revision(ui, r): def describe_commit(ui, h, b): ui.note(' committed to "%s" as %s\n' % ((b or 'default'), node.short(h))) + + +def swap_out_encoding(new_encoding="UTF-8"): + """ Utility for mercurial incompatibility changes, can be removed after 1.3""" + if encoding is None: + old = util._encoding + util._encoding = new_encoding + else: + old = encoding.encoding + encoding.encoding = new_encoding + return old