Storage may not be backed by revlogs. So it is wrong to refer
to storage as "revlog" or use abbreviations like "rl."
This commit replaces revlog terminology in manifest context classes
and starts referring to things as "store" or "storage."
hg-reviewers |
Storage may not be backed by revlogs. So it is wrong to refer
to storage as "revlog" or use abbreviations like "rl."
This commit replaces revlog terminology in manifest context classes
and starts referring to things as "store" or "storage."
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
return self._revlog.rev(node) | return self._revlog.rev(node) | ||||
@interfaceutil.implementer(repository.imanifestrevisionwritable) | @interfaceutil.implementer(repository.imanifestrevisionwritable) | ||||
class memmanifestctx(object): | class memmanifestctx(object): | ||||
def __init__(self, manifestlog): | def __init__(self, manifestlog): | ||||
self._manifestlog = manifestlog | self._manifestlog = manifestlog | ||||
self._manifestdict = manifestdict() | self._manifestdict = manifestdict() | ||||
def _revlog(self): | def _storage(self): | ||||
return self._manifestlog._revlog | return self._manifestlog._revlog | ||||
def new(self): | def new(self): | ||||
return memmanifestctx(self._manifestlog) | return memmanifestctx(self._manifestlog) | ||||
def copy(self): | def copy(self): | ||||
memmf = memmanifestctx(self._manifestlog) | memmf = memmanifestctx(self._manifestlog) | ||||
memmf._manifestdict = self.read().copy() | memmf._manifestdict = self.read().copy() | ||||
return memmf | return memmf | ||||
def read(self): | def read(self): | ||||
return self._manifestdict | return self._manifestdict | ||||
def write(self, transaction, link, p1, p2, added, removed): | def write(self, transaction, link, p1, p2, added, removed): | ||||
return self._revlog().add(self._manifestdict, transaction, link, p1, p2, | return self._storage().add(self._manifestdict, transaction, link, | ||||
added, removed) | p1, p2, added, removed) | ||||
@interfaceutil.implementer(repository.imanifestrevisionstored) | @interfaceutil.implementer(repository.imanifestrevisionstored) | ||||
class manifestctx(object): | class manifestctx(object): | ||||
"""A class representing a single revision of a manifest, including its | """A class representing a single revision of a manifest, including its | ||||
contents, its parent revs, and its linkrev. | contents, its parent revs, and its linkrev. | ||||
""" | """ | ||||
def __init__(self, manifestlog, node): | def __init__(self, manifestlog, node): | ||||
self._manifestlog = manifestlog | self._manifestlog = manifestlog | ||||
self._data = None | self._data = None | ||||
self._node = node | self._node = node | ||||
# TODO: We eventually want p1, p2, and linkrev exposed on this class, | # TODO: We eventually want p1, p2, and linkrev exposed on this class, | ||||
# but let's add it later when something needs it and we can load it | # but let's add it later when something needs it and we can load it | ||||
# lazily. | # lazily. | ||||
#self.p1, self.p2 = revlog.parents(node) | #self.p1, self.p2 = store.parents(node) | ||||
#rev = revlog.rev(node) | #rev = store.rev(node) | ||||
#self.linkrev = revlog.linkrev(rev) | #self.linkrev = store.linkrev(rev) | ||||
def _revlog(self): | def _storage(self): | ||||
return self._manifestlog._revlog | return self._manifestlog._revlog | ||||
def node(self): | def node(self): | ||||
return self._node | return self._node | ||||
def new(self): | def new(self): | ||||
return memmanifestctx(self._manifestlog) | return memmanifestctx(self._manifestlog) | ||||
def copy(self): | def copy(self): | ||||
memmf = memmanifestctx(self._manifestlog) | memmf = memmanifestctx(self._manifestlog) | ||||
memmf._manifestdict = self.read().copy() | memmf._manifestdict = self.read().copy() | ||||
return memmf | return memmf | ||||
@propertycache | @propertycache | ||||
def parents(self): | def parents(self): | ||||
return self._revlog().parents(self._node) | return self._storage().parents(self._node) | ||||
def read(self): | def read(self): | ||||
if self._data is None: | if self._data is None: | ||||
if self._node == nullid: | if self._node == nullid: | ||||
self._data = manifestdict() | self._data = manifestdict() | ||||
else: | else: | ||||
rl = self._revlog() | store = self._storage() | ||||
if self._node in rl._fulltextcache: | # TODO accessing non-public API. | ||||
text = pycompat.bytestr(rl._fulltextcache[self._node]) | if self._node in store._fulltextcache: | ||||
text = pycompat.bytestr(store._fulltextcache[self._node]) | |||||
else: | else: | ||||
text = rl.revision(self._node) | text = store.revision(self._node) | ||||
arraytext = bytearray(text) | arraytext = bytearray(text) | ||||
rl._fulltextcache[self._node] = arraytext | store._fulltextcache[self._node] = arraytext | ||||
self._data = manifestdict(text) | self._data = manifestdict(text) | ||||
return self._data | return self._data | ||||
def readfast(self, shallow=False): | def readfast(self, shallow=False): | ||||
'''Calls either readdelta or read, based on which would be less work. | '''Calls either readdelta or read, based on which would be less work. | ||||
readdelta is called if the delta is against the p1, and therefore can be | readdelta is called if the delta is against the p1, and therefore can be | ||||
read quickly. | read quickly. | ||||
If `shallow` is True, nothing changes since this is a flat manifest. | If `shallow` is True, nothing changes since this is a flat manifest. | ||||
''' | ''' | ||||
rl = self._revlog() | store = self._storage() | ||||
r = rl.rev(self._node) | r = store.rev(self._node) | ||||
deltaparent = rl.deltaparent(r) | deltaparent = store.deltaparent(r) | ||||
if deltaparent != nullrev and deltaparent in rl.parentrevs(r): | if deltaparent != nullrev and deltaparent in store.parentrevs(r): | ||||
return self.readdelta() | return self.readdelta() | ||||
return self.read() | return self.read() | ||||
def readdelta(self, shallow=False): | def readdelta(self, shallow=False): | ||||
'''Returns a manifest containing just the entries that are present | '''Returns a manifest containing just the entries that are present | ||||
in this manifest, but not in its p1 manifest. This is efficient to read | in this manifest, but not in its p1 manifest. This is efficient to read | ||||
if the revlog delta is already p1. | if the revlog delta is already p1. | ||||
Changing the value of `shallow` has no effect on flat manifests. | Changing the value of `shallow` has no effect on flat manifests. | ||||
''' | ''' | ||||
revlog = self._revlog() | store = self._storage() | ||||
r = revlog.rev(self._node) | r = store.rev(self._node) | ||||
d = mdiff.patchtext(revlog.revdiff(revlog.deltaparent(r), r)) | d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r)) | ||||
return manifestdict(d) | return manifestdict(d) | ||||
def find(self, key): | def find(self, key): | ||||
return self.read().find(key) | return self.read().find(key) | ||||
@interfaceutil.implementer(repository.imanifestrevisionwritable) | @interfaceutil.implementer(repository.imanifestrevisionwritable) | ||||
class memtreemanifestctx(object): | class memtreemanifestctx(object): | ||||
def __init__(self, manifestlog, dir=''): | def __init__(self, manifestlog, dir=''): | ||||
self._manifestlog = manifestlog | self._manifestlog = manifestlog | ||||
self._dir = dir | self._dir = dir | ||||
self._treemanifest = treemanifest() | self._treemanifest = treemanifest() | ||||
def _revlog(self): | def _storage(self): | ||||
return self._manifestlog._revlog | return self._manifestlog._revlog | ||||
def new(self, dir=''): | def new(self, dir=''): | ||||
return memtreemanifestctx(self._manifestlog, dir=dir) | return memtreemanifestctx(self._manifestlog, dir=dir) | ||||
def copy(self): | def copy(self): | ||||
memmf = memtreemanifestctx(self._manifestlog, dir=self._dir) | memmf = memtreemanifestctx(self._manifestlog, dir=self._dir) | ||||
memmf._treemanifest = self._treemanifest.copy() | memmf._treemanifest = self._treemanifest.copy() | ||||
return memmf | return memmf | ||||
def read(self): | def read(self): | ||||
return self._treemanifest | return self._treemanifest | ||||
def write(self, transaction, link, p1, p2, added, removed): | def write(self, transaction, link, p1, p2, added, removed): | ||||
def readtree(dir, node): | def readtree(dir, node): | ||||
return self._manifestlog.get(dir, node).read() | return self._manifestlog.get(dir, node).read() | ||||
return self._revlog().add(self._treemanifest, transaction, link, p1, p2, | return self._storage().add(self._treemanifest, transaction, link, | ||||
added, removed, readtree=readtree) | p1, p2, added, removed, readtree=readtree) | ||||
@interfaceutil.implementer(repository.imanifestrevisionstored) | @interfaceutil.implementer(repository.imanifestrevisionstored) | ||||
class treemanifestctx(object): | class treemanifestctx(object): | ||||
def __init__(self, manifestlog, dir, node): | def __init__(self, manifestlog, dir, node): | ||||
self._manifestlog = manifestlog | self._manifestlog = manifestlog | ||||
self._dir = dir | self._dir = dir | ||||
self._data = None | self._data = None | ||||
self._node = node | self._node = node | ||||
# TODO: Load p1/p2/linkrev lazily. They need to be lazily loaded so that | # TODO: Load p1/p2/linkrev lazily. They need to be lazily loaded so that | ||||
# we can instantiate treemanifestctx objects for directories we don't | # we can instantiate treemanifestctx objects for directories we don't | ||||
# have on disk. | # have on disk. | ||||
#self.p1, self.p2 = revlog.parents(node) | #self.p1, self.p2 = store.parents(node) | ||||
#rev = revlog.rev(node) | #rev = store.rev(node) | ||||
#self.linkrev = revlog.linkrev(rev) | #self.linkrev = store.linkrev(rev) | ||||
def _revlog(self): | def _storage(self): | ||||
narrowmatch = self._manifestlog._narrowmatch | narrowmatch = self._manifestlog._narrowmatch | ||||
if not narrowmatch.always(): | if not narrowmatch.always(): | ||||
if not narrowmatch.visitdir(self._dir[:-1] or '.'): | if not narrowmatch.visitdir(self._dir[:-1] or '.'): | ||||
return excludedmanifestrevlog(self._dir) | return excludedmanifestrevlog(self._dir) | ||||
return self._manifestlog.getstorage(self._dir) | return self._manifestlog.getstorage(self._dir) | ||||
def read(self): | def read(self): | ||||
if self._data is None: | if self._data is None: | ||||
rl = self._revlog() | store = self._storage() | ||||
if self._node == nullid: | if self._node == nullid: | ||||
self._data = treemanifest() | self._data = treemanifest() | ||||
elif rl._treeondisk: | # TODO accessing non-public API | ||||
elif store._treeondisk: | |||||
m = treemanifest(dir=self._dir) | m = treemanifest(dir=self._dir) | ||||
def gettext(): | def gettext(): | ||||
return rl.revision(self._node) | return store.revision(self._node) | ||||
def readsubtree(dir, subm): | def readsubtree(dir, subm): | ||||
# Set verify to False since we need to be able to create | # Set verify to False since we need to be able to create | ||||
# subtrees for trees that don't exist on disk. | # subtrees for trees that don't exist on disk. | ||||
return self._manifestlog.get(dir, subm, verify=False).read() | return self._manifestlog.get(dir, subm, verify=False).read() | ||||
m.read(gettext, readsubtree) | m.read(gettext, readsubtree) | ||||
m.setnode(self._node) | m.setnode(self._node) | ||||
self._data = m | self._data = m | ||||
else: | else: | ||||
if self._node in rl.fulltextcache: | if self._node in store.fulltextcache: | ||||
text = pycompat.bytestr(rl.fulltextcache[self._node]) | text = pycompat.bytestr(store.fulltextcache[self._node]) | ||||
else: | else: | ||||
text = rl.revision(self._node) | text = store.revision(self._node) | ||||
arraytext = bytearray(text) | arraytext = bytearray(text) | ||||
rl.fulltextcache[self._node] = arraytext | store.fulltextcache[self._node] = arraytext | ||||
self._data = treemanifest(dir=self._dir, text=text) | self._data = treemanifest(dir=self._dir, text=text) | ||||
return self._data | return self._data | ||||
def node(self): | def node(self): | ||||
return self._node | return self._node | ||||
def new(self, dir=''): | def new(self, dir=''): | ||||
return memtreemanifestctx(self._manifestlog, dir=dir) | return memtreemanifestctx(self._manifestlog, dir=dir) | ||||
def copy(self): | def copy(self): | ||||
memmf = memtreemanifestctx(self._manifestlog, dir=self._dir) | memmf = memtreemanifestctx(self._manifestlog, dir=self._dir) | ||||
memmf._treemanifest = self.read().copy() | memmf._treemanifest = self.read().copy() | ||||
return memmf | return memmf | ||||
@propertycache | @propertycache | ||||
def parents(self): | def parents(self): | ||||
return self._revlog().parents(self._node) | return self._storage().parents(self._node) | ||||
def readdelta(self, shallow=False): | def readdelta(self, shallow=False): | ||||
'''Returns a manifest containing just the entries that are present | '''Returns a manifest containing just the entries that are present | ||||
in this manifest, but not in its p1 manifest. This is efficient to read | in this manifest, but not in its p1 manifest. This is efficient to read | ||||
if the revlog delta is already p1. | if the revlog delta is already p1. | ||||
If `shallow` is True, this will read the delta for this directory, | If `shallow` is True, this will read the delta for this directory, | ||||
without recursively reading subdirectory manifests. Instead, any | without recursively reading subdirectory manifests. Instead, any | ||||
subdirectory entry will be reported as it appears in the manifest, i.e. | subdirectory entry will be reported as it appears in the manifest, i.e. | ||||
the subdirectory will be reported among files and distinguished only by | the subdirectory will be reported among files and distinguished only by | ||||
its 't' flag. | its 't' flag. | ||||
''' | ''' | ||||
revlog = self._revlog() | store = self._storage() | ||||
if shallow: | if shallow: | ||||
r = revlog.rev(self._node) | r = store.rev(self._node) | ||||
d = mdiff.patchtext(revlog.revdiff(revlog.deltaparent(r), r)) | d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r)) | ||||
return manifestdict(d) | return manifestdict(d) | ||||
else: | else: | ||||
# Need to perform a slow delta | # Need to perform a slow delta | ||||
r0 = revlog.deltaparent(revlog.rev(self._node)) | r0 = store.deltaparent(store.rev(self._node)) | ||||
m0 = self._manifestlog.get(self._dir, revlog.node(r0)).read() | m0 = self._manifestlog.get(self._dir, store.node(r0)).read() | ||||
m1 = self.read() | m1 = self.read() | ||||
md = treemanifest(dir=self._dir) | md = treemanifest(dir=self._dir) | ||||
for f, ((n0, fl0), (n1, fl1)) in m0.diff(m1).iteritems(): | for f, ((n0, fl0), (n1, fl1)) in m0.diff(m1).iteritems(): | ||||
if n1: | if n1: | ||||
md[f] = n1 | md[f] = n1 | ||||
if fl1: | if fl1: | ||||
md.setflag(f, fl1) | md.setflag(f, fl1) | ||||
return md | return md | ||||
def readfast(self, shallow=False): | def readfast(self, shallow=False): | ||||
'''Calls either readdelta or read, based on which would be less work. | '''Calls either readdelta or read, based on which would be less work. | ||||
readdelta is called if the delta is against the p1, and therefore can be | readdelta is called if the delta is against the p1, and therefore can be | ||||
read quickly. | read quickly. | ||||
If `shallow` is True, it only returns the entries from this manifest, | If `shallow` is True, it only returns the entries from this manifest, | ||||
and not any submanifests. | and not any submanifests. | ||||
''' | ''' | ||||
rl = self._revlog() | store = self._storage() | ||||
r = rl.rev(self._node) | r = store.rev(self._node) | ||||
deltaparent = rl.deltaparent(r) | deltaparent = store.deltaparent(r) | ||||
if (deltaparent != nullrev and | if (deltaparent != nullrev and | ||||
deltaparent in rl.parentrevs(r)): | deltaparent in store.parentrevs(r)): | ||||
return self.readdelta(shallow=shallow) | return self.readdelta(shallow=shallow) | ||||
if shallow: | if shallow: | ||||
return manifestdict(rl.revision(self._node)) | return manifestdict(store.revision(self._node)) | ||||
else: | else: | ||||
return self.read() | return self.read() | ||||
def find(self, key): | def find(self, key): | ||||
return self.read().find(key) | return self.read().find(key) | ||||
class excludeddir(treemanifest): | class excludeddir(treemanifest): | ||||
"""Stand-in for a directory that is excluded from the repository. | """Stand-in for a directory that is excluded from the repository. |