mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 16:57:49 +03:00
store: add union stores
Future patches will refactor the storage logic into a more abstract API. This patch adds a union store, which will allow us to check both local client storage and shared cache storage, without exposing the difference at higher levels.
This commit is contained in:
parent
b62ef50278
commit
9c88142860
@ -3,6 +3,46 @@ import basestore, ioutil
|
||||
from mercurial import util
|
||||
from mercurial.node import hex
|
||||
|
||||
class unioncontentstore(object):
|
||||
def __init__(self, local, shared):
|
||||
self._local = local
|
||||
self._shared = shared
|
||||
|
||||
def get(self, name, node):
|
||||
try:
|
||||
return self._shared.get(name, node)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
try:
|
||||
return self._local.get(name, node)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
self._shared.triggerfetches([(name, node)])
|
||||
try:
|
||||
return self._shared.get(name, node)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
raise error.LookupError(id, self.filename, _('no node'))
|
||||
|
||||
def add(self, name, node, data):
|
||||
raise Exception("cannot add content only to remotefilelog "
|
||||
"contentstore")
|
||||
|
||||
def contains(self, keys):
|
||||
missing = self._local.contains(keys)
|
||||
if missing:
|
||||
missing = self._shared.contains(missing)
|
||||
return missing
|
||||
|
||||
def addfetcher(self, fetchfunc):
|
||||
self._shared.addfetcher(fetchfunc)
|
||||
|
||||
def triggerfetches(self, keys):
|
||||
self._shared.triggerfetches(keys)
|
||||
|
||||
class remotefilelogcontentstore(basestore.basestore):
|
||||
def get(self, name, node):
|
||||
pass
|
||||
|
@ -3,6 +3,61 @@ import basestore, ioutil
|
||||
from mercurial import util
|
||||
from mercurial.node import hex
|
||||
|
||||
class unionmetadatastore(object):
|
||||
def __init__(self, local, shared):
|
||||
self._local = local
|
||||
self._shared = shared
|
||||
|
||||
def getparents(self, name, node):
|
||||
"""Returns the immediate parents of the node."""
|
||||
pass
|
||||
|
||||
def getancestors(self, name, node):
|
||||
"""Returns as many ancestors as we're aware of.
|
||||
|
||||
return value: {
|
||||
node: (p1, p2, linknode),
|
||||
...
|
||||
}
|
||||
"""
|
||||
try:
|
||||
return self._shared.getancestors(name, node)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
try:
|
||||
return self._local.getancestors(name, node)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
self._shared.triggerfetches([(name, node)])
|
||||
try:
|
||||
return self._shared.getancestors(name, node)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
raise error.LookupError(node, name, _('no valid file history'))
|
||||
|
||||
def getlinknode(self, name, node):
|
||||
ancestors = self.getancestors(name, node)
|
||||
return ancestors[node][3]
|
||||
|
||||
def add(self, name, node, data):
|
||||
raise Exception("cannot add content only to remotefilelog "
|
||||
"contentstore")
|
||||
|
||||
def contains(self, keys):
|
||||
missing = self._local.contains(keys)
|
||||
if missing:
|
||||
missing = self._shared.contains(missing)
|
||||
return missing
|
||||
|
||||
def addfetcher(self, fetchfunc):
|
||||
self._shared.addfetcher(fetchfunc)
|
||||
|
||||
def triggerfetches(self, keys):
|
||||
self._shared.triggerfetches(keys)
|
||||
|
||||
class remotefilelogmetadatastore(basestore.basestore):
|
||||
def getparents(self, name, node):
|
||||
"""Returns the immediate parents of the node."""
|
||||
|
Loading…
Reference in New Issue
Block a user