/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/bzr/vf_search.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Searching in versioned file repositories."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
import itertools
20
22
 
21
23
from .. import (
29
31
    Graph,
30
32
    invert_parent_map,
31
33
    )
 
34
from ..sixish import (
 
35
    viewvalues,
 
36
    )
32
37
 
33
38
 
34
39
class AbstractSearchResult(object):
125
130
        else:
126
131
            exclude_keys_repr = repr(exclude_keys)
127
132
        return '<%s %s:(%s, %s, %d)>' % (self.__class__.__name__,
128
 
                                         kind, start_keys_repr, exclude_keys_repr, key_count)
 
133
            kind, start_keys_repr, exclude_keys_repr, key_count)
129
134
 
130
135
    def get_recipe(self):
131
136
        """Return a recipe that can be used to replay this search.
151
156
        return self._recipe
152
157
 
153
158
    def get_network_struct(self):
154
 
        start_keys = b' '.join(self._recipe[1])
155
 
        stop_keys = b' '.join(self._recipe[2])
156
 
        count = str(self._recipe[3]).encode('ascii')
157
 
        return (self._recipe[0].encode('ascii'),
158
 
                b'\n'.join((start_keys, stop_keys, count)))
 
159
        start_keys = ' '.join(self._recipe[1])
 
160
        stop_keys = ' '.join(self._recipe[2])
 
161
        count = str(self._recipe[3])
 
162
        return (self._recipe[0], '\n'.join((start_keys, stop_keys, count)))
159
163
 
160
164
    def get_keys(self):
161
165
        """Return the keys found in this search.
234
238
        return ('proxy-search', self.heads, set(), -1)
235
239
 
236
240
    def get_network_struct(self):
237
 
        parts = [b'ancestry-of']
 
241
        parts = ['ancestry-of']
238
242
        parts.extend(self.heads)
239
243
        return parts
240
244
 
290
294
        raise NotImplementedError(self.get_recipe)
291
295
 
292
296
    def get_network_struct(self):
293
 
        return (b'everything',)
 
297
        return ('everything',)
294
298
 
295
299
    def get_keys(self):
296
300
        if 'evil' in debug.debug_flags:
331
335
    """Find all revisions missing in one repo for a some specific heads."""
332
336
 
333
337
    def __init__(self, to_repo, from_repo, required_ids, if_present_ids=None,
334
 
                 find_ghosts=False, limit=None):
 
338
            find_ghosts=False, limit=None):
335
339
        """Constructor.
336
340
 
337
341
        :param required_ids: revision IDs of heads that must be found, or else
362
366
 
363
367
        return ("<%s from:%r to:%r find_ghosts:%r req'd:%r if-present:%r"
364
368
                "limit:%r>") % (
365
 
            self.__class__.__name__, self.from_repo, self.to_repo,
366
 
            self.find_ghosts, reqd_revs_repr, ifp_revs_repr,
367
 
            self.limit)
 
369
                self.__class__.__name__, self.from_repo, self.to_repo,
 
370
                self.find_ghosts, reqd_revs_repr, ifp_revs_repr,
 
371
                self.limit)
368
372
 
369
373
    def execute(self):
370
374
        return self.to_repo.search_missing_revision_ids(
381
385
    # start_set is all the keys in the cache
382
386
    start_set = set(parent_map)
383
387
    # result set is all the references to keys in the cache
384
 
    result_parents = set(itertools.chain.from_iterable(parent_map.values()))
 
388
    result_parents = set(itertools.chain.from_iterable(viewvalues(parent_map)))
385
389
    stop_keys = result_parents.difference(start_set)
386
390
    # We don't need to send ghosts back to the server as a position to
387
391
    # stop either.
388
392
    stop_keys.difference_update(missing_keys)
389
393
    key_count = len(parent_map)
390
394
    if (revision.NULL_REVISION in result_parents
391
 
            and revision.NULL_REVISION in missing_keys):
 
395
        and revision.NULL_REVISION in missing_keys):
392
396
        # If we pruned NULL_REVISION from the stop_keys because it's also
393
397
        # in our cache of "missing" keys we need to increment our key count
394
398
        # by 1, because the reconsitituted SearchResult on the server will
419
423
            next_revs = next(s)
420
424
        except StopIteration:
421
425
            break
422
 
        for parents in s._current_parents.values():
 
426
        for parents in viewvalues(s._current_parents):
423
427
            f_heads = heads.intersection(parents)
424
428
            if f_heads:
425
429
                found_heads.update(f_heads)
426
430
        stop_keys = exclude_keys.intersection(next_revs)
427
431
        if stop_keys:
428
432
            s.stop_searching_any(stop_keys)
429
 
    for parents in s._current_parents.values():
 
433
    for parents in viewvalues(s._current_parents):
430
434
        f_heads = heads.intersection(parents)
431
435
        if f_heads:
432
436
            found_heads.update(f_heads)