~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Patch Queue Manager
  • Date: 2012-01-28 13:24:39 UTC
  • mfrom: (6450.1.1 bzr.dev)
  • Revision ID: pqm@pqm.ubuntu.com-20120128132439-phvlss4cq7bf5rji
(jelmer) Merge the 2.5 branch. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
    )
84
84
 
85
85
 
86
 
def _get_branch_location(control_dir):
 
86
def _get_branch_location(control_dir, possible_transports=None):
87
87
    """Return location of branch for this control dir."""
88
88
    try:
89
 
        this_branch = control_dir.open_branch()
 
89
        this_branch = control_dir.open_branch(
 
90
            possible_transports=possible_transports)
90
91
        # This may be a heavy checkout, where we want the master branch
91
92
        master_location = this_branch.get_bound_location()
92
93
        if master_location is not None:
101
102
            return control_dir.root_transport.base
102
103
 
103
104
 
104
 
def lookup_new_sibling_branch(control_dir, location):
 
105
def _is_colocated(control_dir, possible_transports=None):
 
106
    """Check if the branch in control_dir is colocated.
 
107
 
 
108
    :param control_dir: Control directory
 
109
    :return: Boolean indicating whether 
 
110
    """
 
111
    # This path is meant to be relative to the existing branch
 
112
    this_url = _get_branch_location(control_dir,
 
113
        possible_transports=possible_transports)
 
114
    # Perhaps the target control dir supports colocated branches?
 
115
    try:
 
116
        root = controldir.ControlDir.open(this_url,
 
117
            possible_transports=possible_transports)
 
118
    except errors.NotBranchError:
 
119
        return (False, this_url)
 
120
    else:
 
121
        try:
 
122
            wt = control_dir.open_workingtree()
 
123
        except (errors.NoWorkingTree, errors.NotLocalUrl):
 
124
            return (False, this_url)
 
125
        else:
 
126
            return (
 
127
                root._format.colocated_branches and
 
128
                control_dir.control_url == root.control_url,
 
129
                this_url)
 
130
 
 
131
 
 
132
def lookup_new_sibling_branch(control_dir, location, possible_transports=None):
105
133
    """Lookup the location for a new sibling branch.
106
134
 
107
135
    :param control_dir: Control directory relative to which to look up
111
139
    """
112
140
    location = directory_service.directories.dereference(location)
113
141
    if '/' not in location and '\\' not in location:
114
 
        # This path is meant to be relative to the existing branch
115
 
        this_url = _get_branch_location(control_dir)
116
 
        # Perhaps the target control dir supports colocated branches?
117
 
        try:
118
 
            root = controldir.ControlDir.open(this_url,
119
 
                possible_transports=[control_dir.user_transport])
120
 
        except errors.NotBranchError:
121
 
            colocated = False
122
 
        else:
123
 
            colocated = root._format.colocated_branches
 
142
        (colocated, this_url) = _is_colocated(control_dir, possible_transports)
124
143
 
125
144
        if colocated:
126
145
            return urlutils.join_segment_parameters(this_url,
130
149
    return location
131
150
 
132
151
 
133
 
def lookup_sibling_branch(control_dir, location):
 
152
def lookup_sibling_branch(control_dir, location, possible_transports=None):
134
153
    """Lookup sibling branch.
135
154
    
136
155
    :param control_dir: Control directory relative to which to lookup the
140
159
    """
141
160
    try:
142
161
        # Perhaps it's a colocated branch?
143
 
        return control_dir.open_branch(location)
 
162
        return control_dir.open_branch(location, 
 
163
            possible_transports=possible_transports)
144
164
    except (errors.NotBranchError, errors.NoColocatedBranchSupport):
145
165
        try:
146
166
            return Branch.open(location)
1415
1435
            revision_id = br_from.last_revision()
1416
1436
        if to_location is None:
1417
1437
            to_location = getattr(br_from, "name", None)
1418
 
            if to_location is None:
 
1438
            if not to_location:
1419
1439
                to_location = urlutils.derive_to_location(from_location)
1420
1440
        to_transport = transport.get_transport(to_location)
1421
1441
        try:
6199
6219
        from bzrlib import switch
6200
6220
        tree_location = directory
6201
6221
        revision = _get_one_revision('switch', revision)
6202
 
        control_dir = controldir.ControlDir.open_containing(tree_location)[0]
 
6222
        possible_transports = []
 
6223
        control_dir = controldir.ControlDir.open_containing(tree_location,
 
6224
            possible_transports=possible_transports)[0]
6203
6225
        if to_location is None:
6204
6226
            if revision is None:
6205
6227
                raise errors.BzrCommandError(gettext('You must supply either a'
6206
6228
                                             ' revision or a location'))
6207
6229
            to_location = tree_location
6208
6230
        try:
6209
 
            branch = control_dir.open_branch()
 
6231
            branch = control_dir.open_branch(
 
6232
                possible_transports=possible_transports)
6210
6233
            had_explicit_nick = branch.get_config().has_explicit_nickname()
6211
6234
        except errors.NotBranchError:
6212
6235
            branch = None
6215
6238
            if branch is None:
6216
6239
                raise errors.BzrCommandError(
6217
6240
                    gettext('cannot create branch without source branch'))
6218
 
            to_location = lookup_new_sibling_branch(control_dir, to_location)
 
6241
            to_location = lookup_new_sibling_branch(control_dir, to_location,
 
6242
                 possible_transports=possible_transports)
6219
6243
            to_branch = branch.bzrdir.sprout(to_location,
6220
 
                 possible_transports=[branch.bzrdir.root_transport],
 
6244
                 possible_transports=possible_transports,
6221
6245
                 source_branch=branch).open_branch()
6222
6246
        else:
6223
6247
            to_branch = lookup_sibling_branch(control_dir, to_location)