def load(cls, repo): fp = repo.vfs(cls._filename) try: version = int(fp.readline().strip()) if version != cls._version: raise error.Abort( _('this version of shelve is incompatible ' 'with the version used in this repo')) name = fp.readline().strip() wctx = nodemod.bin(fp.readline().strip()) pendingctx = nodemod.bin(fp.readline().strip()) parents = [nodemod.bin(h) for h in fp.readline().split()] stripnodes = [nodemod.bin(h) for h in fp.readline().split()] branchtorestore = fp.readline().strip() except (ValueError, TypeError) as err: raise error.CorruptedState(str(err)) finally: fp.close() try: obj = cls() obj.name = name obj.wctx = repo[wctx] obj.pendingctx = repo[pendingctx] obj.parents = parents obj.stripnodes = stripnodes obj.branchtorestore = branchtorestore except error.RepoLookupError as err: raise error.CorruptedState(str(err)) return obj
def load(cls, repo): version = cls._getversion(repo) if version < cls._version: d = cls._readold(repo) elif version == cls._version: d = scmutil.simplekeyvaluefile(repo.vfs, cls._filename)\ .read(firstlinenonkeyval=True) else: raise error.Abort(_('this version of shelve is incompatible ' 'with the version used in this repo')) cls._verifyandtransform(d) try: obj = cls() obj.name = d['name'] obj.wctx = repo[d['originalwctx']] obj.pendingctx = repo[d['pendingctx']] obj.parents = d['parents'] obj.nodestoremove = d['nodestoremove'] obj.branchtorestore = d.get('branchtorestore', '') obj.keep = d.get('keep') == cls._keep obj.activebookmark = '' if d.get('activebook', '') != cls._noactivebook: obj.activebookmark = d.get('activebook', '') except (error.RepoLookupError, KeyError) as err: raise error.CorruptedState(pycompat.bytestr(err)) return obj
def _getversion(cls, repo): """Read version information from shelvestate file""" fp = repo.vfs(cls._filename) try: version = int(fp.readline().strip()) except ValueError as err: raise error.CorruptedState(pycompat.bytestr(err)) finally: fp.close() return version
def _verifyandtransform(cls, d): """Some basic shelvestate syntactic verification and transformation""" try: d['originalwctx'] = nodemod.bin(d['originalwctx']) d['pendingctx'] = nodemod.bin(d['pendingctx']) d['parents'] = [nodemod.bin(h) for h in d['parents'].split(' ')] d['nodestoremove'] = [nodemod.bin(h) for h in d['nodestoremove'].split(' ')] except (ValueError, TypeError, KeyError) as err: raise error.CorruptedState(pycompat.bytestr(err))