~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Joe Julian
  • Date: 2010-01-10 02:25:31 UTC
  • mto: (4634.119.7 2.0)
  • mto: This revision was merged to the branch mainline in revision 4959.
  • Revision ID: joe@julianfamily.org-20100110022531-wqk61rsagz8xsiga
Added MANIFEST.in to allow bdist_rpm to have all the required include files and tools. bdist_rpm will still fail to build correctly on some distributions due to a disttools bug http://bugs.python.org/issue644744

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
 
65
65
 
66
66
def transform_tree(from_tree, to_tree, interesting_ids=None):
67
 
    merge_inner(from_tree.branch, to_tree, from_tree, ignore_zero=True,
68
 
                interesting_ids=interesting_ids, this_tree=from_tree)
 
67
    from_tree.lock_tree_write()
 
68
    try:
 
69
        merge_inner(from_tree.branch, to_tree, from_tree, ignore_zero=True,
 
70
                    interesting_ids=interesting_ids, this_tree=from_tree)
 
71
    finally:
 
72
        from_tree.unlock()
69
73
 
70
74
 
71
75
class Merger(object):
102
106
        self._is_criss_cross = None
103
107
        self._lca_trees = None
104
108
 
 
109
    def cache_trees_with_revision_ids(self, trees):
 
110
        """Cache any tree in trees if it has a revision_id."""
 
111
        for maybe_tree in trees:
 
112
            if maybe_tree is None:
 
113
                continue
 
114
            try:
 
115
                rev_id = maybe_tree.get_revision_id()
 
116
            except AttributeError:
 
117
                continue
 
118
            self._cached_trees[rev_id] = maybe_tree
 
119
 
105
120
    @property
106
121
    def revision_graph(self):
107
122
        if self._revision_graph is None:
243
258
 
244
259
        if self.other_rev_id is None:
245
260
            other_basis_tree = self.revision_tree(self.other_basis)
246
 
            changes = other_basis_tree.changes_from(self.other_tree)
247
 
            if changes.has_changed():
 
261
            if other_basis_tree.has_changes(self.other_tree):
248
262
                raise WorkingTreeNotRevision(self.this_tree)
249
263
            other_rev_id = self.other_basis
250
264
            self.other_tree = other_basis_tree
276
290
            basis_tree = self.revision_tree(self.this_tree.last_revision())
277
291
        except errors.NoSuchRevision:
278
292
            basis_tree = self.this_tree.basis_tree()
279
 
        changes = self.this_tree.changes_from(basis_tree)
280
 
        if not changes.has_changed():
 
293
        if not self.this_tree.has_changes(basis_tree):
281
294
            self.this_rev_id = self.this_basis
282
295
 
283
296
    def set_interesting_files(self, file_list):
462
475
                               **kwargs)
463
476
 
464
477
    def _do_merge_to(self, merge):
 
478
        if self.other_branch is not None:
 
479
            self.other_branch.update_references(self.this_branch)
465
480
        merge.do_merge()
466
481
        if self.recurse == 'down':
467
482
            for relpath, file_id in self.this_tree.iter_references():
546
561
        :param working_tree: The working tree to apply the merge to
547
562
        :param this_tree: The local tree in the merge operation
548
563
        :param base_tree: The common tree in the merge operation
549
 
        :param other_tree: The other other tree to merge changes from
 
564
        :param other_tree: The other tree to merge changes from
550
565
        :param interesting_ids: The file_ids of files that should be
551
566
            participate in the merge.  May not be combined with
552
567
            interesting_files.
598
613
        self.this_tree.lock_tree_write()
599
614
        self.base_tree.lock_read()
600
615
        self.other_tree.lock_read()
601
 
        self.tt = TreeTransform(self.this_tree, self.pb)
602
616
        try:
603
 
            self.pp.next_phase()
604
 
            self._compute_transform()
605
 
            self.pp.next_phase()
606
 
            results = self.tt.apply(no_conflicts=True)
607
 
            self.write_modified(results)
 
617
            self.tt = TreeTransform(self.this_tree, self.pb)
608
618
            try:
609
 
                self.this_tree.add_conflicts(self.cooked_conflicts)
610
 
            except UnsupportedOperation:
611
 
                pass
 
619
                self.pp.next_phase()
 
620
                self._compute_transform()
 
621
                self.pp.next_phase()
 
622
                results = self.tt.apply(no_conflicts=True)
 
623
                self.write_modified(results)
 
624
                try:
 
625
                    self.this_tree.add_conflicts(self.cooked_conflicts)
 
626
                except UnsupportedOperation:
 
627
                    pass
 
628
            finally:
 
629
                self.tt.finalize()
612
630
        finally:
613
 
            self.tt.finalize()
614
631
            self.other_tree.unlock()
615
632
            self.base_tree.unlock()
616
633
            self.this_tree.unlock()
1145
1162
                self.tt.delete_contents(trans_id)
1146
1163
            if file_id in self.other_tree:
1147
1164
                # OTHER changed the file
 
1165
                wt = self.this_tree
 
1166
                if wt.supports_content_filtering():
 
1167
                    # We get the path from the working tree if it exists.
 
1168
                    # That fails though when OTHER is adding a file, so
 
1169
                    # we fall back to the other tree to find the path if
 
1170
                    # it doesn't exist locally.
 
1171
                    try:
 
1172
                        filter_tree_path = wt.id2path(file_id)
 
1173
                    except errors.NoSuchId:
 
1174
                        filter_tree_path = self.other_tree.id2path(file_id)
 
1175
                else:
 
1176
                    # Skip the id2path lookup for older formats
 
1177
                    filter_tree_path = None
1148
1178
                create_from_tree(self.tt, trans_id,
1149
 
                                 self.other_tree, file_id)
 
1179
                                 self.other_tree, file_id,
 
1180
                                 filter_tree_path=filter_tree_path)
1150
1181
                if not file_in_this:
1151
1182
                    self.tt.version_file(file_id, trans_id)
1152
1183
                return "modified"
1239
1270
                ('THIS', self.this_tree, this_lines)]
1240
1271
        if not no_base:
1241
1272
            data.append(('BASE', self.base_tree, base_lines))
 
1273
 
 
1274
        # We need to use the actual path in the working tree of the file here,
 
1275
        # ignoring the conflict suffixes
 
1276
        wt = self.this_tree
 
1277
        if wt.supports_content_filtering():
 
1278
            try:
 
1279
                filter_tree_path = wt.id2path(file_id)
 
1280
            except errors.NoSuchId:
 
1281
                # file has been deleted
 
1282
                filter_tree_path = None
 
1283
        else:
 
1284
            # Skip the id2path lookup for older formats
 
1285
            filter_tree_path = None
 
1286
 
1242
1287
        versioned = False
1243
1288
        file_group = []
1244
1289
        for suffix, tree, lines in data:
1245
1290
            if file_id in tree:
1246
1291
                trans_id = self._conflict_file(name, parent_id, tree, file_id,
1247
 
                                               suffix, lines)
 
1292
                                               suffix, lines, filter_tree_path)
1248
1293
                file_group.append(trans_id)
1249
1294
                if set_version and not versioned:
1250
1295
                    self.tt.version_file(file_id, trans_id)
1252
1297
        return file_group
1253
1298
 
1254
1299
    def _conflict_file(self, name, parent_id, tree, file_id, suffix,
1255
 
                       lines=None):
 
1300
                       lines=None, filter_tree_path=None):
1256
1301
        """Emit a single conflict file."""
1257
1302
        name = name + '.' + suffix
1258
1303
        trans_id = self.tt.create_path(name, parent_id)
1259
 
        create_from_tree(self.tt, trans_id, tree, file_id, lines)
 
1304
        create_from_tree(self.tt, trans_id, tree, file_id, lines,
 
1305
            filter_tree_path)
1260
1306
        return trans_id
1261
1307
 
1262
1308
    def merge_executable(self, file_id, file_status):
1516
1562
    get_revision_id = getattr(base_tree, 'get_revision_id', None)
1517
1563
    if get_revision_id is None:
1518
1564
        get_revision_id = base_tree.last_revision
 
1565
    merger.cache_trees_with_revision_ids([other_tree, base_tree, this_tree])
1519
1566
    merger.set_base_revision(get_revision_id(), this_branch)
1520
1567
    return merger.do_merge()
1521
1568