[PATCH 09 of 13] Py3k localrepo fixes; WIP
Martin Geisler
mg at lazybytes.net
Wed Aug 5 17:50:43 CDT 2009
Alejandro Santos <alejolp at alejolp.com> writes:
> # HG changeset patch
> # User Alejandro Santos <alejolp at alejolp.com>
> # Date 1249505636 10800
> # Node ID 7e7aba33a25ebfe2afd1c15ec866c97d2ed511bb
> # Parent 33bef15b45baf422fb233d40b723905e7f810e18
> Py3k localrepo fixes; WIP
>
> diff -r 33bef15b45ba -r 7e7aba33a25e mercurial/context.py
> --- a/mercurial/context.py Wed Aug 05 17:53:56 2009 -0300
> +++ b/mercurial/context.py Wed Aug 05 17:53:56 2009 -0300
> @@ -8,7 +8,7 @@
> from node import nullid, nullrev, short, hex
> from i18n import _
> import ancestor, bdiff, error, util, subrepo
> -import os, errno
> +import os, sys, errno
>
> propertycache = util.propertycache
>
> @@ -512,7 +512,8 @@
> if 'branch' not in self._extra:
> branch = self._repo.dirstate.branch()
> try:
> - branch = branch.decode('UTF-8').encode('UTF-8')
> + if sys.version_info[0] == 2:
> + branch = branch.decode('UTF-8').encode('UTF-8')
> except UnicodeDecodeError:
> raise util.Abort(_('branch name not in UTF-8!'))
> self._extra['branch'] = branch
I don't see why this check should not be done for Python 3. It looks
strange, but it verifies that the bytestring is proper UTF-8. However,
for that I would just do
branch.decode('UTF-8')
and throw away the result -- if this succeeds, then the bytestring was
indeed UTF-8. Encoding the decoded bytestring (the Unicode string) is
not necessary, it will just give a new string equal to branch.
As far as I can see, the above should also hold if bytestring == bytes
and Unicode string = str.
--
Martin Geisler
VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://selenic.com/pipermail/mercurial-devel/attachments/20090806/d10c21ae/attachment.pgp
More information about the Mercurial-devel
mailing list