/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: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

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