/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 bzrlib/repository.py

  • Committer: Martin
  • Date: 2011-01-26 20:02:52 UTC
  • mfrom: (5633 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5634.
  • Revision ID: gzlist@googlemail.com-20110126200252-s4yy1eywfgomxup7
Merge bzr.dev to add release notes for 2.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
    pyutils,
43
43
    revision as _mod_revision,
44
44
    static_tuple,
45
 
    symbol_versioning,
46
45
    trace,
47
46
    tsort,
48
47
    versionedfile,
53
52
from bzrlib.testament import Testament
54
53
""")
55
54
 
56
 
import sys
57
55
from bzrlib import (
58
56
    errors,
59
57
    registry,
 
58
    symbol_versioning,
60
59
    ui,
61
60
    )
62
61
from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
1597
1596
        return ret
1598
1597
 
1599
1598
    @needs_read_lock
1600
 
    def search_missing_revision_ids(self, other, revision_id=None, find_ghosts=True):
 
1599
    def search_missing_revision_ids(self, other,
 
1600
            revision_id=symbol_versioning.DEPRECATED_PARAMETER,
 
1601
            find_ghosts=True, revision_ids=None, if_present_ids=None):
1601
1602
        """Return the revision ids that other has that this does not.
1602
1603
 
1603
1604
        These are returned in topological order.
1604
1605
 
1605
1606
        revision_id: only return revision ids included by revision_id.
1606
1607
        """
 
1608
        if symbol_versioning.deprecated_passed(revision_id):
 
1609
            symbol_versioning.warn(
 
1610
                'search_missing_revision_ids(revision_id=...) was '
 
1611
                'deprecated in 2.3.  Use revision_ids=[...] instead.',
 
1612
                DeprecationWarning, stacklevel=3)
 
1613
            if revision_ids is not None:
 
1614
                raise AssertionError(
 
1615
                    'revision_ids is mutually exclusive with revision_id')
 
1616
            if revision_id is not None:
 
1617
                revision_ids = [revision_id]
1607
1618
        return InterRepository.get(other, self).search_missing_revision_ids(
1608
 
            revision_id, find_ghosts)
 
1619
            find_ghosts=find_ghosts, revision_ids=revision_ids,
 
1620
            if_present_ids=if_present_ids)
1609
1621
 
1610
1622
    @staticmethod
1611
1623
    def open(base):
3436
3448
                               fetch_spec=fetch_spec,
3437
3449
                               find_ghosts=find_ghosts)
3438
3450
 
3439
 
    def _walk_to_common_revisions(self, revision_ids):
 
3451
    def _walk_to_common_revisions(self, revision_ids, if_present_ids=None):
3440
3452
        """Walk out from revision_ids in source to revisions target has.
3441
3453
 
3442
3454
        :param revision_ids: The start point for the search.
3444
3456
        """
3445
3457
        target_graph = self.target.get_graph()
3446
3458
        revision_ids = frozenset(revision_ids)
 
3459
        if if_present_ids:
 
3460
            all_wanted_revs = revision_ids.union(if_present_ids)
 
3461
        else:
 
3462
            all_wanted_revs = revision_ids
3447
3463
        missing_revs = set()
3448
3464
        source_graph = self.source.get_graph()
3449
3465
        # ensure we don't pay silly lookup costs.
3450
 
        searcher = source_graph._make_breadth_first_searcher(revision_ids)
 
3466
        searcher = source_graph._make_breadth_first_searcher(all_wanted_revs)
3451
3467
        null_set = frozenset([_mod_revision.NULL_REVISION])
3452
3468
        searcher_exhausted = False
3453
3469
        while True:
3489
3505
        return searcher.get_result()
3490
3506
 
3491
3507
    @needs_read_lock
3492
 
    def search_missing_revision_ids(self, revision_id=None, find_ghosts=True):
 
3508
    def search_missing_revision_ids(self,
 
3509
            revision_id=symbol_versioning.DEPRECATED_PARAMETER,
 
3510
            find_ghosts=True, revision_ids=None, if_present_ids=None):
3493
3511
        """Return the revision ids that source has that target does not.
3494
3512
 
3495
3513
        :param revision_id: only return revision ids included by this
3496
 
                            revision_id.
 
3514
            revision_id.
 
3515
        :param revision_ids: return revision ids included by these
 
3516
            revision_ids.  NoSuchRevision will be raised if any of these
 
3517
            revisions are not present.
 
3518
        :param if_present_ids: like revision_ids, but will not cause
 
3519
            NoSuchRevision if any of these are absent, instead they will simply
 
3520
            not be in the result.  This is useful for e.g. finding revisions
 
3521
            to fetch for tags, which may reference absent revisions.
3497
3522
        :param find_ghosts: If True find missing revisions in deep history
3498
3523
            rather than just finding the surface difference.
3499
3524
        :return: A bzrlib.graph.SearchResult.
3500
3525
        """
 
3526
        if symbol_versioning.deprecated_passed(revision_id):
 
3527
            symbol_versioning.warn(
 
3528
                'search_missing_revision_ids(revision_id=...) was '
 
3529
                'deprecated in 2.3.  Use revision_ids=[...] instead.',
 
3530
                DeprecationWarning, stacklevel=2)
 
3531
            if revision_ids is not None:
 
3532
                raise AssertionError(
 
3533
                    'revision_ids is mutually exclusive with revision_id')
 
3534
            if revision_id is not None:
 
3535
                revision_ids = [revision_id]
 
3536
        del revision_id
3501
3537
        # stop searching at found target revisions.
3502
 
        if not find_ghosts and revision_id is not None:
3503
 
            return self._walk_to_common_revisions([revision_id])
 
3538
        if not find_ghosts and (revision_ids is not None or if_present_ids is
 
3539
                not None):
 
3540
            return self._walk_to_common_revisions(revision_ids,
 
3541
                    if_present_ids=if_present_ids)
3504
3542
        # generic, possibly worst case, slow code path.
3505
3543
        target_ids = set(self.target.all_revision_ids())
3506
 
        if revision_id is not None:
3507
 
            source_ids = self.source.get_ancestry(revision_id)
3508
 
            if source_ids[0] is not None:
3509
 
                raise AssertionError()
3510
 
            source_ids.pop(0)
3511
 
        else:
3512
 
            source_ids = self.source.all_revision_ids()
 
3544
        source_ids = self._present_source_revisions_for(
 
3545
            revision_ids, if_present_ids)
3513
3546
        result_set = set(source_ids).difference(target_ids)
3514
3547
        return self.source.revision_ids_to_search_result(result_set)
3515
3548
 
 
3549
    def _present_source_revisions_for(self, revision_ids, if_present_ids=None):
 
3550
        """Returns set of all revisions in ancestry of revision_ids present in
 
3551
        the source repo.
 
3552
 
 
3553
        :param revision_ids: if None, all revisions in source are returned.
 
3554
        :param if_present_ids: like revision_ids, but if any/all of these are
 
3555
            absent no error is raised.
 
3556
        """
 
3557
        if revision_ids is not None or if_present_ids is not None:
 
3558
            # First, ensure all specified revisions exist.  Callers expect
 
3559
            # NoSuchRevision when they pass absent revision_ids here.
 
3560
            if revision_ids is None:
 
3561
                revision_ids = set()
 
3562
            if if_present_ids is None:
 
3563
                if_present_ids = set()
 
3564
            revision_ids = set(revision_ids)
 
3565
            if_present_ids = set(if_present_ids)
 
3566
            all_wanted_ids = revision_ids.union(if_present_ids)
 
3567
            graph = self.source.get_graph()
 
3568
            present_revs = set(graph.get_parent_map(all_wanted_ids))
 
3569
            missing = revision_ids.difference(present_revs)
 
3570
            if missing:
 
3571
                raise errors.NoSuchRevision(self.source, missing.pop())
 
3572
            found_ids = all_wanted_ids.intersection(present_revs)
 
3573
            source_ids = [rev_id for (rev_id, parents) in
 
3574
                          graph.iter_ancestry(found_ids)
 
3575
                          if rev_id != _mod_revision.NULL_REVISION
 
3576
                          and parents is not None]
 
3577
        else:
 
3578
            source_ids = self.source.all_revision_ids()
 
3579
        return set(source_ids)
 
3580
 
3516
3581
    @staticmethod
3517
3582
    def _same_model(source, target):
3518
3583
        """True if source and target have the same data representation.
3836
3901
            fetch_spec=None):
3837
3902
        """See InterRepository.fetch()."""
3838
3903
        if fetch_spec is not None:
3839
 
            raise AssertionError("Not implemented yet...")
 
3904
            if (isinstance(fetch_spec, graph.NotInOtherForRevs) and
 
3905
                    len(fetch_spec.required_ids) == 1 and not
 
3906
                    fetch_spec.if_present_ids):
 
3907
                revision_id = list(fetch_spec.required_ids)[0]
 
3908
                del fetch_spec
 
3909
            else:
 
3910
                raise AssertionError("Not implemented yet...")
3840
3911
        ui.ui_factory.warn_experimental_format_fetch(self)
3841
3912
        if (not self.source.supports_rich_root()
3842
3913
            and self.target.supports_rich_root()):
3849
3920
            ui.ui_factory.show_user_warning('cross_format_fetch',
3850
3921
                from_format=self.source._format,
3851
3922
                to_format=self.target._format)
 
3923
        if revision_id:
 
3924
            search_revision_ids = [revision_id]
 
3925
        else:
 
3926
            search_revision_ids = None
3852
3927
        revision_ids = self.target.search_missing_revision_ids(self.source,
3853
 
            revision_id, find_ghosts=find_ghosts).get_keys()
 
3928
            revision_ids=search_revision_ids, find_ghosts=find_ghosts).get_keys()
3854
3929
        if not revision_ids:
3855
3930
            return 0, 0
3856
3931
        revision_ids = tsort.topo_sort(