hgext/remotefilelog/metadatastore.py
changeset 43076 2372284d9457
parent 40657 13d4ad8d7801
child 43077 687b865b95ad
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
     3 from mercurial.node import hex, nullid
     3 from mercurial.node import hex, nullid
     4 from . import (
     4 from . import (
     5     basestore,
     5     basestore,
     6     shallowutil,
     6     shallowutil,
     7 )
     7 )
       
     8 
     8 
     9 
     9 class unionmetadatastore(basestore.baseunionstore):
    10 class unionmetadatastore(basestore.baseunionstore):
    10     def __init__(self, *args, **kwargs):
    11     def __init__(self, *args, **kwargs):
    11         super(unionmetadatastore, self).__init__(*args, **kwargs)
    12         super(unionmetadatastore, self).__init__(*args, **kwargs)
    12 
    13 
    30             known = set()
    31             known = set()
    31         if node in known:
    32         if node in known:
    32             return []
    33             return []
    33 
    34 
    34         ancestors = {}
    35         ancestors = {}
       
    36 
    35         def traverse(curname, curnode):
    37         def traverse(curname, curnode):
    36             # TODO: this algorithm has the potential to traverse parts of
    38             # TODO: this algorithm has the potential to traverse parts of
    37             # history twice. Ex: with A->B->C->F and A->B->D->F, both D and C
    39             # history twice. Ex: with A->B->C->F and A->B->D->F, both D and C
    38             # may be queued as missing, then B and A are traversed for both.
    40             # may be queued as missing, then B and A are traversed for both.
    39             queue = [(curname, curnode)]
    41             queue = [(curname, curnode)]
    57 
    59 
    58         missing = [(name, node)]
    60         missing = [(name, node)]
    59         while missing:
    61         while missing:
    60             curname, curnode = missing.pop()
    62             curname, curnode = missing.pop()
    61             try:
    63             try:
    62                 ancestors.update(self._getpartialancestors(curname, curnode,
    64                 ancestors.update(
    63                                                            known=known))
    65                     self._getpartialancestors(curname, curnode, known=known)
       
    66                 )
    64                 newmissing = traverse(curname, curnode)
    67                 newmissing = traverse(curname, curnode)
    65                 missing.extend(newmissing)
    68                 missing.extend(newmissing)
    66             except KeyError:
    69             except KeyError:
    67                 # If we allow incomplete histories, don't throw.
    70                 # If we allow incomplete histories, don't throw.
    68                 if not self.allowincomplete:
    71                 if not self.allowincomplete:
    93                 pass
    96                 pass
    94 
    97 
    95         raise KeyError((name, hex(node)))
    98         raise KeyError((name, hex(node)))
    96 
    99 
    97     def add(self, name, node, data):
   100     def add(self, name, node, data):
    98         raise RuntimeError("cannot add content only to remotefilelog "
   101         raise RuntimeError(
    99                            "contentstore")
   102             "cannot add content only to remotefilelog " "contentstore"
       
   103         )
   100 
   104 
   101     def getmissing(self, keys):
   105     def getmissing(self, keys):
   102         missing = keys
   106         missing = keys
   103         for store in self.stores:
   107         for store in self.stores:
   104             if missing:
   108             if missing:
   110             store.markledger(ledger, options)
   114             store.markledger(ledger, options)
   111 
   115 
   112     def getmetrics(self):
   116     def getmetrics(self):
   113         metrics = [s.getmetrics() for s in self.stores]
   117         metrics = [s.getmetrics() for s in self.stores]
   114         return shallowutil.sumdicts(*metrics)
   118         return shallowutil.sumdicts(*metrics)
       
   119 
   115 
   120 
   116 class remotefilelogmetadatastore(basestore.basestore):
   121 class remotefilelogmetadatastore(basestore.basestore):
   117     def getancestors(self, name, node, known=None):
   122     def getancestors(self, name, node, known=None):
   118         """Returns as many ancestors as we're aware of.
   123         """Returns as many ancestors as we're aware of.
   119 
   124 
   128 
   133 
   129     def getnodeinfo(self, name, node):
   134     def getnodeinfo(self, name, node):
   130         return self.getancestors(name, node)[node]
   135         return self.getancestors(name, node)[node]
   131 
   136 
   132     def add(self, name, node, parents, linknode):
   137     def add(self, name, node, parents, linknode):
   133         raise RuntimeError("cannot add metadata only to remotefilelog "
   138         raise RuntimeError(
   134                            "metadatastore")
   139             "cannot add metadata only to remotefilelog " "metadatastore"
       
   140         )
       
   141 
   135 
   142 
   136 class remotemetadatastore(object):
   143 class remotemetadatastore(object):
   137     def __init__(self, ui, fileservice, shared):
   144     def __init__(self, ui, fileservice, shared):
   138         self._fileservice = fileservice
   145         self._fileservice = fileservice
   139         self._shared = shared
   146         self._shared = shared
   140 
   147 
   141     def getancestors(self, name, node, known=None):
   148     def getancestors(self, name, node, known=None):
   142         self._fileservice.prefetch([(name, hex(node))], force=True,
   149         self._fileservice.prefetch(
   143                                    fetchdata=False, fetchhistory=True)
   150             [(name, hex(node))], force=True, fetchdata=False, fetchhistory=True
       
   151         )
   144         return self._shared.getancestors(name, node, known=known)
   152         return self._shared.getancestors(name, node, known=known)
   145 
   153 
   146     def getnodeinfo(self, name, node):
   154     def getnodeinfo(self, name, node):
   147         return self.getancestors(name, node)[node]
   155         return self.getancestors(name, node)[node]
   148 
   156