/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/branch.py

  • Committer: Jelmer Vernooij
  • Date: 2011-05-18 10:24:05 UTC
  • mfrom: (5889 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5903.
  • Revision ID: jelmer@samba.org-20110518102405-isallt5uet1afh4f
merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
        repository,
36
36
        revision as _mod_revision,
37
37
        rio,
38
 
        symbol_versioning,
39
38
        transport,
40
 
        tsort,
41
39
        ui,
42
40
        urlutils,
43
41
        )
783
781
    def generate_revision_history(self, revision_id, last_rev=None,
784
782
                                  other_branch=None):
785
783
        """See Branch.generate_revision_history"""
786
 
        # FIXME: This shouldn't have to fetch the entire history
787
 
        history = self._lefthand_history(revision_id, last_rev, other_branch)
788
 
        revno = len(history)
 
784
        graph = self.repository.get_graph()
 
785
        known_revision_ids = [
 
786
            self.last_revision_info(),
 
787
            (_mod_revision.NULL_REVISION, 0),
 
788
            ]
 
789
        if last_rev is not None:
 
790
            if not graph.is_ancestor(last_rev, revision_id):
 
791
                # our previous tip is not merged into stop_revision
 
792
                raise errors.DivergedBranches(self, other_branch)
 
793
        revno = graph.find_distance_to_null(revision_id, known_revision_ids)
789
794
        self.set_last_revision_info(revno, revision_id)
790
 
        self._cache_revision_history(history)
791
795
 
792
796
    @needs_write_lock
793
797
    def set_parent(self, url):
1099
1103
            stop_revision=stop_revision,
1100
1104
            possible_transports=possible_transports, *args, **kwargs)
1101
1105
 
1102
 
    def push(self, target, overwrite=False, stop_revision=None, *args,
1103
 
        **kwargs):
 
1106
    def push(self, target, overwrite=False, stop_revision=None, lossy=False,
 
1107
            *args, **kwargs):
1104
1108
        """Mirror this branch into target.
1105
1109
 
1106
1110
        This branch is considered to be 'local', having low latency.
1107
1111
        """
1108
1112
        return InterBranch.get(self, target).push(overwrite, stop_revision,
1109
 
            *args, **kwargs)
1110
 
 
1111
 
    def lossy_push(self, target, stop_revision=None):
1112
 
        """Push deltas into another branch.
1113
 
 
1114
 
        :note: This does not, like push, retain the revision ids from 
1115
 
            the source branch and will, rather than adding bzr-specific 
1116
 
            metadata, push only those semantics of the revision that can be 
1117
 
            natively represented by this branch' VCS.
1118
 
 
1119
 
        :param target: Target branch
1120
 
        :param stop_revision: Revision to push, defaults to last revision.
1121
 
        :return: BranchPushResult with an extra member revidmap: 
1122
 
            A dictionary mapping revision ids from the target branch 
1123
 
            to new revision ids in the target branch, for each 
1124
 
            revision that was pushed.
1125
 
        """
1126
 
        inter = InterBranch.get(self, target)
1127
 
        lossy_push = getattr(inter, "lossy_push", None)
1128
 
        if lossy_push is None:
1129
 
            raise errors.LossyPushToSameVCS(self, target)
1130
 
        return lossy_push(stop_revision)
 
1113
            lossy, *args, **kwargs)
1131
1114
 
1132
1115
    def basis_tree(self):
1133
1116
        """Return `Tree` object for last revision."""
2809
2792
        self._reference_info = None
2810
2793
 
2811
2794
    def _check_history_violation(self, revision_id):
2812
 
        last_revision = _mod_revision.ensure_null(self.last_revision())
 
2795
        current_revid = self.last_revision()
 
2796
        last_revision = _mod_revision.ensure_null(current_revid)
2813
2797
        if _mod_revision.is_null(last_revision):
2814
2798
            return
2815
 
        if last_revision not in self._lefthand_history(revision_id):
2816
 
            raise errors.AppendRevisionsOnlyViolation(self.user_url)
 
2799
        graph = self.repository.get_graph()
 
2800
        for lh_ancestor in graph.iter_lefthand_ancestry(revision_id):
 
2801
            if lh_ancestor == current_revid:
 
2802
                return
 
2803
        raise errors.AppendRevisionsOnlyViolation(self.user_url)
2817
2804
 
2818
2805
    def _gen_revision_history(self):
2819
2806
        """Generate the revision history from last revision
3244
3231
        raise NotImplementedError(self.pull)
3245
3232
 
3246
3233
    @needs_write_lock
3247
 
    def push(self, overwrite=False, stop_revision=None,
 
3234
    def push(self, overwrite=False, stop_revision=None, lossy=False,
3248
3235
             _override_hook_source_branch=None):
3249
3236
        """Mirror the source branch into the target branch.
3250
3237
 
3401
3388
            if master_branch:
3402
3389
                master_branch.unlock()
3403
3390
 
3404
 
    def push(self, overwrite=False, stop_revision=None,
 
3391
    def push(self, overwrite=False, stop_revision=None, lossy=False,
3405
3392
             _override_hook_source_branch=None):
3406
3393
        """See InterBranch.push.
3407
3394
 
3412
3399
        This is for use of RemoteBranch, where push is delegated to the
3413
3400
        underlying vfs-based Branch.
3414
3401
        """
 
3402
        if lossy:
 
3403
            raise errors.LossyPushToSameVCS(self.source, self.target)
3415
3404
        # TODO: Public option to disable running hooks - should be trivial but
3416
3405
        # needs tests.
3417
3406
        self.source.lock_read()
3418
3407
        try:
3419
3408
            return _run_with_write_locked_target(
3420
3409
                self.target, self._push_with_bound_branches, overwrite,
3421
 
                stop_revision,
 
3410
                stop_revision, 
3422
3411
                _override_hook_source_branch=_override_hook_source_branch)
3423
3412
        finally:
3424
3413
            self.source.unlock()