~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

Merge bzr.dev and tree-file-ids-as-tuples.

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):
 
87
    """Return location of branch for this control dir."""
 
88
    try:
 
89
        this_branch = control_dir.open_branch()
 
90
        # This may be a heavy checkout, where we want the master branch
 
91
        master_location = this_branch.get_bound_location()
 
92
        if master_location is not None:
 
93
            return master_location
 
94
        # If not, use a local sibling
 
95
        return this_branch.base
 
96
    except errors.NotBranchError:
 
97
        format = control_dir.find_branch_format()
 
98
        if getattr(format, 'get_reference', None) is not None:
 
99
            return format.get_reference(control_dir)
 
100
        else:
 
101
            return control_dir.root_transport.base
 
102
 
 
103
 
 
104
def lookup_new_sibling_branch(control_dir, location):
 
105
    """Lookup the location for a new sibling branch.
 
106
 
 
107
    :param control_dir: Control directory relative to which to look up
 
108
        the name.
 
109
    :param location: Name of the new branch
 
110
    :return: Full location to the new branch
 
111
    """
 
112
    location = directory_service.directories.dereference(location)
 
113
    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
 
124
 
 
125
        if colocated:
 
126
            return urlutils.join_segment_parameters(this_url,
 
127
                {"branch": urlutils.escape(location)})
 
128
        else:
 
129
            return urlutils.join(this_url, '..', urlutils.escape(location))
 
130
    return location
 
131
 
 
132
 
 
133
def lookup_sibling_branch(control_dir, location):
 
134
    """Lookup sibling branch.
 
135
    
 
136
    :param control_dir: Control directory relative to which to lookup the
 
137
        location.
 
138
    :param location: Location to look up
 
139
    :return: branch to open
 
140
    """
 
141
    try:
 
142
        # Perhaps it's a colocated branch?
 
143
        return control_dir.open_branch(location)
 
144
    except (errors.NotBranchError, errors.NoColocatedBranchSupport):
 
145
        try:
 
146
            return Branch.open(location)
 
147
        except errors.NotBranchError:
 
148
            this_url = _get_branch_location(control_dir)
 
149
            return Branch.open(
 
150
                urlutils.join(
 
151
                    this_url, '..', urlutils.escape(location)))
 
152
 
 
153
 
86
154
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
87
155
def tree_files(file_list, default_branch=u'.', canonicalize=True,
88
156
    apply_view=True):
945
1013
                from_id = tree.path2id(
946
1014
                            tree.get_canonical_inventory_path(rel_names[0]))
947
1015
                if (not osutils.lexists(names_list[0]) and
948
 
                    from_id and tree.kind(from_id) == "directory"):
 
1016
                    from_id and tree.stored_kind(from_id) == "directory"):
949
1017
                    into_existing = False
950
1018
        # move/rename
951
1019
        if into_existing:
1393
1461
                    from_location, revision)
1394
1462
                raise errors.BzrCommandError(msg)
1395
1463
        else:
 
1464
            try:
 
1465
                to_repo = to_dir.open_repository()
 
1466
            except errors.NoRepositoryPresent:
 
1467
                to_repo = to_dir.create_repository()
 
1468
            to_repo.fetch(br_from.repository, revision_id=revision_id)
1396
1469
            branch = br_from.sprout(to_dir, revision_id=revision_id)
1397
1470
        _merge_tags_if_possible(br_from, branch)
1398
1471
        # If the source branch is stacked, the new branch may
1443
1516
        else:
1444
1517
            dir = controldir.ControlDir.open_containing(location)[0]
1445
1518
            try:
1446
 
                active_branch = dir.open_branch(name=None)
 
1519
                active_branch = dir.open_branch(name="")
1447
1520
            except errors.NotBranchError:
1448
1521
                active_branch = None
1449
1522
            branches = dir.get_branches()
1450
1523
            names = {}
1451
1524
            for name, branch in branches.iteritems():
1452
 
                if name is None:
 
1525
                if name == "":
1453
1526
                    continue
1454
1527
                active = (active_branch is not None and
1455
1528
                          active_branch.base == branch.base)
4166
4239
    Merge will do its best to combine the changes in two branches, but there
4167
4240
    are some kinds of problems only a human can fix.  When it encounters those,
4168
4241
    it will mark a conflict.  A conflict means that you need to fix something,
4169
 
    before you should commit.
 
4242
    before you can commit.
4170
4243
 
4171
4244
    Use bzr resolve when you have fixed a problem.  See also bzr conflicts.
4172
4245
 
6141
6214
            had_explicit_nick = False
6142
6215
        if create_branch:
6143
6216
            if branch is None:
6144
 
                raise errors.BzrCommandError(gettext('cannot create branch without'
6145
 
                                             ' source branch'))
6146
 
            to_location = directory_service.directories.dereference(
6147
 
                              to_location)
6148
 
            if '/' not in to_location and '\\' not in to_location:
6149
 
                # This path is meant to be relative to the existing branch
6150
 
                this_url = self._get_branch_location(control_dir)
6151
 
                # Perhaps the target control dir supports colocated branches?
6152
 
                try:
6153
 
                    root = controldir.ControlDir.open(this_url,
6154
 
                        possible_transports=[control_dir.user_transport])
6155
 
                except errors.NotBranchError:
6156
 
                    colocated = False
6157
 
                else:
6158
 
                    colocated = root._format.colocated_branches
6159
 
                if colocated:
6160
 
                    to_location = urlutils.join_segment_parameters(this_url,
6161
 
                        {"branch": urlutils.escape(to_location)})
6162
 
                else:
6163
 
                    to_location = urlutils.join(
6164
 
                        this_url, '..', urlutils.escape(to_location))
 
6217
                raise errors.BzrCommandError(
 
6218
                    gettext('cannot create branch without source branch'))
 
6219
            to_location = lookup_new_sibling_branch(control_dir, to_location)
6165
6220
            to_branch = branch.bzrdir.sprout(to_location,
6166
 
                                 possible_transports=[branch.bzrdir.root_transport],
6167
 
                                 source_branch=branch).open_branch()
 
6221
                 possible_transports=[branch.bzrdir.root_transport],
 
6222
                 source_branch=branch).open_branch()
6168
6223
        else:
6169
 
            # Perhaps it's a colocated branch?
6170
 
            try:
6171
 
                to_branch = control_dir.open_branch(to_location)
6172
 
            except (errors.NotBranchError, errors.NoColocatedBranchSupport):
6173
 
                try:
6174
 
                    to_branch = Branch.open(to_location)
6175
 
                except errors.NotBranchError:
6176
 
                    this_url = self._get_branch_location(control_dir)
6177
 
                    to_branch = Branch.open(
6178
 
                        urlutils.join(
6179
 
                            this_url, '..', urlutils.escape(to_location)))
 
6224
            to_branch = lookup_sibling_branch(control_dir, to_location)
6180
6225
        if revision is not None:
6181
6226
            revision = revision.as_revision_id(to_branch)
6182
6227
        switch.switch(control_dir, to_branch, force, revision_id=revision)
6186
6231
        note(gettext('Switched to branch: %s'),
6187
6232
            urlutils.unescape_for_display(to_branch.base, 'utf-8'))
6188
6233
 
6189
 
    def _get_branch_location(self, control_dir):
6190
 
        """Return location of branch for this control dir."""
6191
 
        try:
6192
 
            this_branch = control_dir.open_branch()
6193
 
            # This may be a heavy checkout, where we want the master branch
6194
 
            master_location = this_branch.get_bound_location()
6195
 
            if master_location is not None:
6196
 
                return master_location
6197
 
            # If not, use a local sibling
6198
 
            return this_branch.base
6199
 
        except errors.NotBranchError:
6200
 
            format = control_dir.find_branch_format()
6201
 
            if getattr(format, 'get_reference', None) is not None:
6202
 
                return format.get_reference(control_dir)
6203
 
            else:
6204
 
                return control_dir.root_transport.base
6205
6234
 
6206
6235
 
6207
6236
class cmd_view(Command):