~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to cbranch.py

  • Committer: Aaron Bentley
  • Date: 2007-12-21 04:23:49 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20071221042349-9sfpmuzu1g1rdshe
Rename from-files to files-from, to match bzr proper

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2008 Aaron Bentley
2
 
# <aaron@aaronbentley.com>
 
1
# Copyright (C) 2006 Aaron Bentley
 
2
# <aaron.bentley@utoronto.ca>
3
3
#
4
4
#    This program is free software; you can redistribute it and/or modify
5
5
#    it under the terms of the GNU General Public License as published by
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 import ui
19
18
from bzrlib.bzrdir import BzrDir
20
19
from bzrlib.branch import Branch
21
20
from bzrlib.config import LocationConfig
22
 
from bzrlib.errors import BzrCommandError, NoSuchFile
 
21
from bzrlib.errors import BzrCommandError
23
22
from bzrlib.osutils import pathjoin, basename, abspath
24
 
from bzrlib.transport import get_transport
25
23
from bzrlib.workingtree import WorkingTree
 
24
from bzrlib import ui
26
25
from bzrlib.urlutils import derive_to_location
27
26
 
28
27
def cbranch(from_location, to_location=None, revision=None,
29
 
            lightweight=False, files_from=None, hardlink=False):
 
28
            lightweight=False, files_from=None):
30
29
    if to_location is None:
31
30
        to_location = derive_to_location(from_location)
32
31
    config = LocationConfig(abspath(to_location))
46
45
        revision_id = revision[0].in_history(old_branch)[1]
47
46
    else:
48
47
        raise BzrCommandError('At most one revision may be supplied.')
49
 
    b_transport = get_transport(b_loc)
50
 
    ensure_base_recursive(b_transport.clone('..'))
51
48
    pb = ui.ui_factory.nested_progress_bar()
52
49
    try:
53
50
        pb.update('Creating branch', 0, 2)
55
52
            accelerator_tree=accelerator_tree).open_branch()
56
53
        pb.update('Creating checkout', 1, 2)
57
54
        new_branch.create_checkout(to_location, lightweight=lightweight,
58
 
                                   accelerator_tree=accelerator_tree,
59
 
                                   hardlink=hardlink)
 
55
                                   accelerator_tree=accelerator_tree)
60
56
    finally:
61
57
        pb.finished()
62
 
 
63
 
 
64
 
def ensure_base_recursive(transport):
65
 
    """Ensure that the transport base and any its parents exist"""
66
 
    pending_transports = [transport]
67
 
    while len(pending_transports) > 0:
68
 
        transport = pending_transports.pop()
69
 
        try:
70
 
            transport.ensure_base()
71
 
        except NoSuchFile, e:
72
 
            pending_transports.append(transport)
73
 
            parent = transport.clone('..')
74
 
            if parent.base == transport.base:
75
 
                raise e
76
 
            pending_transports.append(parent)