~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2005-08-25 06:02:26 UTC
  • mto: (974.1.50) (1185.1.10) (1092.3.1)
  • mto: This revision was merged to the branch mainline in revision 1139.
  • Revision ID: robertc@robertcollins.net-20050825060226-115adb0093d707ad
pull the important stuff out of cmd_branch.run to branch.copy_branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1405
1405
    """Return a new tree-root file id."""
1406
1406
    return gen_file_id('TREE_ROOT')
1407
1407
 
 
1408
def copy_branch(branch_from, to_location, revision):
 
1409
    """Copy branch_from into the existing directory to_location.
 
1410
 
 
1411
    If revision is not None, the head of the new branch will be revision.
 
1412
    """
 
1413
    from bzrlib.merge import merge
 
1414
    from bzrlib.branch import Branch
 
1415
    from shutil import rmtree
 
1416
    br_to = Branch(to_location, init=True)
 
1417
    br_to.set_root_id(branch_from.get_root_id())
 
1418
    if revision is None:
 
1419
        revno = branch_from.revno()
 
1420
    else:
 
1421
        revno, rev_id = branch_from.get_revision_info(revision)
 
1422
    br_to.update_revisions(branch_from, stop_revision=revno)
 
1423
    merge((to_location, -1), (to_location, 0), this_dir=to_location,
 
1424
          check_clean=False, ignore_zero=True)
 
1425
    from_location = pull_loc(branch_from)
 
1426
    br_to.controlfile("x-pull", "wb").write(from_location + "\n")
 
1427