--- a/tests/simplestorerepo.py Sat Oct 05 10:29:34 2019 -0400
+++ b/tests/simplestorerepo.py Sun Oct 06 09:45:02 2019 -0400
@@ -21,9 +21,7 @@
nullid,
nullrev,
)
-from mercurial.thirdparty import (
- attr,
-)
+from mercurial.thirdparty import attr
from mercurial import (
ancestor,
bundlerepo,
@@ -44,9 +42,7 @@
cborutil,
storageutil,
)
-from mercurial.revlogutils import (
- flagutil,
-)
+from mercurial.revlogutils import flagutil
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
@@ -56,6 +52,7 @@
REQUIREMENT = 'testonly-simplestore'
+
def validatenode(node):
if isinstance(node, int):
raise ValueError('expected node; got int')
@@ -63,13 +60,16 @@
if len(node) != 20:
raise ValueError('expected 20 byte node')
+
def validaterev(rev):
if not isinstance(rev, int):
raise ValueError('expected int')
+
class simplestoreerror(error.StorageError):
pass
+
@interfaceutil.implementer(repository.irevisiondelta)
@attr.s(slots=True)
class simplestorerevisiondelta(object):
@@ -83,6 +83,7 @@
delta = attr.ib()
linknode = attr.ib(default=None)
+
@interfaceutil.implementer(repository.iverifyproblem)
@attr.s(frozen=True)
class simplefilestoreproblem(object):
@@ -90,6 +91,7 @@
error = attr.ib(default=None)
node = attr.ib(default=None)
+
@interfaceutil.implementer(repository.ifilestorage)
class filestorage(object):
"""Implements storage for a tracked path.
@@ -152,8 +154,9 @@
p1rev, p2rev = self.parentrevs(self.rev(entry[b'node']))
# start, length, rawsize, chainbase, linkrev, p1, p2, node
- self._index.append((0, 0, 0, -1, entry[b'linkrev'], p1rev, p2rev,
- entry[b'node']))
+ self._index.append(
+ (0, 0, 0, -1, entry[b'linkrev'], p1rev, p2rev, entry[b'node'])
+ )
self._index.append((0, 0, 0, -1, -1, -1, -1, nullid))
@@ -261,8 +264,9 @@
validaterev(baserev)
validaterev(rev)
- if ((self._flags(baserev) & revlog.REVIDX_RAWTEXT_CHANGING_FLAGS)
- or (self._flags(rev) & revlog.REVIDX_RAWTEXT_CHANGING_FLAGS)):
+ if (self._flags(baserev) & revlog.REVIDX_RAWTEXT_CHANGING_FLAGS) or (
+ self._flags(rev) & revlog.REVIDX_RAWTEXT_CHANGING_FLAGS
+ ):
return False
return True
@@ -271,8 +275,9 @@
if p1 is None and p2 is None:
p1, p2 = self.parents(node)
if node != storageutil.hashrevisionsha1(text, p1, p2):
- raise simplestoreerror(_("integrity check failed on %s") %
- self._path)
+ raise simplestoreerror(
+ _("integrity check failed on %s") % self._path
+ )
def revision(self, nodeorrev, raw=False):
if isinstance(nodeorrev, int):
@@ -313,7 +318,7 @@
return revision
start = revision.index(b'\1\n', 2)
- return revision[start + 2:]
+ return revision[start + 2 :]
def renamed(self, node):
validatenode(node)
@@ -405,9 +410,14 @@
return [b'/'.join((self._storepath, f)) for f in entries]
- def storageinfo(self, exclusivefiles=False, sharedfiles=False,
- revisionscount=False, trackedsize=False,
- storedsize=False):
+ def storageinfo(
+ self,
+ exclusivefiles=False,
+ sharedfiles=False,
+ revisionscount=False,
+ trackedsize=False,
+ storedsize=False,
+ ):
# TODO do a real implementation of this
return {
'exclusivefiles': [],
@@ -425,22 +435,31 @@
self.revision(node)
except Exception as e:
yield simplefilestoreproblem(
- error='unpacking %s: %s' % (node, e),
- node=node)
+ error='unpacking %s: %s' % (node, e), node=node
+ )
state['skipread'].add(node)
- def emitrevisions(self, nodes, nodesorder=None, revisiondata=False,
- assumehaveparentrevisions=False,
- deltamode=repository.CG_DELTAMODE_STD):
+ def emitrevisions(
+ self,
+ nodes,
+ nodesorder=None,
+ revisiondata=False,
+ assumehaveparentrevisions=False,
+ deltamode=repository.CG_DELTAMODE_STD,
+ ):
# TODO this will probably break on some ordering options.
nodes = [n for n in nodes if n != nullid]
if not nodes:
return
for delta in storageutil.emitrevisions(
- self, nodes, nodesorder, simplestorerevisiondelta,
- revisiondata=revisiondata,
- assumehaveparentrevisions=assumehaveparentrevisions,
- deltamode=deltamode):
+ self,
+ nodes,
+ nodesorder,
+ simplestorerevisiondelta,
+ revisiondata=revisiondata,
+ assumehaveparentrevisions=assumehaveparentrevisions,
+ deltamode=deltamode,
+ ):
yield delta
def add(self, text, meta, transaction, linkrev, p1, p2):
@@ -449,8 +468,17 @@
return self.addrevision(text, transaction, linkrev, p1, p2)
- def addrevision(self, text, transaction, linkrev, p1, p2, node=None,
- flags=revlog.REVIDX_DEFAULT_FLAGS, cachedelta=None):
+ def addrevision(
+ self,
+ text,
+ transaction,
+ linkrev,
+ p1,
+ p2,
+ node=None,
+ flags=revlog.REVIDX_DEFAULT_FLAGS,
+ cachedelta=None,
+ ):
validatenode(p1)
validatenode(p2)
@@ -467,8 +495,9 @@
if validatehash:
self.checkhash(rawtext, node, p1=p1, p2=p2)
- return self._addrawrevision(node, rawtext, transaction, linkrev, p1, p2,
- flags)
+ return self._addrawrevision(
+ node, rawtext, transaction, linkrev, p1, p2, flags
+ )
def _addrawrevision(self, node, rawtext, transaction, link, p1, p2, flags):
transaction.addbackup(self._indexpath)
@@ -477,13 +506,15 @@
self._svfs.write(path, rawtext)
- self._indexdata.append({
- b'node': node,
- b'p1': p1,
- b'p2': p2,
- b'linkrev': link,
- b'flags': flags,
- })
+ self._indexdata.append(
+ {
+ b'node': node,
+ b'p1': p1,
+ b'p2': p2,
+ b'linkrev': link,
+ b'flags': flags,
+ }
+ )
self._reflectindexupdate()
@@ -491,14 +522,22 @@
def _reflectindexupdate(self):
self._refreshindex()
- self._svfs.write(self._indexpath,
- ''.join(cborutil.streamencode(self._indexdata)))
+ self._svfs.write(
+ self._indexpath, ''.join(cborutil.streamencode(self._indexdata))
+ )
- def addgroup(self, deltas, linkmapper, transaction, addrevisioncb=None,
- maybemissingparents=False):
+ def addgroup(
+ self,
+ deltas,
+ linkmapper,
+ transaction,
+ addrevisioncb=None,
+ maybemissingparents=False,
+ ):
if maybemissingparents:
- raise error.Abort(_('simple store does not support missing parents '
- 'write mode'))
+ raise error.Abort(
+ _('simple store does not support missing parents ' 'write mode')
+ )
nodes = []
@@ -519,8 +558,9 @@
else:
text = mdiff.patch(self.revision(deltabase), delta)
- self._addrawrevision(node, text, transaction, linkrev, p1, p2,
- flags)
+ self._addrawrevision(
+ node, text, transaction, linkrev, p1, p2, flags
+ )
if addrevisioncb:
addrevisioncb(self, node)
@@ -535,8 +575,7 @@
revishead[self.rev(entry[b'p1'])] = False
revishead[self.rev(entry[b'p2'])] = False
- return [rev for rev, ishead in sorted(revishead.items())
- if ishead]
+ return [rev for rev, ishead in sorted(revishead.items()) if ishead]
def heads(self, start=None, stop=None):
# This is copied from revlog.py.
@@ -584,8 +623,12 @@
def getstrippoint(self, minlink):
return storageutil.resolvestripinfo(
- minlink, len(self) - 1, self._headrevs(), self.linkrev,
- self.parentrevs)
+ minlink,
+ len(self) - 1,
+ self._headrevs(),
+ self.linkrev,
+ self.parentrevs,
+ )
def strip(self, minlink, transaction):
if not len(self):
@@ -599,6 +642,7 @@
self._indexdata[rev:] = []
self._reflectindexupdate()
+
def issimplestorefile(f, kind, st):
if kind != stat.S_IFREG:
return False
@@ -613,6 +657,7 @@
# Otherwise assume it belongs to the simple store.
return True
+
class simplestore(store.encodedstore):
def datafiles(self):
for x in super(simplestore, self).datafiles():
@@ -629,6 +674,7 @@
yield unencoded, encoded, size
+
def reposetup(ui, repo):
if not repo.local():
return
@@ -642,9 +688,11 @@
repo.__class__ = simplestorerepo
+
def featuresetup(ui, supported):
supported.add(REQUIREMENT)
+
def newreporequirements(orig, ui, createopts):
"""Modifies default requirements for new repos to use the simple store."""
requirements = orig(ui, createopts)
@@ -652,21 +700,23 @@
# These requirements are only used to affect creation of the store
# object. We have our own store. So we can remove them.
# TODO do this once we feel like taking the test hit.
- #if 'fncache' in requirements:
+ # if 'fncache' in requirements:
# requirements.remove('fncache')
- #if 'dotencode' in requirements:
+ # if 'dotencode' in requirements:
# requirements.remove('dotencode')
requirements.add(REQUIREMENT)
return requirements
+
def makestore(orig, requirements, path, vfstype):
if REQUIREMENT not in requirements:
return orig(requirements, path, vfstype)
return simplestore(path, vfstype)
+
def verifierinit(orig, self, *args, **kwargs):
orig(self, *args, **kwargs)
@@ -674,10 +724,12 @@
# advertised. So suppress these warnings.
self.warnorphanstorefiles = False
+
def extsetup(ui):
localrepo.featuresetupfuncs.add(featuresetup)
- extensions.wrapfunction(localrepo, 'newreporequirements',
- newreporequirements)
+ extensions.wrapfunction(
+ localrepo, 'newreporequirements', newreporequirements
+ )
extensions.wrapfunction(localrepo, 'makestore', makestore)
extensions.wrapfunction(verify.verifier, '__init__', verifierinit)