diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -3622,8 +3622,9 @@ def import_(ui, repo, patch1=None, *patc try: try: wlock = repo.wlock() - lock = repo.lock() - tr = repo.transaction('import') + if not opts.get('no_commit'): + lock = repo.lock() + tr = repo.transaction('import') parents = repo.parents() for patchurl in patches: if patchurl == '-': @@ -3649,7 +3650,8 @@ def import_(ui, repo, patch1=None, *patc if not haspatch: raise util.Abort(_('%s: no diffs found') % patchurl) - tr.close() + if tr: + tr.close() if msgs: repo.savecommitmessage('\n* * *\n'.join(msgs)) except: diff --git a/mercurial/encoding.py b/mercurial/encoding.py --- a/mercurial/encoding.py +++ b/mercurial/encoding.py @@ -92,24 +92,32 @@ def tolocal(s): 'foo: \\xc3\\xa4' """ - for e in ('UTF-8', fallbackencoding): + try: try: - u = s.decode(e) # attempt strict decoding + # make sure string is actually stored in UTF-8 + u = s.decode('UTF-8') + if encoding == 'UTF-8': + # fast path + return s r = u.encode(encoding, "replace") if u == r.decode(encoding): # r is a safe, non-lossy encoding of s return r - elif e == 'UTF-8': - return localstr(s, r) - else: + return localstr(s, r) + except UnicodeDecodeError: + # we should only get here if we're looking at an ancient changeset + try: + u = s.decode(fallbackencoding) + r = u.encode(encoding, "replace") + if u == r.decode(encoding): + # r is a safe, non-lossy encoding of s + return r return localstr(u.encode('UTF-8'), r) - - except LookupError, k: - raise error.Abort(k, hint="please check your locale settings") - except UnicodeDecodeError: - pass - u = s.decode("utf-8", "replace") # last ditch - return u.encode(encoding, "replace") # can't round-trip + except UnicodeDecodeError: + u = s.decode("utf-8", "replace") # last ditch + return u.encode(encoding, "replace") # can't round-trip + except LookupError, k: + raise error.Abort(k, hint="please check your locale settings") def fromlocal(s): """