~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to cbranch.py

  • Committer: Aaron Bentley
  • Date: 2008-03-20 15:36:35 UTC
  • Revision ID: aaron@aaronbentley.com-20080320153635-ywgk5968qpopub9y
cbranch creates parent directories as needed

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 import ui
18
19
from bzrlib.bzrdir import BzrDir
19
20
from bzrlib.branch import Branch
20
21
from bzrlib.config import LocationConfig
21
 
from bzrlib.errors import BzrCommandError
 
22
from bzrlib.errors import BzrCommandError, NoSuchFile
22
23
from bzrlib.osutils import pathjoin, basename, abspath
 
24
from bzrlib.transport import get_transport
23
25
from bzrlib.workingtree import WorkingTree
24
 
from bzrlib import ui
25
26
from bzrlib.urlutils import derive_to_location
26
27
 
27
28
def cbranch(from_location, to_location=None, revision=None,
45
46
        revision_id = revision[0].in_history(old_branch)[1]
46
47
    else:
47
48
        raise BzrCommandError('At most one revision may be supplied.')
 
49
    b_transport = get_transport(b_loc)
 
50
    ensure_base_recursive(b_transport.clone('..'))
48
51
    pb = ui.ui_factory.nested_progress_bar()
49
52
    try:
50
53
        pb.update('Creating branch', 0, 2)
56
59
                                   hardlink=hardlink)
57
60
    finally:
58
61
        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)