/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 brzlib/vf_search.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Searching in versioned file repositories."""
18
18
 
19
 
import itertools
 
19
from __future__ import absolute_import
20
20
 
21
 
from .. import (
 
21
from brzlib import (
22
22
    debug,
23
23
    revision,
24
24
    trace,
25
25
    )
26
26
 
27
 
from ..graph import (
 
27
from brzlib.graph import (
28
28
    DictParentsProvider,
29
29
    Graph,
30
30
    invert_parent_map,
33
33
 
34
34
class AbstractSearchResult(object):
35
35
    """The result of a search, describing a set of keys.
36
 
 
 
36
    
37
37
    Search results are typically used as the 'fetch_spec' parameter when
38
38
    fetching revisions.
39
39
 
125
125
        else:
126
126
            exclude_keys_repr = repr(exclude_keys)
127
127
        return '<%s %s:(%s, %s, %d)>' % (self.__class__.__name__,
128
 
                                         kind, start_keys_repr, exclude_keys_repr, key_count)
 
128
            kind, start_keys_repr, exclude_keys_repr, key_count)
129
129
 
130
130
    def get_recipe(self):
131
131
        """Return a recipe that can be used to replay this search.
151
151
        return self._recipe
152
152
 
153
153
    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)))
 
154
        start_keys = ' '.join(self._recipe[1])
 
155
        stop_keys = ' '.join(self._recipe[2])
 
156
        count = str(self._recipe[3])
 
157
        return (self._recipe[0], '\n'.join((start_keys, stop_keys, count)))
159
158
 
160
159
    def get_keys(self):
161
160
        """Return the keys found in this search.
234
233
        return ('proxy-search', self.heads, set(), -1)
235
234
 
236
235
    def get_network_struct(self):
237
 
        parts = [b'ancestry-of']
 
236
        parts = ['ancestry-of']
238
237
        parts.extend(self.heads)
239
238
        return parts
240
239
 
290
289
        raise NotImplementedError(self.get_recipe)
291
290
 
292
291
    def get_network_struct(self):
293
 
        return (b'everything',)
 
292
        return ('everything',)
294
293
 
295
294
    def get_keys(self):
296
295
        if 'evil' in debug.debug_flags:
297
 
            from . import remote
 
296
            from brzlib import remote
298
297
            if isinstance(self._repo, remote.RemoteRepository):
299
298
                # warn developers (not users) not to do this
300
299
                trace.mutter_callsite(
331
330
    """Find all revisions missing in one repo for a some specific heads."""
332
331
 
333
332
    def __init__(self, to_repo, from_repo, required_ids, if_present_ids=None,
334
 
                 find_ghosts=False, limit=None):
 
333
            find_ghosts=False, limit=None):
335
334
        """Constructor.
336
335
 
337
336
        :param required_ids: revision IDs of heads that must be found, or else
362
361
 
363
362
        return ("<%s from:%r to:%r find_ghosts:%r req'd:%r if-present:%r"
364
363
                "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)
 
364
                self.__class__.__name__, self.from_repo, self.to_repo,
 
365
                self.find_ghosts, reqd_revs_repr, ifp_revs_repr,
 
366
                self.limit)
368
367
 
369
368
    def execute(self):
370
369
        return self.to_repo.search_missing_revision_ids(
381
380
    # start_set is all the keys in the cache
382
381
    start_set = set(parent_map)
383
382
    # result set is all the references to keys in the cache
384
 
    result_parents = set(itertools.chain.from_iterable(parent_map.values()))
 
383
    result_parents = set()
 
384
    for parents in parent_map.itervalues():
 
385
        result_parents.update(parents)
385
386
    stop_keys = result_parents.difference(start_set)
386
387
    # We don't need to send ghosts back to the server as a position to
387
388
    # stop either.
388
389
    stop_keys.difference_update(missing_keys)
389
390
    key_count = len(parent_map)
390
391
    if (revision.NULL_REVISION in result_parents
391
 
            and revision.NULL_REVISION in missing_keys):
 
392
        and revision.NULL_REVISION in missing_keys):
392
393
        # If we pruned NULL_REVISION from the stop_keys because it's also
393
394
        # in our cache of "missing" keys we need to increment our key count
394
395
        # by 1, because the reconsitituted SearchResult on the server will
416
417
    found_heads = set()
417
418
    while True:
418
419
        try:
419
 
            next_revs = next(s)
 
420
            next_revs = s.next()
420
421
        except StopIteration:
421
422
            break
422
 
        for parents in s._current_parents.values():
 
423
        for parents in s._current_parents.itervalues():
423
424
            f_heads = heads.intersection(parents)
424
425
            if f_heads:
425
426
                found_heads.update(f_heads)
426
427
        stop_keys = exclude_keys.intersection(next_revs)
427
428
        if stop_keys:
428
429
            s.stop_searching_any(stop_keys)
429
 
    for parents in s._current_parents.values():
 
430
    for parents in s._current_parents.itervalues():
430
431
        f_heads = heads.intersection(parents)
431
432
        if f_heads:
432
433
            found_heads.update(f_heads)