[PATCH stable] rollback: read dirstate branch with correct encoding

Matt Mackall mpm at selenic.com
Fri Aug 17 23:30:11 CDT 2012


On Tue, 2012-08-14 at 15:41 +0200, Sune Foldager wrote:
> # HG changeset patch
> # User Sune Foldager <cryo at cyanite.org>
> # Date 1344951206 -7200
> # Branch stable
> # Node ID 5e3d883950b7de8bbf6826d3f6bd9cf022838417
> # Parent  bde1185f406cd2367e3973d827a6d613fd68ec60
> rollback: read dirstate branch with correct encoding
> 
> diff -r bde1185f406c -r 5e3d883950b7 mercurial/localrepo.py
> --- a/mercurial/localrepo.py	Thu Aug 02 19:10:45 2012 +0400
> +++ b/mercurial/localrepo.py	Tue Aug 14 15:33:26 2012 +0200
> @@ -1009,7 +1009,7 @@
>              util.rename(self.join('undo.dirstate'), self.join('dirstate'))
>              try:
>                  branch = self.opener.read('undo.branch')
> -                self.dirstate.setbranch(branch)
> +                self.dirstate.setbranch(encoding.tolocal(branch))

I found this fix quite confusing, because the rule is there should never
be any non-local strings "in the wild"... so why were we calling tolocal
on branch, which is already in local encoding? Oh, because we read
branch a line earlier without properly decoding it. A better fix would
be to run tolocal a line earlier before assigning to branch.

But an even better fix is instead of hand-rolling a dirstate.branch(),
to simply copy the logic we use to rollback the other metadata
(dirstate, bookmarks, phaseroots) that does so with no internal
knowledge of their structures/encoding/methods and thus is immune to
this sort of confusion.

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list