2016-04-05 02:26:12 +03:00
|
|
|
import os, shutil
|
2016-04-05 02:26:12 +03:00
|
|
|
import basestore, shallowutil
|
2016-04-27 01:10:38 +03:00
|
|
|
from mercurial import error, mdiff
|
|
|
|
from mercurial.i18n import _
|
|
|
|
from mercurial.node import hex, nullid
|
|
|
|
|
|
|
|
class ChainIndicies(object):
|
|
|
|
"""A static class for easy reference to the delta chain indicies.
|
|
|
|
"""
|
|
|
|
# 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
|
2016-04-05 02:26:12 +03:00
|
|
|
|
2016-04-05 02:26:12 +03:00
|
|
|
class unioncontentstore(object):
|
2016-04-27 01:10:38 +03:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
self.stores = args
|
|
|
|
self.writestore = kwargs.get('writestore')
|
2016-04-05 02:26:12 +03:00
|
|
|
|
|
|
|
def get(self, name, node):
|
2016-04-27 01:10:38 +03:00
|
|
|
"""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)
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
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)
|
|
|
|
while chain[-1][ChainIndicies.BASENODE] != nullid:
|
|
|
|
x, x, deltabasename, deltabasenode, x = chain[-1]
|
|
|
|
morechain = self._getpartialchain(deltabasename, deltabasenode)
|
|
|
|
chain.extend(morechain)
|
|
|
|
|
|
|
|
return chain
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
2016-04-27 01:10:38 +03:00
|
|
|
for store in self.stores:
|
|
|
|
try:
|
2016-04-27 01:10:38 +03:00
|
|
|
return store.getdeltachain(name, node)
|
2016-04-27 01:10:38 +03:00
|
|
|
except KeyError:
|
|
|
|
pass
|
2016-04-05 02:26:12 +03:00
|
|
|
|
2016-04-27 01:10:38 +03:00
|
|
|
raise error.LookupError(name, hex(node), _('no node'))
|
2016-04-05 02:26:12 +03:00
|
|
|
|
|
|
|
def add(self, name, node, data):
|
2016-04-28 02:49:33 +03:00
|
|
|
raise RuntimeError("cannot add content only to remotefilelog "
|
|
|
|
"contentstore")
|
2016-04-05 02:26:12 +03:00
|
|
|
|
2016-04-05 02:48:55 +03:00
|
|
|
def getmissing(self, keys):
|
2016-04-27 01:10:38 +03:00
|
|
|
missing = keys
|
|
|
|
for store in self.stores:
|
|
|
|
if missing:
|
|
|
|
missing = store.getmissing(missing)
|
2016-04-05 02:26:12 +03:00
|
|
|
return missing
|
|
|
|
|
2016-04-05 02:48:55 +03:00
|
|
|
def addremotefilelognode(self, name, node, data):
|
2016-04-27 01:10:38 +03:00
|
|
|
if self.writestore:
|
|
|
|
self.writestore.addremotefilelognode(name, node, data)
|
|
|
|
else:
|
2016-04-28 02:49:33 +03:00
|
|
|
raise RuntimeError("no writable store configured")
|
2016-04-05 02:26:12 +03:00
|
|
|
|
2016-05-03 22:33:00 +03:00
|
|
|
def markledger(self, ledger):
|
|
|
|
for store in self.stores:
|
|
|
|
store.markledger(ledger)
|
|
|
|
|
2016-04-05 02:26:12 +03:00
|
|
|
class remotefilelogcontentstore(basestore.basestore):
|
|
|
|
def get(self, name, node):
|
2016-04-05 02:26:12 +03:00
|
|
|
data = self._getdata(name, node)
|
|
|
|
|
2016-04-05 02:26:12 +03:00
|
|
|
index, size = shallowutil.parsesize(data)
|
2016-04-05 02:26:12 +03:00
|
|
|
content = data[(index + 1):(index + 1 + size)]
|
|
|
|
|
2016-04-05 02:26:12 +03:00
|
|
|
ancestormap = shallowutil.ancestormap(data)
|
2016-04-05 02:26:12 +03:00
|
|
|
p1, p2, linknode, copyfrom = ancestormap[node]
|
|
|
|
copyrev = None
|
|
|
|
if copyfrom:
|
|
|
|
copyrev = hex(p1)
|
|
|
|
|
2016-04-05 02:26:12 +03:00
|
|
|
revision = shallowutil.createrevlogtext(content, copyfrom, copyrev)
|
2016-04-05 02:26:12 +03:00
|
|
|
return revision
|
2016-04-05 02:26:12 +03:00
|
|
|
|
2016-04-27 01:10:38 +03:00
|
|
|
def getdeltachain(self, name, node):
|
2016-04-28 02:49:33 +03:00
|
|
|
# Since remotefilelog content stores just contain full texts, we return
|
|
|
|
# a fake delta chain that just consists of a single full text revision.
|
2016-04-27 01:10:38 +03:00
|
|
|
# The nullid in the deltabasenode slot indicates that the revision is a
|
|
|
|
# fulltext.
|
|
|
|
revision = self.get(name, node)
|
|
|
|
return [(name, node, None, nullid, revision)]
|
|
|
|
|
2016-04-05 02:26:12 +03:00
|
|
|
def add(self, name, node, data):
|
2016-04-28 02:49:33 +03:00
|
|
|
raise RuntimeError("cannot add content only to remotefilelog "
|
|
|
|
"contentstore")
|
2016-04-05 02:26:12 +03:00
|
|
|
|
|
|
|
class remotecontentstore(object):
|
|
|
|
def __init__(self, ui, fileservice, shared):
|
|
|
|
self._fileservice = fileservice
|
|
|
|
self._shared = shared
|
|
|
|
|
|
|
|
def get(self, name, node):
|
2016-05-16 20:59:09 +03:00
|
|
|
self._fileservice.prefetch([(name, hex(node))], force=True,
|
|
|
|
fetchdata=True)
|
2016-04-05 02:26:12 +03:00
|
|
|
return self._shared.get(name, node)
|
|
|
|
|
2016-04-27 01:10:38 +03:00
|
|
|
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)
|
|
|
|
return [(name, node, None, nullid, revision)]
|
|
|
|
|
2016-04-05 02:26:12 +03:00
|
|
|
def add(self, name, node, data):
|
2016-04-28 02:49:33 +03:00
|
|
|
raise RuntimeError("cannot add to a remote store")
|
2016-04-05 02:26:12 +03:00
|
|
|
|
2016-04-27 01:10:38 +03:00
|
|
|
def getmissing(self, keys):
|
|
|
|
return keys
|
2016-05-03 22:33:00 +03:00
|
|
|
|
|
|
|
def markledger(self, ledger):
|
|
|
|
pass
|