[PATCH evolve-ext-V5] evolve: add new methods _evolvestatewrite, _evolvestateread, _evolvestatedelete
Shusen Liu
liushusen at fb.com
Fri Jan 29 07:09:50 CST 2016
What would be the suggested format for storing `evolvestate`?
On 1/27/16, 21:56, "Matt Mackall" <mpm at selenic.com> wrote:
>On Thu, 2016-01-28 at 00:07 +0900, Yuya Nishihara wrote:
>> On Tue, 26 Jan 2016 15:43:07 -0800, Shusen LIU wrote:
>> > # HG changeset patch
>> > # User Shusen LIU <liushusen at fb.com>
>> > # Date 1453329104 28800
>> > # Wed Jan 20 14:31:44 2016 -0800
>> > # Node ID c82a0edf16d90727e307e2c4b17bd1202e414fb7
>> > # Parent ea7523380efa894213582ca1600dc472baa7b25e
>> > evolve: add new methods _evolvestatewrite, _evolvestateread,
>> > _evolvestatedelete
>>
>> > +def _fm0evolvestateread(repo):
>> > + serialized_data = repo.vfs.read('evolvestate').split('\n')[1]
>> > + data = dict([(str(k), str(v))
>> > + for k,v in json.loads(serialized_data).iteritems()])
>> > + return data
>> > +
>> > +def _fm0evolvestatewrite(repo, data):
>> > + serialized_data = json.dumps(data)
>> > + repo.vfs.write('evolvestate',
>> > + '\n'.join([str(_fm0evolvestateversion),
>> > serialized_data]))
>>
>> I'm not sure this is the case, but JSON is really bad at handling non-UTF-8
>> string such as a file name. If 'evolvestate' is not intended to be read by
>> other tools, JSON won't be a good choice.
>
>Indeed. Also problematic:
>
>- XML (also can't handle non-Unicode data)[1]
>- pickle (executes arbitrary code on read)
>- marshal (executes arbitrary code on read)
>
>[1] and frequently executes arbitrary code on read, but not by design
>--
>Mathematics is the supreme nostalgia of our time.
>
More information about the Mercurial-devel
mailing list