~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):
600
613
        self.this_tree.lock_tree_write()
601
614
        self.base_tree.lock_read()
602
615
        self.other_tree.lock_read()
603
 
        self.tt = TreeTransform(self.this_tree, self.pb)
604
616
        try:
605
 
            self.pp.next_phase()
606
 
            self._compute_transform()
607
 
            self.pp.next_phase()
608
 
            results = self.tt.apply(no_conflicts=True)
609
 
            self.write_modified(results)
 
617
            self.tt = TreeTransform(self.this_tree, self.pb)
610
618
            try:
611
 
                self.this_tree.add_conflicts(self.cooked_conflicts)
612
 
            except UnsupportedOperation:
613
 
                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()
614
630
        finally:
615
 
            self.tt.finalize()
616
631
            self.other_tree.unlock()
617
632
            self.base_tree.unlock()
618
633
            self.this_tree.unlock()
1147
1162
                self.tt.delete_contents(trans_id)
1148
1163
            if file_id in self.other_tree:
1149
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
1150
1178
                create_from_tree(self.tt, trans_id,
1151
 
                                 self.other_tree, file_id)
 
1179
                                 self.other_tree, file_id,
 
1180
                                 filter_tree_path=filter_tree_path)
1152
1181
                if not file_in_this:
1153
1182
                    self.tt.version_file(file_id, trans_id)
1154
1183
                return "modified"
1241
1270
                ('THIS', self.this_tree, this_lines)]
1242
1271
        if not no_base:
1243
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
 
1244
1287
        versioned = False
1245
1288
        file_group = []
1246
1289
        for suffix, tree, lines in data:
1247
1290
            if file_id in tree:
1248
1291
                trans_id = self._conflict_file(name, parent_id, tree, file_id,
1249
 
                                               suffix, lines)
 
1292
                                               suffix, lines, filter_tree_path)
1250
1293
                file_group.append(trans_id)
1251
1294
                if set_version and not versioned:
1252
1295
                    self.tt.version_file(file_id, trans_id)
1254
1297
        return file_group
1255
1298
 
1256
1299
    def _conflict_file(self, name, parent_id, tree, file_id, suffix,
1257
 
                       lines=None):
 
1300
                       lines=None, filter_tree_path=None):
1258
1301
        """Emit a single conflict file."""
1259
1302
        name = name + '.' + suffix
1260
1303
        trans_id = self.tt.create_path(name, parent_id)
1261
 
        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)
1262
1306
        return trans_id
1263
1307
 
1264
1308
    def merge_executable(self, file_id, file_status):
1518
1562
    get_revision_id = getattr(base_tree, 'get_revision_id', None)
1519
1563
    if get_revision_id is None:
1520
1564
        get_revision_id = base_tree.last_revision
 
1565
    merger.cache_trees_with_revision_ids([other_tree, base_tree, this_tree])
1521
1566
    merger.set_base_revision(get_revision_id(), this_branch)
1522
1567
    return merger.do_merge()
1523
1568