~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2005-09-28 09:35:50 UTC
  • mfrom: (1185.1.47)
  • Revision ID: robertc@robertcollins.net-20050928093550-3ca194dfaffc79f1
merge from integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
                            file_kind)
29
29
from bzrlib.errors import (BzrError, InvalidRevisionNumber, InvalidRevisionId,
30
30
                           NoSuchRevision, HistoryMissing, NotBranchError,
31
 
                           DivergedBranches, LockError)
 
31
                           DivergedBranches, LockError, UnlistableStore,
 
32
                           UnlistableBranch)
32
33
from bzrlib.textui import show_status
33
 
from bzrlib.revision import Revision, validate_revision_id
 
34
from bzrlib.revision import Revision, validate_revision_id, is_ancestor
34
35
from bzrlib.delta import compare_trees
35
36
from bzrlib.tree import EmptyTree, RevisionTree
36
37
from bzrlib.inventory import Inventory
37
38
from bzrlib.weavestore import WeaveStore
38
 
from bzrlib.store import ImmutableStore
 
39
from bzrlib.store import copy_all, ImmutableStore
39
40
import bzrlib.xml5
40
41
import bzrlib.ui
41
42
 
197
198
    # This should match a prefix with a function which accepts
198
199
    REVISION_NAMESPACES = {}
199
200
 
 
201
    def push_stores(self, branch_to):
 
202
        """Copy the content of this branches store to branch_to."""
 
203
        if (self._branch_format != branch_to._branch_format
 
204
            or self._branch_format != 4):
 
205
            from bzrlib.fetch import greedy_fetch
 
206
            mutter("falling back to fetch logic to push between %s and %s",
 
207
                   self, branch_to)
 
208
            greedy_fetch(to_branch=branch_to, from_branch=self,
 
209
                         revision=self.last_revision())
 
210
            return
 
211
 
 
212
        store_pairs = ((self.text_store,      branch_to.text_store),
 
213
                       (self.inventory_store, branch_to.inventory_store),
 
214
                       (self.revision_store,  branch_to.revision_store))
 
215
        try:
 
216
            for from_store, to_store in store_pairs: 
 
217
                copy_all(from_store, to_store)
 
218
        except UnlistableStore:
 
219
            raise UnlistableBranch(from_store)
 
220
 
200
221
    def __init__(self, base, init=False, find_root=True,
201
222
                 relax_version_check=False):
202
223
        """Create new branch object at a particular location.
881
902
                         revision=pullable_revs[-1])
882
903
            self.append_revision(*pullable_revs)
883
904
    
 
905
 
884
906
    def commit(self, *args, **kw):
885
907
        from bzrlib.commit import Commit
886
908
        Commit().commit(self, *args, **kw)
1317
1339
    return gen_file_id('TREE_ROOT')
1318
1340
 
1319
1341
 
1320
 
def copy_branch(branch_from, to_location, revision=None):
 
1342
def copy_branch(branch_from, to_location, revision=None, basis_branch=None):
1321
1343
    """Copy branch_from into the existing directory to_location.
1322
1344
 
1323
1345
    revision
1327
1349
 
1328
1350
    to_location
1329
1351
        The name of a local directory that exists but is empty.
 
1352
 
 
1353
    revno
 
1354
        The revision to copy up to
 
1355
 
 
1356
    basis_branch
 
1357
        A local branch to copy revisions from, related to branch_from
1330
1358
    """
1331
1359
    # TODO: This could be done *much* more efficiently by just copying
1332
1360
    # all the whole weaves and revisions, rather than getting one
1337
1365
    assert isinstance(to_location, basestring)
1338
1366
    
1339
1367
    br_to = Branch.initialize(to_location)
 
1368
    if basis_branch is not None:
 
1369
        basis_branch.push_stores(br_to)
1340
1370
    br_to.set_root_id(branch_from.get_root_id())
1341
1371
    if revision is None:
1342
1372
        revision = branch_from.last_revision()