mercurial/setdiscovery.py
changeset 41881 e514799e4e07
parent 41880 55919b96c02a
child 41882 c98420914c10
equal deleted inserted replaced
41880:55919b96c02a 41881:e514799e4e07
   163         """the heads of the known common set"""
   163         """the heads of the known common set"""
   164         # heads(common) == heads(common.bases) since common represents
   164         # heads(common) == heads(common.bases) since common represents
   165         # common.bases and all its ancestors
   165         # common.bases and all its ancestors
   166         return self._common.basesheads()
   166         return self._common.basesheads()
   167 
   167 
       
   168     def _parentsgetter(self):
       
   169         getrev = self._repo.changelog.index.__getitem__
       
   170         def getparents(r):
       
   171             return getrev(r)[5:6]
       
   172         return getparents
       
   173 
   168     def takequicksample(self, headrevs, size):
   174     def takequicksample(self, headrevs, size):
   169         """takes a quick sample of size <size>
   175         """takes a quick sample of size <size>
   170 
   176 
   171         It is meant for initial sampling and focuses on querying heads and close
   177         It is meant for initial sampling and focuses on querying heads and close
   172         ancestors of heads.
   178         ancestors of heads.
   179         sample = set(self._repo.revs('heads(%ld)', revs))
   185         sample = set(self._repo.revs('heads(%ld)', revs))
   180 
   186 
   181         if len(sample) >= size:
   187         if len(sample) >= size:
   182             return _limitsample(sample, size)
   188             return _limitsample(sample, size)
   183 
   189 
   184         _updatesample(None, headrevs, sample, self._repo.changelog.parentrevs,
   190         _updatesample(None, headrevs, sample, self._parentsgetter(),
   185                       quicksamplesize=size)
   191                       quicksamplesize=size)
   186         return sample
   192         return sample
   187 
   193 
   188     def takefullsample(self, headrevs, size):
   194     def takefullsample(self, headrevs, size):
   189         revs = self.undecided
   195         revs = self.undecided
   190         if len(revs) <= size:
   196         if len(revs) <= size:
   191             return list(revs)
   197             return list(revs)
   192         repo = self._repo
   198         repo = self._repo
   193         sample = set(repo.revs('heads(%ld)', revs))
   199         sample = set(repo.revs('heads(%ld)', revs))
       
   200         parentrevs = self._parentsgetter()
   194 
   201 
   195         # update from heads
   202         # update from heads
   196         revsheads = sample.copy()
   203         revsheads = sample.copy()
   197         _updatesample(revs, revsheads, sample, repo.changelog.parentrevs)
   204         _updatesample(revs, revsheads, sample, parentrevs)
   198 
   205 
   199         # update from roots
   206         # update from roots
   200         revsroots = set(repo.revs('roots(%ld)', revs))
   207         revsroots = set(repo.revs('roots(%ld)', revs))
   201 
   208 
   202         # _updatesample() essentially does interaction over revisions to look
   209         # _updatesample() essentially does interaction over revisions to look
   207         # Because this function can be called multiple times during discovery,
   214         # Because this function can be called multiple times during discovery,
   208         # we may still perform redundant work and there is room to optimize
   215         # we may still perform redundant work and there is room to optimize
   209         # this by keeping a persistent cache of children across invocations.
   216         # this by keeping a persistent cache of children across invocations.
   210         children = {}
   217         children = {}
   211 
   218 
   212         parentrevs = repo.changelog.parentrevs
       
   213         for rev in repo.changelog.revs(start=min(revsroots)):
   219         for rev in repo.changelog.revs(start=min(revsroots)):
   214             # Always ensure revision has an entry so we don't need to worry
   220             # Always ensure revision has an entry so we don't need to worry
   215             # about missing keys.
   221             # about missing keys.
   216             children.setdefault(rev, [])
   222             children.setdefault(rev, [])
   217 
   223