##// END OF EJS Templates
unstable: do not consider internal phases when computing unstable...
unstable: do not consider internal phases when computing unstable The revisions that are not part of the "working" set by other means should not be considered for the evolution related computation. This impact the test introduced in 5f9af8422b31 as this is actually a more semantic fix of the issue.

File last commit:

r51822:18c8c189 default
r52017:80bda425 default
Show More
contentstore.py
395 lines | 12.8 KiB | text/x-python | PythonLexer
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 import threading
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 from mercurial.node import (
hex,
sha1nodeconstants,
)
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 from mercurial import (
mdiff,
revlog,
)
from . import (
basestore,
constants,
shallowutil,
)
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class ChainIndicies:
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """A static class for easy reference to the delta chain indicies."""
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 # The filename of this revision delta
NAME = 0
# The mercurial file node for this revision delta
NODE = 1
# The filename of the delta base's revision. This is useful when delta
# between different files (like in the case of a move or copy, we can delta
# against the original file content).
BASENAME = 2
# The mercurial file node for the delta base revision. This is the nullid if
# this delta is a full text.
BASENODE = 3
# The actual delta or full text data.
DATA = 4
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 class unioncontentstore(basestore.baseunionstore):
def __init__(self, *args, **kwargs):
super(unioncontentstore, self).__init__(*args, **kwargs)
self.stores = args
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 self.writestore = kwargs.get('writestore')
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
# If allowincomplete==True then the union store can return partial
# delta chains, otherwise it will throw a KeyError if a full
# deltachain can't be found.
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 self.allowincomplete = kwargs.get('allowincomplete', False)
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
def get(self, name, node):
"""Fetches the full text revision contents of the given name+node pair.
If the full text doesn't exist, throws a KeyError.
Under the hood, this uses getdeltachain() across all the stores to build
up a full chain to produce the full text.
"""
chain = self.getdeltachain(name, node)
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 if chain[-1][ChainIndicies.BASENODE] != sha1nodeconstants.nullid:
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 # If we didn't receive a full chain, throw
raise KeyError((name, hex(node)))
# The last entry in the chain is a full text, so we start our delta
# applies with that.
fulltext = chain.pop()[ChainIndicies.DATA]
text = fulltext
while chain:
delta = chain.pop()[ChainIndicies.DATA]
text = mdiff.patches(text, [delta])
return text
@basestore.baseunionstore.retriable
def getdelta(self, name, node):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """Return the single delta entry for the given name/node pair."""
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 for store in self.stores:
try:
return store.getdelta(name, node)
except KeyError:
pass
raise KeyError((name, hex(node)))
def getdeltachain(self, name, node):
"""Returns the deltachain for the given name/node pair.
Returns an ordered list of:
[(name, node, deltabasename, deltabasenode, deltacontent),...]
where the chain is terminated by a full text entry with a nullid
deltabasenode.
"""
chain = self._getpartialchain(name, node)
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 while chain[-1][ChainIndicies.BASENODE] != sha1nodeconstants.nullid:
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 x, x, deltabasename, deltabasenode, x = chain[-1]
try:
morechain = self._getpartialchain(deltabasename, deltabasenode)
chain.extend(morechain)
except KeyError:
# If we allow incomplete chains, don't throw.
if not self.allowincomplete:
raise
break
return chain
@basestore.baseunionstore.retriable
def getmeta(self, name, node):
"""Returns the metadata dict for given node."""
for store in self.stores:
try:
return store.getmeta(name, node)
except KeyError:
pass
raise KeyError((name, hex(node)))
def getmetrics(self):
metrics = [s.getmetrics() for s in self.stores]
return shallowutil.sumdicts(*metrics)
@basestore.baseunionstore.retriable
def _getpartialchain(self, name, node):
"""Returns a partial delta chain for the given name/node pair.
A partial chain is a chain that may not be terminated in a full-text.
"""
for store in self.stores:
try:
return store.getdeltachain(name, node)
except KeyError:
pass
raise KeyError((name, hex(node)))
def add(self, name, node, data):
Augie Fackler
formatting: blacken the codebase...
r43346 raise RuntimeError(
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 b"cannot add content only to remotefilelog contentstore"
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
def getmissing(self, keys):
missing = keys
for store in self.stores:
if missing:
missing = store.getmissing(missing)
return missing
def addremotefilelognode(self, name, node, data):
if self.writestore:
self.writestore.addremotefilelognode(name, node, data)
else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise RuntimeError(b"no writable store configured")
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
def markledger(self, ledger, options=None):
for store in self.stores:
store.markledger(ledger, options)
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 class remotefilelogcontentstore(basestore.basestore):
def __init__(self, *args, **kwargs):
super(remotefilelogcontentstore, self).__init__(*args, **kwargs)
self._threaddata = threading.local()
def get(self, name, node):
# return raw revision text
data = self._getdata(name, node)
offset, size, flags = shallowutil.parsesizeflags(data)
Augie Fackler
formatting: blacken the codebase...
r43346 content = data[offset : offset + size]
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
ancestormap = shallowutil.ancestormap(data)
p1, p2, linknode, copyfrom = ancestormap[node]
copyrev = None
if copyfrom:
copyrev = hex(p1)
self._updatemetacache(node, size, flags)
# lfs tracks renames in its own metadata, remove hg copy metadata,
# because copy metadata will be re-added by lfs flag processor.
if flags & revlog.REVIDX_EXTSTORED:
copyrev = copyfrom = None
revision = shallowutil.createrevlogtext(content, copyfrom, copyrev)
return revision
def getdelta(self, name, node):
# Since remotefilelog content stores only contain full texts, just
# return that.
revision = self.get(name, node)
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 return (
revision,
name,
sha1nodeconstants.nullid,
self.getmeta(name, node),
)
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
def getdeltachain(self, name, node):
# Since remotefilelog content stores just contain full texts, we return
# a fake delta chain that just consists of a single full text revision.
# The nullid in the deltabasenode slot indicates that the revision is a
# fulltext.
revision = self.get(name, node)
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 return [(name, node, None, sha1nodeconstants.nullid, revision)]
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
def getmeta(self, name, node):
self._sanitizemetacache()
if node != self._threaddata.metacache[0]:
data = self._getdata(name, node)
offset, size, flags = shallowutil.parsesizeflags(data)
self._updatemetacache(node, size, flags)
return self._threaddata.metacache[1]
def add(self, name, node, data):
Augie Fackler
formatting: blacken the codebase...
r43346 raise RuntimeError(
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 b"cannot add content only to remotefilelog contentstore"
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
def _sanitizemetacache(self):
metacache = getattr(self._threaddata, 'metacache', None)
if metacache is None:
Augie Fackler
formatting: blacken the codebase...
r43346 self._threaddata.metacache = (None, None) # (node, meta)
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
def _updatemetacache(self, node, size, flags):
self._sanitizemetacache()
if node == self._threaddata.metacache[0]:
return
Augie Fackler
formatting: blacken the codebase...
r43346 meta = {constants.METAKEYFLAG: flags, constants.METAKEYSIZE: size}
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 self._threaddata.metacache = (node, meta)
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class remotecontentstore:
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 def __init__(self, ui, fileservice, shared):
self._fileservice = fileservice
# type(shared) is usually remotefilelogcontentstore
self._shared = shared
def get(self, name, node):
Augie Fackler
formatting: blacken the codebase...
r43346 self._fileservice.prefetch(
[(name, hex(node))], force=True, fetchdata=True
)
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 return self._shared.get(name, node)
def getdelta(self, name, node):
revision = self.get(name, node)
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 return (
revision,
name,
sha1nodeconstants.nullid,
self._shared.getmeta(name, node),
)
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
def getdeltachain(self, name, node):
# Since our remote content stores just contain full texts, we return a
# fake delta chain that just consists of a single full text revision.
# The nullid in the deltabasenode slot indicates that the revision is a
# fulltext.
revision = self.get(name, node)
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 return [(name, node, None, sha1nodeconstants.nullid, revision)]
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
def getmeta(self, name, node):
Augie Fackler
formatting: blacken the codebase...
r43346 self._fileservice.prefetch(
[(name, hex(node))], force=True, fetchdata=True
)
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 return self._shared.getmeta(name, node)
def add(self, name, node, data):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise RuntimeError(b"cannot add to a remote store")
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
def getmissing(self, keys):
return keys
def markledger(self, ledger, options=None):
pass
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class manifestrevlogstore:
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 def __init__(self, repo):
self._store = repo.store
self._svfs = repo.svfs
self._revlogs = dict()
revlog: use a "radix" to address revlog...
r47921 self._cl = revlog.revlog(self._svfs, radix=b'00changelog.i')
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 self._repackstartlinkrev = 0
def get(self, name, node):
rawdata: update caller in remotefilelog...
r43039 return self._revlog(name).rawdata(node)
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
def getdelta(self, name, node):
revision = self.get(name, node)
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 return revision, name, self._cl.nullid, self.getmeta(name, node)
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
def getdeltachain(self, name, node):
revision = self.get(name, node)
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 return [(name, node, None, self._cl.nullid, revision)]
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
def getmeta(self, name, node):
rl = self._revlog(name)
rev = rl.rev(node)
Augie Fackler
formatting: blacken the codebase...
r43346 return {
constants.METAKEYFLAG: rl.flags(rev),
constants.METAKEYSIZE: rl.rawsize(rev),
}
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
def getancestors(self, name, node, known=None):
if known is None:
known = set()
if node in known:
return []
rl = self._revlog(name)
ancestors = {}
Augie Fackler
cleanup: run pyupgrade on our source tree to clean up varying things...
r44937 missing = {node}
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 for ancrev in rl.ancestors([rl.rev(node)], inclusive=True):
ancnode = rl.node(ancrev)
missing.discard(ancnode)
p1, p2 = rl.parents(ancnode)
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 if p1 != self._cl.nullid and p1 not in known:
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 missing.add(p1)
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 if p2 != self._cl.nullid and p2 not in known:
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 missing.add(p2)
linknode = self._cl.node(rl.linkrev(ancrev))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ancestors[rl.node(ancrev)] = (p1, p2, linknode, b'')
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 if not missing:
break
return ancestors
def getnodeinfo(self, name, node):
cl = self._cl
rl = self._revlog(name)
parents = rl.parents(node)
linkrev = rl.linkrev(rl.rev(node))
return (parents[0], parents[1], cl.node(linkrev), None)
def add(self, *args):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise RuntimeError(b"cannot add to a revlog store")
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
def _revlog(self, name):
rl = self._revlogs.get(name)
if rl is None:
revlog: use a "radix" to address revlog...
r47921 revlogname = b'00manifesttree'
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if name != b'':
revlog: use a "radix" to address revlog...
r47921 revlogname = b'meta/%s/00manifest' % name
rl = revlog.revlog(self._svfs, radix=revlogname)
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 self._revlogs[name] = rl
return rl
def getmissing(self, keys):
missing = []
for name, node in keys:
mfrevlog = self._revlog(name)
if node not in mfrevlog.nodemap:
missing.append((name, node))
return missing
def setrepacklinkrevrange(self, startrev, endrev):
self._repackstartlinkrev = startrev
self._repackendlinkrev = endrev
def markledger(self, ledger, options=None):
if options and options.get(constants.OPTION_PACKSONLY):
return
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 treename = b''
revlog: use a "radix" to address revlog...
r47921 rl = revlog.revlog(self._svfs, radix=b'00manifesttree')
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 startlinkrev = self._repackstartlinkrev
endlinkrev = self._repackendlinkrev
Manuel Jacob
py3: replace `pycompat.xrange` by `range`
r50179 for rev in range(len(rl) - 1, -1, -1):
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 linkrev = rl.linkrev(rev)
if linkrev < startlinkrev:
break
if linkrev > endlinkrev:
continue
node = rl.node(rev)
ledger.markdataentry(self, treename, node)
ledger.markhistoryentry(self, treename, node)
store: rename `datafiles` to `data_entries`...
r51397 for t, path, size in self._store.data_entries():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if path[:5] != b'meta/' or path[-2:] != b'.i':
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 continue
revlog: use a "radix" to address revlog...
r47921 treename = path[5 : -len(b'/00manifest')]
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
revlog: use a "radix" to address revlog...
r47921 rl = revlog.revlog(self._svfs, indexfile=path[:-2])
Manuel Jacob
py3: replace `pycompat.xrange` by `range`
r50179 for rev in range(len(rl) - 1, -1, -1):
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 linkrev = rl.linkrev(rev)
if linkrev < startlinkrev:
break
if linkrev > endlinkrev:
continue
node = rl.node(rev)
ledger.markdataentry(self, treename, node)
ledger.markhistoryentry(self, treename, node)
def cleanup(self, ledger):
pass