~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2005-09-29 02:55:34 UTC
  • mfrom: (1185.1.47)
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050929025534-1782933743abbfd5
update with integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from bzrlib.osutils import isdir, quotefn, compact_date, rand_bytes, \
24
24
     rename, splitpath, sha_file, appendpath, file_kind
25
25
 
 
26
from bzrlib.store import copy_all
26
27
from bzrlib.errors import BzrError, InvalidRevisionNumber, InvalidRevisionId, \
27
 
     DivergedBranches, NotBranchError
 
28
     DivergedBranches, NotBranchError, UnlistableStore, UnlistableBranch
28
29
from bzrlib.textui import show_status
29
 
from bzrlib.revision import Revision
 
30
from bzrlib.revision import Revision, is_ancestor
30
31
from bzrlib.delta import compare_trees
31
32
from bzrlib.tree import EmptyTree, RevisionTree
32
33
import bzrlib.xml
819
820
                                                         other_revision, self)
820
821
                assert self.last_patch() not in revision_ids
821
822
            except bzrlib.errors.NotAncestor:
822
 
                raise e
823
 
 
 
823
                if is_ancestor(self.last_patch(), other_revision, self):
 
824
                    revision_ids = []
 
825
                else:
 
826
                    raise e
824
827
        self.append_revision(*revision_ids)
825
828
        pb.clear()
826
829
 
1317
1320
    return gen_file_id('TREE_ROOT')
1318
1321
 
1319
1322
 
1320
 
def copy_branch(branch_from, to_location, revno=None):
 
1323
def copy_branch(branch_from, to_location, revno=None, basis_branch=None):
1321
1324
    """Copy branch_from into the existing directory to_location.
1322
1325
 
1323
1326
    revision
1326
1329
 
1327
1330
    to_location
1328
1331
        The name of a local directory that exists but is empty.
 
1332
 
 
1333
    revno
 
1334
        The revision to copy up to
 
1335
 
 
1336
    basis_branch
 
1337
        A local branch to copy revisions from, related to branch_from
1329
1338
    """
1330
1339
    from bzrlib.merge import merge
1331
1340
 
1333
1342
    assert isinstance(to_location, basestring)
1334
1343
    
1335
1344
    br_to = Branch.initialize(to_location)
 
1345
    if basis_branch is not None:
 
1346
        copy_stores(basis_branch, br_to)
1336
1347
    br_to.set_root_id(branch_from.get_root_id())
1337
1348
    if revno is None:
1338
1349
        revno = branch_from.revno()
1341
1352
          check_clean=False, ignore_zero=True)
1342
1353
    br_to.set_parent(branch_from.base)
1343
1354
    return br_to
 
1355
 
 
1356
def copy_stores(branch_from, branch_to):
 
1357
    """Copies all entries from branch stores to another branch's stores.
 
1358
    """
 
1359
    store_pairs = ((branch_from.text_store,      branch_to.text_store),
 
1360
                   (branch_from.inventory_store, branch_to.inventory_store),
 
1361
                   (branch_from.revision_store,  branch_to.revision_store))
 
1362
    try:
 
1363
        for from_store, to_store in store_pairs: 
 
1364
            copy_all(from_store, to_store)
 
1365
    except UnlistableStore:
 
1366
        raise UnlistableBranch(from_store)