~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

Merge in InterRepository api to have it available.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
from bzrlib.trace import mutter, note
58
58
from bzrlib.tree import EmptyTree, RevisionTree
59
59
from bzrlib.repository import Repository
60
 
from bzrlib.revision import (Revision, is_ancestor, get_intervening_revisions)
 
60
from bzrlib.revision import (
 
61
                             get_intervening_revisions,
 
62
                             is_ancestor,
 
63
                             NULL_REVISION,
 
64
                             Revision,
 
65
                             )
61
66
from bzrlib.store import copy_all
62
67
from bzrlib.symbol_versioning import *
63
68
import bzrlib.transactions as transactions
190
195
        """
191
196
        raise NotImplementedError('abspath is abstract')
192
197
 
 
198
    @needs_write_lock
 
199
    def fetch(self, from_branch, last_revision=None, pb=None):
 
200
        """Copy revisions from from_branch into this branch.
 
201
 
 
202
        :param from_branch: Where to copy from.
 
203
        :param last_revision: What revision to stop at (None for at the end
 
204
                              of the branch.
 
205
        :param pb: An optional progress bar to use.
 
206
 
 
207
        Returns the copied revision count and the failed revisions in a tuple:
 
208
        (copied, failures).
 
209
        """
 
210
        if self.base == from_branch.base:
 
211
            raise Exception("can't fetch from a branch to itself %s, %s" % 
 
212
                            (self.base, to_branch.base))
 
213
        if pb is None:
 
214
            pb = bzrlib.ui.ui_factory.progress_bar()
 
215
 
 
216
        from_branch.lock_read()
 
217
        try:
 
218
            if last_revision is None:
 
219
                pb.update('get source history')
 
220
                from_history = from_branch.revision_history()
 
221
                if from_history:
 
222
                    last_revision = from_history[-1]
 
223
                else:
 
224
                    # no history in the source branch
 
225
                    last_revision = NULL_REVISION
 
226
            return self.repository.fetch(from_branch.repository,
 
227
                                         revision_id=last_revision,
 
228
                                         pb=pb)
 
229
        finally:
 
230
            from_branch.unlock()
 
231
 
193
232
    def get_root_id(self):
194
233
        """Return the id of this branches root"""
195
234
        raise NotImplementedError('get_root_id is abstract')
940
979
 
941
980
    def update_revisions(self, other, stop_revision=None):
942
981
        """See Branch.update_revisions."""
943
 
        from bzrlib.fetch import greedy_fetch
944
 
 
945
982
        if stop_revision is None:
946
983
            stop_revision = other.last_revision()
947
984
        ### Should this be checking is_ancestor instead of revision_history?
948
985
        if (stop_revision is not None and 
949
986
            stop_revision in self.revision_history()):
950
987
            return
951
 
        greedy_fetch(to_branch=self, from_branch=other,
952
 
                     revision=stop_revision)
 
988
        self.fetch(other, stop_revision)
953
989
        pullable_revs = self.pullable_revisions(other, stop_revision)
954
990
        if len(pullable_revs) > 0:
955
991
            self.append_revision(*pullable_revs)