Mercurial > hg
changeset 19904:5b327880a660
shelve: drop pickle usage
Pickle was used to the `shelvedstate` file. However the content of the file is
very simple and we can handle serialisation ourself. Not using pickle is a net
win.
Note incrementing the format version as no releases have been done so far.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Mon, 14 Oct 2013 18:59:12 +0200 |
parents | ca875b271ac3 |
children | 078ccd780b71 |
files | hgext/shelve.py |
diffstat | 1 files changed, 15 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/shelve.py Tue Oct 15 00:51:05 2013 +0900 +++ b/hgext/shelve.py Mon Oct 14 18:59:12 2013 +0200 @@ -21,13 +21,8 @@ shelve". """ -try: - import cPickle as pickle - pickle.dump # import now -except ImportError: - import pickle from mercurial.i18n import _ -from mercurial.node import nullid +from mercurial.node import nullid, bin, hex from mercurial import changegroup, cmdutil, scmutil, phases from mercurial import error, hg, mdiff, merge, patch, repair, util from mercurial import templatefilters @@ -88,11 +83,17 @@ @classmethod def load(cls, repo): fp = repo.opener(cls._filename) - (version, name, parents, stripnodes) = pickle.load(fp) + try: + version = int(fp.readline().strip()) - if version != cls._version: - raise util.Abort(_('this version of shelve is incompatible ' - 'with the version used in this repo')) + if version != cls._version: + raise util.Abort(_('this version of shelve is incompatible ' + 'with the version used in this repo')) + name = fp.readline().strip() + parents = [bin(h) for h in fp.readline().split()] + stripnodes = [bin(h) for h in fp.readline().split()] + finally: + fp.close() obj = cls() obj.name = name @@ -104,9 +105,10 @@ @classmethod def save(cls, repo, name, stripnodes): fp = repo.opener(cls._filename, 'wb') - pickle.dump((cls._version, name, - repo.dirstate.parents(), - stripnodes), fp) + fp.write('%i\n' % cls._version) + fp.write('%s\n' % name) + fp.write('%s\n' % ' '.join([hex(p) for p in repo.dirstate.parents()])) + fp.write('%s\n' % ' '.join([hex(n) for n in stripnodes])) fp.close() @staticmethod