~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to cbranch.py

  • Committer: Aaron Bentley
  • Date: 2008-01-23 23:09:27 UTC
  • Revision ID: aaron@aaronbentley.com-20080123230927-7wtn8mvyyuhs5gq3
Remove unneeded imports from dotgraph

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#    along with this program; if not, write to the Free Software
16
16
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
 
from bzrlib.builtins import cmd_branch, cmd_checkout
 
18
from bzrlib.bzrdir import BzrDir
 
19
from bzrlib.branch import Branch
19
20
from bzrlib.config import LocationConfig
20
21
from bzrlib.errors import BzrCommandError
21
 
from bzrlib.osutils import pathjoin, basename, abspath, getcwd
 
22
from bzrlib.osutils import pathjoin, basename, abspath
 
23
from bzrlib.workingtree import WorkingTree
 
24
from bzrlib import ui
 
25
from bzrlib.urlutils import derive_to_location
22
26
 
23
 
def cbranch(from_location, to_location=None, revision=None, lightweight=False):
24
 
    from_location = from_location.rstrip('/')
 
27
def cbranch(from_location, to_location=None, revision=None,
 
28
            lightweight=False, files_from=None):
25
29
    if to_location is None:
26
 
        to_location = pathjoin(getcwd(), basename(from_location))
 
30
        to_location = derive_to_location(from_location)
27
31
    config = LocationConfig(abspath(to_location))
28
 
    b_root = config.get_user_option("cbranch_root")
29
 
    if b_root is None:
30
 
        raise BzrCommandError("Can't find cbranch_root in branches.conf")
31
 
    b_loc = pathjoin(b_root, basename(to_location))
32
 
    cmd_branch().run(from_location, b_loc, revision=revision)
33
 
    cmd_checkout().run(b_loc, to_location, lightweight=lightweight)
 
32
    b_loc = config.get_user_option("cbranch_target")
 
33
    if b_loc is None:
 
34
        b_root = config.get_user_option("cbranch_root")
 
35
        if b_root is None:
 
36
            raise BzrCommandError("Can't find cbranch_target in"
 
37
                                  " locations.conf")
 
38
        b_loc = pathjoin(b_root, basename(to_location))
 
39
    accelerator_tree, old_branch = BzrDir.open_tree_or_branch(from_location)
 
40
    if files_from is not None:
 
41
        accelerator_tree = WorkingTree.open(files_from)
 
42
    if revision is None or len(revision) == 0:
 
43
        revision_id = old_branch.last_revision()
 
44
    elif len(revision) == 1:
 
45
        revision_id = revision[0].in_history(old_branch)[1]
 
46
    else:
 
47
        raise BzrCommandError('At most one revision may be supplied.')
 
48
    pb = ui.ui_factory.nested_progress_bar()
 
49
    try:
 
50
        pb.update('Creating branch', 0, 2)
 
51
        new_branch = old_branch.bzrdir.sprout(b_loc, revision_id,
 
52
            accelerator_tree=accelerator_tree).open_branch()
 
53
        pb.update('Creating checkout', 1, 2)
 
54
        new_branch.create_checkout(to_location, lightweight=lightweight,
 
55
                                   accelerator_tree=accelerator_tree)
 
56
    finally:
 
57
        pb.finished()