[PATCH 1 of 2] histedit: replace pickle with custom serialization

Pierre-Yves David pierre-yves.david at ens-lyon.org
Tue Apr 14 13:14:46 CDT 2015



On 04/14/2015 01:50 PM, Ryan McElroy wrote:
> On 4/14/2015 10:06 AM, Durham Goode wrote:
>> # HG changeset patch
>> # User Durham Goode <durham at fb.com>
>> # Date 1428938637 25200
>> #      Mon Apr 13 08:23:57 2015 -0700
>> # Node ID 6289acbbd36ec81eab91ed3b8e32b3354bf8cf84
>> # Parent  b2fb1403994e033584aed8a487ab162a9d75fa80
>> histedit: replace pickle with custom serialization
>>
>> Pickle is undesirable, so let's serialize it ourselves. We keep the
>> ability to
>> parse existing pickle blobs for now.
>>
>> diff --git a/hgext/histedit.py b/hgext/histedit.py
>> --- a/hgext/histedit.py
>> +++ b/hgext/histedit.py
>> @@ -220,7 +220,12 @@ class histeditstate(object):
>>                   raise
>>               raise util.Abort(_('no histedit in progress'))
>> -        parentctxnode, rules, keep, topmost, replacements =
>> pickle.load(fp)
>> +        try:
>> +            data = pickle.load(fp)
>> +            parentctxnode, rules, keep, topmost, replacements = data
>> +        except pickle.UnpicklingError:
>> +            data = self._load()
>> +            parentctxnode, rules, keep, topmost, replacements = data
>>           self.parentctxnode = parentctxnode
>>           self.rules = rules
>> @@ -230,10 +235,63 @@ class histeditstate(object):
>>       def write(self):
>>           fp = self.repo.vfs('histedit-state', 'w')
>> -        pickle.dump((self.parentctxnode, self.rules, self.keep,
>> -                     self.topmost, self.replacements), fp)
>> +        fp.write('v1\n')
>> +        fp.write('%s\n' % node.hex(self.parentctxnode))
>> +        fp.write('%s\n' % node.hex(self.topmost))
>> +        fp.write('%s\n' % self.keep)
>> +        fp.write('%d\n' % len(self.rules))
>> +        for rule in self.rules:
>> +            fp.write('%s%s\n' % (rule[1], rule[0]))
> I'd prefer rules to be in their own file, so it's easy to edit even
> without --edit-todo.
>
> I'm fine having that in a later change though.
>
> That would also eliminate the need for printing the number of lines into
> the file.

This looks like a smart proposal, so we should probably not do it. This 
kind of open the way to all kind of out of control black magic 
witchcraft from user that will hinter our ability to make things better 
in the future.


-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list