/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/merge.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-07-28 02:47:10 UTC
  • mfrom: (7519.1.1 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200728024710-a2ylds219f1lsl62
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/388173

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from __future__ import absolute_import
 
17
import contextlib
18
18
 
19
19
from .lazy_import import lazy_import
20
20
lazy_import(globals(), """
22
22
 
23
23
from breezy import (
24
24
    branch as _mod_branch,
25
 
    cleanup,
26
25
    conflicts as _mod_conflicts,
27
26
    debug,
28
27
    graph as _mod_graph,
31
30
    revision as _mod_revision,
32
31
    textfile,
33
32
    trace,
34
 
    transform,
35
33
    tree as _mod_tree,
36
34
    tsort,
37
35
    ui,
48
46
    errors,
49
47
    hooks,
50
48
    registry,
51
 
    )
52
 
from .sixish import (
53
 
    viewitems,
 
49
    transform,
54
50
    )
55
51
# TODO: Report back as changes are merged in
56
52
 
447
443
    def _add_parent(self):
448
444
        new_parents = self.this_tree.get_parent_ids() + [self.other_rev_id]
449
445
        new_parent_trees = []
450
 
        with cleanup.ExitStack() as stack:
 
446
        with contextlib.ExitStack() as stack:
451
447
            for revision_id in new_parents:
452
448
                try:
453
449
                    tree = self.revision_tree(revision_id)
654
650
        return merge
655
651
 
656
652
    def do_merge(self):
657
 
        with cleanup.ExitStack() as stack:
 
653
        with contextlib.ExitStack() as stack:
658
654
            stack.enter_context(self.this_tree.lock_tree_write())
659
655
            if self.base_tree is not None:
660
656
                stack.enter_context(self.base_tree.lock_read())
757
753
            self.do_merge()
758
754
 
759
755
    def do_merge(self):
760
 
        with cleanup.ExitStack() as stack:
 
756
        with contextlib.ExitStack() as stack:
761
757
            stack.enter_context(self.working_tree.lock_tree_write())
762
758
            stack.enter_context(self.this_tree.lock_read())
763
759
            stack.enter_context(self.base_tree.lock_read())
764
760
            stack.enter_context(self.other_tree.lock_read())
765
 
            self.tt = self.working_tree.get_transform()
 
761
            self.tt = self.working_tree.transform()
766
762
            stack.enter_context(self.tt)
767
763
            self._compute_transform()
768
764
            results = self.tt.apply(no_conflicts=True)
774
770
 
775
771
    def make_preview_transform(self):
776
772
        with self.base_tree.lock_read(), self.other_tree.lock_read():
777
 
            self.tt = transform.TransformPreview(self.working_tree)
 
773
            self.tt = self.working_tree.preview_transform()
778
774
            self._compute_transform()
779
775
            return self.tt
780
776
 
781
777
    def _compute_transform(self):
782
778
        if self._lca_trees is None:
783
 
            entries = self._entries3()
 
779
            entries = list(self._entries3())
784
780
            resolver = self._three_way
785
781
        else:
786
 
            entries = self._entries_lca()
 
782
            entries = list(self._entries_lca())
787
783
            resolver = self._lca_multi_way
788
784
        # Prepare merge hooks
789
785
        factories = Merger.hooks['merge_file_content']
794
790
            for num, (file_id, changed, paths3, parents3, names3,
795
791
                      executable3) in enumerate(entries):
796
792
                trans_id = self.tt.trans_id_file_id(file_id)
797
 
 
798
793
                # Try merging each entry
799
794
                child_pb.update(gettext('Preparing file merge'),
800
795
                                num, len(entries))
835
830
        other and this.  names3 is a tuple of names for base, other and this.
836
831
        executable3 is a tuple of execute-bit values for base, other and this.
837
832
        """
838
 
        result = []
839
833
        iterator = self.other_tree.iter_changes(self.base_tree,
840
834
                                                specific_files=self.interesting_files,
841
835
                                                extra_trees=[self.this_tree])
863
857
            names3 = change.name + (this_name,)
864
858
            paths3 = change.path + (this_path, )
865
859
            executable3 = change.executable + (this_executable,)
866
 
            result.append(
 
860
            yield (
867
861
                (change.file_id, change.changed_content, paths3,
868
862
                 parents3, names3, executable3))
869
 
        return result
870
863
 
871
864
    def _entries_lca(self):
872
865
        """Gather data about files modified between multiple trees.
895
888
                self.interesting_files, lookup_trees)
896
889
        else:
897
890
            interesting_files = None
898
 
        result = []
899
891
        from .multiwalker import MultiWalker
900
892
        walker = MultiWalker(self.other_tree, self._lca_trees)
901
893
 
1039
1031
                    raise AssertionError('unhandled kind: %s' % other_ie.kind)
1040
1032
 
1041
1033
            # If we have gotten this far, that means something has changed
1042
 
            result.append((file_id, content_changed,
 
1034
            yield (file_id, content_changed,
1043
1035
                           ((base_path, lca_paths),
1044
1036
                            other_path, this_path),
1045
1037
                           ((base_ie.parent_id, lca_parent_ids),
1048
1040
                            other_ie.name, this_ie.name),
1049
1041
                           ((base_ie.executable, lca_executable),
1050
1042
                            other_ie.executable, this_ie.executable)
1051
 
                           ))
1052
 
        return result
 
1043
                           )
1053
1044
 
1054
1045
    def write_modified(self, results):
1055
1046
        if not self.working_tree.supports_merge_modified():
1288
1279
                    keep_this = True
1289
1280
                    # versioning the merged file will trigger a duplicate
1290
1281
                    # conflict
1291
 
                    self.tt.version_file(file_id, trans_id)
 
1282
                    self.tt.version_file(trans_id, file_id=file_id)
1292
1283
                    transform.create_from_tree(
1293
1284
                        self.tt, trans_id, self.other_tree,
1294
1285
                        other_path,
1335
1326
        else:
1336
1327
            raise AssertionError('unknown hook_status: %r' % (hook_status,))
1337
1328
        if not this_path and result == "modified":
1338
 
            self.tt.version_file(file_id, trans_id)
 
1329
            self.tt.version_file(trans_id, file_id=file_id)
1339
1330
        if not keep_this:
1340
1331
            # The merge has been performed and produced a new content, so the
1341
1332
            # old contents should not be retained.
1465
1456
            data.append(('BASE', self.base_tree, base_path, base_lines))
1466
1457
 
1467
1458
        # We need to use the actual path in the working tree of the file here,
1468
 
        # ignoring the conflict suffixes
1469
 
        wt = self.this_tree
1470
 
        if wt.supports_content_filtering():
1471
 
            try:
1472
 
                filter_tree_path = wt.id2path(file_id)
1473
 
            except errors.NoSuchId:
1474
 
                # file has been deleted
1475
 
                filter_tree_path = None
 
1459
        if self.this_tree.supports_content_filtering():
 
1460
            filter_tree_path = this_path
1476
1461
        else:
1477
1462
            # Skip the id2path lookup for older formats
1478
1463
            filter_tree_path = None
1486
1471
                    filter_tree_path)
1487
1472
                file_group.append(trans_id)
1488
1473
                if set_version and not versioned:
1489
 
                    self.tt.version_file(file_id, trans_id)
 
1474
                    self.tt.version_file(trans_id, file_id=file_id)
1490
1475
                    versioned = True
1491
1476
        return file_group
1492
1477
 
2255
2240
        filtered_parent_map = {}
2256
2241
        child_map = {}
2257
2242
        tails = []
2258
 
        for key, parent_keys in viewitems(parent_map):
 
2243
        for key, parent_keys in parent_map.items():
2259
2244
            culled_parent_keys = [p for p in parent_keys if p in parent_map]
2260
2245
            if not culled_parent_keys:
2261
2246
                tails.append(key)