comparison mercurial/setdiscovery.py @ 41111:3c85a62d7462

discovery: move handling of sampling special case inside sampling function The handling of cases where the number of revisions to sample is smaller than the sample size can be moved with the sample function themselves. This simplifies main logic, preparing a coming refactoring.
author Boris Feld <boris.feld@octobus.net>
date Fri, 14 Dec 2018 12:01:15 +0100
parents 71b0db4fa027
children 3023bc4b3da0
comparison
equal deleted inserted replaced
41110:71b0db4fa027 41111:3c85a62d7462
100 100
101 :dag: a dag object 101 :dag: a dag object
102 :headrevs: set of head revisions in local DAG to consider 102 :headrevs: set of head revisions in local DAG to consider
103 :revs: set of revs to discover 103 :revs: set of revs to discover
104 :size: the maximum size of the sample""" 104 :size: the maximum size of the sample"""
105 if len(revs) <= size:
106 return list(revs)
105 sample = set(repo.revs('heads(%ld)', revs)) 107 sample = set(repo.revs('heads(%ld)', revs))
106 108
107 if len(sample) >= size: 109 if len(sample) >= size:
108 return _limitsample(sample, size) 110 return _limitsample(sample, size)
109 111
110 _updatesample(None, headrevs, sample, repo.changelog.parentrevs, 112 _updatesample(None, headrevs, sample, repo.changelog.parentrevs,
111 quicksamplesize=size) 113 quicksamplesize=size)
112 return sample 114 return sample
113 115
114 def _takefullsample(repo, headrevs, revs, size): 116 def _takefullsample(repo, headrevs, revs, size):
117 if len(revs) <= size:
118 return list(revs)
115 sample = set(repo.revs('heads(%ld)', revs)) 119 sample = set(repo.revs('heads(%ld)', revs))
116 120
117 # update from heads 121 # update from heads
118 revsheads = set(repo.revs('heads(%ld)', revs)) 122 revsheads = set(repo.revs('heads(%ld)', revs))
119 _updatesample(revs, revsheads, sample, repo.changelog.parentrevs) 123 _updatesample(revs, revsheads, sample, repo.changelog.parentrevs)
262 else: 266 else:
263 # use even cheaper initial sample 267 # use even cheaper initial sample
264 ui.debug("taking quick initial sample\n") 268 ui.debug("taking quick initial sample\n")
265 samplefunc = _takequicksample 269 samplefunc = _takequicksample
266 targetsize = initialsamplesize 270 targetsize = initialsamplesize
267 if len(undecided) <= targetsize: 271 sample = samplefunc(local, ownheads, undecided, targetsize)
268 sample = list(undecided)
269 else:
270 sample = samplefunc(local, ownheads, undecided, targetsize)
271 272
272 roundtrips += 1 273 roundtrips += 1
273 progress.update(roundtrips) 274 progress.update(roundtrips)
274 ui.debug("query %i; still undecided: %i, sample size is: %i\n" 275 ui.debug("query %i; still undecided: %i, sample size is: %i\n"
275 % (roundtrips, len(undecided), len(sample))) 276 % (roundtrips, len(undecided), len(sample)))