~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

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
 
18
 
17
19
import warnings
18
20
 
19
21
from bzrlib.lazy_import import lazy_import
44
46
    decorators,
45
47
    errors,
46
48
    hooks,
 
49
    registry,
47
50
    )
48
51
from bzrlib.symbol_versioning import (
49
52
    deprecated_in,
75
78
            "See the AbstractPerFileMerger API docs for details on how it is "
76
79
            "used by merge.",
77
80
            (2, 1))
 
81
        self.add_hook('pre_merge',
 
82
            'Called before a merge. '
 
83
            'Receives a Merger object as the single argument.',
 
84
            (2, 5))
 
85
        self.add_hook('post_merge',
 
86
            'Called after a merge. '
 
87
            'Receives a Merger object as the single argument. '
 
88
            'The return value is ignored.',
 
89
            (2, 5))
78
90
 
79
91
 
80
92
class AbstractPerFileMerger(object):
92
104
    def merge_contents(self, merge_params):
93
105
        """Attempt to merge the contents of a single file.
94
106
        
95
 
        :param merge_params: A bzrlib.merge.MergeHookParams
 
107
        :param merge_params: A bzrlib.merge.MergeFileHookParams
96
108
        :return: A tuple of (status, chunks), where status is one of
97
109
            'not_applicable', 'success', 'conflicted', or 'delete'.  If status
98
110
            is 'success' or 'conflicted', then chunks should be an iterable of
119
131
 
120
132
    def get_filename(self, params, tree):
121
133
        """Lookup the filename (i.e. basename, not path), given a Tree (e.g.
122
 
        self.merger.this_tree) and a MergeHookParams.
 
134
        self.merger.this_tree) and a MergeFileHookParams.
123
135
        """
124
136
        return osutils.basename(tree.id2path(params.file_id))
125
137
 
126
138
    def get_filepath(self, params, tree):
127
139
        """Calculate the path to the file in a tree.
128
140
 
129
 
        :param params: A MergeHookParams describing the file to merge
 
141
        :param params: A MergeFileHookParams describing the file to merge
130
142
        :param tree: a Tree, e.g. self.merger.this_tree.
131
143
        """
132
144
        return tree.id2path(params.file_id)
139
151
            params.winner == 'other' or
140
152
            # THIS and OTHER aren't both files.
141
153
            not params.is_file_merge() or
142
 
            # The filename doesn't match *.xml
 
154
            # The filename doesn't match
143
155
            not self.file_matches(params)):
144
156
            return 'not_applicable', None
145
157
        return self.merge_matching(params)
221
233
        raise NotImplementedError(self.merge_text)
222
234
 
223
235
 
224
 
class MergeHookParams(object):
 
236
class MergeFileHookParams(object):
225
237
    """Object holding parameters passed to merge_file_content hooks.
226
238
 
227
239
    There are some fields hooks can access:
442
454
        revision_id = _mod_revision.ensure_null(revision_id)
443
455
        return branch, self.revision_tree(revision_id, branch)
444
456
 
445
 
    @deprecated_method(deprecated_in((2, 1, 0)))
446
 
    def ensure_revision_trees(self):
447
 
        if self.this_revision_tree is None:
448
 
            self.this_basis_tree = self.revision_tree(self.this_basis)
449
 
            if self.this_basis == self.this_rev_id:
450
 
                self.this_revision_tree = self.this_basis_tree
451
 
 
452
 
        if self.other_rev_id is None:
453
 
            other_basis_tree = self.revision_tree(self.other_basis)
454
 
            if other_basis_tree.has_changes(self.other_tree):
455
 
                raise errors.WorkingTreeNotRevision(self.this_tree)
456
 
            other_rev_id = self.other_basis
457
 
            self.other_tree = other_basis_tree
458
 
 
459
 
    @deprecated_method(deprecated_in((2, 1, 0)))
460
 
    def file_revisions(self, file_id):
461
 
        self.ensure_revision_trees()
462
 
        if self.this_rev_id is None:
463
 
            if self.this_basis_tree.get_file_sha1(file_id) != \
464
 
                self.this_tree.get_file_sha1(file_id):
465
 
                raise errors.WorkingTreeNotRevision(self.this_tree)
466
 
 
467
 
        trees = (self.this_basis_tree, self.other_tree)
468
 
        return [tree.get_file_revision(file_id) for tree in trees]
469
 
 
470
 
    @deprecated_method(deprecated_in((2, 1, 0)))
471
 
    def check_basis(self, check_clean, require_commits=True):
472
 
        if self.this_basis is None and require_commits is True:
473
 
            raise errors.BzrCommandError(
474
 
                "This branch has no commits."
475
 
                " (perhaps you would prefer 'bzr pull')")
476
 
        if check_clean:
477
 
            self.compare_basis()
478
 
            if self.this_basis != self.this_rev_id:
479
 
                raise errors.UncommittedChanges(self.this_tree)
480
 
 
481
 
    @deprecated_method(deprecated_in((2, 1, 0)))
482
 
    def compare_basis(self):
483
 
        try:
484
 
            basis_tree = self.revision_tree(self.this_tree.last_revision())
485
 
        except errors.NoSuchRevision:
486
 
            basis_tree = self.this_tree.basis_tree()
487
 
        if not self.this_tree.has_changes(basis_tree):
488
 
            self.this_rev_id = self.this_basis
489
 
 
490
457
    def set_interesting_files(self, file_list):
491
458
        self.interesting_files = file_list
492
459
 
537
504
                raise errors.NoCommits(self.other_branch)
538
505
        if self.other_rev_id is not None:
539
506
            self._cached_trees[self.other_rev_id] = self.other_tree
540
 
        self._maybe_fetch(self.other_branch,self.this_branch, self.other_basis)
 
507
        self._maybe_fetch(self.other_branch, self.this_branch, self.other_basis)
541
508
 
542
509
    def set_other_revision(self, revision_id, other_branch):
543
510
        """Set 'other' based on a branch and revision id
592
559
                else:
593
560
                    self.base_rev_id = self.revision_graph.find_unique_lca(
594
561
                                            *lcas)
595
 
                sorted_lca_keys = self.revision_graph.find_merge_order(                
 
562
                sorted_lca_keys = self.revision_graph.find_merge_order(
596
563
                    revisions[0], lcas)
597
564
                if self.base_rev_id == _mod_revision.NULL_REVISION:
598
565
                    self.base_rev_id = sorted_lca_keys[0]
599
 
                
 
566
 
600
567
            if self.base_rev_id == _mod_revision.NULL_REVISION:
601
568
                raise errors.UnrelatedBranches()
602
569
            if self._is_criss_cross:
605
572
                trace.mutter('Criss-cross lcas: %r' % lcas)
606
573
                if self.base_rev_id in lcas:
607
574
                    trace.mutter('Unable to find unique lca. '
608
 
                                 'Fallback %r as best option.' % self.base_rev_id)
 
575
                                 'Fallback %r as best option.'
 
576
                                 % self.base_rev_id)
609
577
                interesting_revision_ids = set(lcas)
610
578
                interesting_revision_ids.add(self.base_rev_id)
611
579
                interesting_trees = dict((t.get_revision_id(), t)
644
612
            self._maybe_fetch(base_branch, self.this_branch, self.base_rev_id)
645
613
 
646
614
    def make_merger(self):
647
 
        kwargs = {'working_tree':self.this_tree, 'this_tree': self.this_tree,
 
615
        kwargs = {'working_tree': self.this_tree, 'this_tree': self.this_tree,
648
616
                  'other_tree': self.other_tree,
649
617
                  'interesting_ids': self.interesting_ids,
650
618
                  'interesting_files': self.interesting_files,
651
619
                  'this_branch': self.this_branch,
 
620
                  'other_branch': self.other_branch,
652
621
                  'do_merge': False}
653
622
        if self.merge_type.requires_base:
654
623
            kwargs['base_tree'] = self.base_tree
680
649
        merge = self.make_merger()
681
650
        if self.other_branch is not None:
682
651
            self.other_branch.update_references(self.this_branch)
 
652
        for hook in Merger.hooks['pre_merge']:
 
653
            hook(merge)
683
654
        merge.do_merge()
 
655
        for hook in Merger.hooks['post_merge']:
 
656
            hook(merge)
684
657
        if self.recurse == 'down':
685
658
            for relpath, file_id in self.this_tree.iter_references():
686
659
                sub_tree = self.this_tree.get_nested_tree(file_id, relpath)
690
663
                    continue
691
664
                sub_merge = Merger(sub_tree.branch, this_tree=sub_tree)
692
665
                sub_merge.merge_type = self.merge_type
693
 
                other_branch = self.other_branch.reference_parent(file_id, relpath)
 
666
                other_branch = self.other_branch.reference_parent(file_id,
 
667
                                                                  relpath)
694
668
                sub_merge.set_other_revision(other_revision, other_branch)
695
669
                base_revision = self.base_tree.get_reference_revision(file_id)
696
670
                sub_merge.base_tree = \
752
726
                 interesting_ids=None, reprocess=False, show_base=False,
753
727
                 pb=None, pp=None, change_reporter=None,
754
728
                 interesting_files=None, do_merge=True,
755
 
                 cherrypick=False, lca_trees=None, this_branch=None):
 
729
                 cherrypick=False, lca_trees=None, this_branch=None,
 
730
                 other_branch=None):
756
731
        """Initialize the merger object and perform the merge.
757
732
 
758
733
        :param working_tree: The working tree to apply the merge to
761
736
        :param other_tree: The other tree to merge changes from
762
737
        :param this_branch: The branch associated with this_tree.  Defaults to
763
738
            this_tree.branch if not supplied.
 
739
        :param other_branch: The branch associated with other_tree, if any.
764
740
        :param interesting_ids: The file_ids of files that should be
765
741
            participate in the merge.  May not be combined with
766
742
            interesting_files.
788
764
            this_branch = this_tree.branch
789
765
        self.interesting_ids = interesting_ids
790
766
        self.interesting_files = interesting_files
791
 
        self.this_tree = working_tree
 
767
        self.working_tree = working_tree
 
768
        self.this_tree = this_tree
792
769
        self.base_tree = base_tree
793
770
        self.other_tree = other_tree
794
771
        self.this_branch = this_branch
 
772
        self.other_branch = other_branch
795
773
        self._raw_conflicts = []
796
774
        self.cooked_conflicts = []
797
775
        self.reprocess = reprocess
813
791
 
814
792
    def do_merge(self):
815
793
        operation = cleanup.OperationWithCleanups(self._do_merge)
816
 
        self.this_tree.lock_tree_write()
 
794
        self.working_tree.lock_tree_write()
 
795
        operation.add_cleanup(self.working_tree.unlock)
 
796
        self.this_tree.lock_read()
817
797
        operation.add_cleanup(self.this_tree.unlock)
818
798
        self.base_tree.lock_read()
819
799
        operation.add_cleanup(self.base_tree.unlock)
822
802
        operation.run()
823
803
 
824
804
    def _do_merge(self, operation):
825
 
        self.tt = transform.TreeTransform(self.this_tree, None)
 
805
        self.tt = transform.TreeTransform(self.working_tree, None)
826
806
        operation.add_cleanup(self.tt.finalize)
827
807
        self._compute_transform()
828
808
        results = self.tt.apply(no_conflicts=True)
829
809
        self.write_modified(results)
830
810
        try:
831
 
            self.this_tree.add_conflicts(self.cooked_conflicts)
 
811
            self.working_tree.add_conflicts(self.cooked_conflicts)
832
812
        except errors.UnsupportedOperation:
833
813
            pass
834
814
 
841
821
        return operation.run_simple()
842
822
 
843
823
    def _make_preview_transform(self):
844
 
        self.tt = transform.TransformPreview(self.this_tree)
 
824
        self.tt = transform.TransformPreview(self.working_tree)
845
825
        self._compute_transform()
846
826
        return self.tt
847
827
 
852
832
        else:
853
833
            entries = self._entries_lca()
854
834
            resolver = self._lca_multi_way
 
835
        # Prepare merge hooks
 
836
        factories = Merger.hooks['merge_file_content']
 
837
        # One hook for each registered one plus our default merger
 
838
        hooks = [factory(self) for factory in factories] + [self]
 
839
        self.active_hooks = [hook for hook in hooks if hook is not None]
855
840
        child_pb = ui.ui_factory.nested_progress_bar()
856
841
        try:
857
 
            factories = Merger.hooks['merge_file_content']
858
 
            hooks = [factory(self) for factory in factories] + [self]
859
 
            self.active_hooks = [hook for hook in hooks if hook is not None]
860
842
            for num, (file_id, changed, parents3, names3,
861
843
                      executable3) in enumerate(entries):
862
 
                child_pb.update(gettext('Preparing file merge'), num, len(entries))
 
844
                # Try merging each entry
 
845
                child_pb.update(gettext('Preparing file merge'),
 
846
                                num, len(entries))
863
847
                self._merge_names(file_id, parents3, names3, resolver=resolver)
864
848
                if changed:
865
849
                    file_status = self._do_merge_contents(file_id)
956
940
        result = []
957
941
        walker = _mod_tree.MultiWalker(self.other_tree, self._lca_trees)
958
942
 
959
 
        base_inventory = self.base_tree.inventory
960
 
        this_inventory = self.this_tree.inventory
 
943
        base_inventory = self.base_tree.root_inventory
 
944
        this_inventory = self.this_tree.root_inventory
961
945
        for path, file_id, other_ie, lca_values in walker.iter_all():
962
946
            # Is this modified at all from any of the other trees?
963
947
            if other_ie is None:
1094
1078
                          ))
1095
1079
        return result
1096
1080
 
1097
 
    @deprecated_method(deprecated_in((2, 4, 0)))
1098
 
    def fix_root(self):
1099
 
        if self.tt.final_kind(self.tt.root) is None:
1100
 
            self.tt.cancel_deletion(self.tt.root)
1101
 
        if self.tt.final_file_id(self.tt.root) is None:
1102
 
            self.tt.version_file(self.tt.tree_file_id(self.tt.root),
1103
 
                                 self.tt.root)
1104
 
        other_root_file_id = self.other_tree.get_root_id()
1105
 
        if other_root_file_id is None:
1106
 
            return
1107
 
        other_root = self.tt.trans_id_file_id(other_root_file_id)
1108
 
        if other_root == self.tt.root:
1109
 
            return
1110
 
        if self.this_tree.inventory.has_id(
1111
 
            self.other_tree.inventory.root.file_id):
1112
 
            # the other tree's root is a non-root in the current tree (as
1113
 
            # when a previously unrelated branch is merged into another)
1114
 
            return
1115
 
        if self.tt.final_kind(other_root) is not None:
1116
 
            other_root_is_present = True
1117
 
        else:
1118
 
            # other_root doesn't have a physical representation. We still need
1119
 
            # to move any references to the actual root of the tree.
1120
 
            other_root_is_present = False
1121
 
        # 'other_tree.inventory.root' is not present in this tree. We are
1122
 
        # calling adjust_path for children which *want* to be present with a
1123
 
        # correct place to go.
1124
 
        for _, child in self.other_tree.inventory.root.children.iteritems():
1125
 
            trans_id = self.tt.trans_id_file_id(child.file_id)
1126
 
            if not other_root_is_present:
1127
 
                if self.tt.final_kind(trans_id) is not None:
1128
 
                    # The item exist in the final tree and has a defined place
1129
 
                    # to go already.
1130
 
                    continue
1131
 
            # Move the item into the root
1132
 
            try:
1133
 
                final_name = self.tt.final_name(trans_id)
1134
 
            except errors.NoFinalPath:
1135
 
                # This file is not present anymore, ignore it.
1136
 
                continue
1137
 
            self.tt.adjust_path(final_name, self.tt.root, trans_id)
1138
 
        if other_root_is_present:
1139
 
            self.tt.cancel_creation(other_root)
1140
 
            self.tt.cancel_versioning(other_root)
1141
 
 
1142
1081
    def write_modified(self, results):
1143
1082
        modified_hashes = {}
1144
1083
        for path in results.modified_paths:
1145
 
            file_id = self.this_tree.path2id(self.this_tree.relpath(path))
 
1084
            file_id = self.working_tree.path2id(self.working_tree.relpath(path))
1146
1085
            if file_id is None:
1147
1086
                continue
1148
 
            hash = self.this_tree.get_file_sha1(file_id)
 
1087
            hash = self.working_tree.get_file_sha1(file_id)
1149
1088
            if hash is None:
1150
1089
                continue
1151
1090
            modified_hashes[file_id] = hash
1152
 
        self.this_tree.set_merge_modified(modified_hashes)
 
1091
        self.working_tree.set_merge_modified(modified_hashes)
1153
1092
 
1154
1093
    @staticmethod
1155
1094
    def parent(entry, file_id):
1254
1193
        # At this point, the lcas disagree, and the tip disagree
1255
1194
        return 'conflict'
1256
1195
 
1257
 
    @staticmethod
1258
 
    @deprecated_method(deprecated_in((2, 2, 0)))
1259
 
    def scalar_three_way(this_tree, base_tree, other_tree, file_id, key):
1260
 
        """Do a three-way test on a scalar.
1261
 
        Return "this", "other" or "conflict", depending whether a value wins.
1262
 
        """
1263
 
        key_base = key(base_tree, file_id)
1264
 
        key_other = key(other_tree, file_id)
1265
 
        #if base == other, either they all agree, or only THIS has changed.
1266
 
        if key_base == key_other:
1267
 
            return "this"
1268
 
        key_this = key(this_tree, file_id)
1269
 
        # "Ambiguous clean merge"
1270
 
        if key_this == key_other:
1271
 
            return "this"
1272
 
        elif key_this == key_base:
1273
 
            return "other"
1274
 
        else:
1275
 
            return "conflict"
1276
 
 
1277
1196
    def merge_names(self, file_id):
1278
1197
        def get_entry(tree):
1279
 
            if tree.has_id(file_id):
1280
 
                return tree.inventory[file_id]
1281
 
            else:
 
1198
            try:
 
1199
                return tree.root_inventory[file_id]
 
1200
            except errors.NoSuchId:
1282
1201
                return None
1283
1202
        this_entry = get_entry(self.this_tree)
1284
1203
        other_entry = get_entry(self.other_tree)
1379
1298
        # We have a hypothetical conflict, but if we have files, then we
1380
1299
        # can try to merge the content
1381
1300
        trans_id = self.tt.trans_id_file_id(file_id)
1382
 
        params = MergeHookParams(self, file_id, trans_id, this_pair[0],
 
1301
        params = MergeFileHookParams(self, file_id, trans_id, this_pair[0],
1383
1302
            other_pair[0], winner)
1384
1303
        hooks = self.active_hooks
1385
1304
        hook_status = 'not_applicable'
1388
1307
            if hook_status != 'not_applicable':
1389
1308
                # Don't try any more hooks, this one applies.
1390
1309
                break
 
1310
        # If the merge ends up replacing the content of the file, we get rid of
 
1311
        # it at the end of this method (this variable is used to track the
 
1312
        # exceptions to this rule).
 
1313
        keep_this = False
1391
1314
        result = "modified"
1392
1315
        if hook_status == 'not_applicable':
1393
 
            # This is a contents conflict, because none of the available
1394
 
            # functions could merge it.
 
1316
            # No merge hook was able to resolve the situation. Two cases exist:
 
1317
            # a content conflict or a duplicate one.
1395
1318
            result = None
1396
1319
            name = self.tt.final_name(trans_id)
1397
1320
            parent_id = self.tt.final_parent(trans_id)
1398
 
            if self.this_tree.has_id(file_id):
1399
 
                self.tt.unversion_file(trans_id)
1400
 
            file_group = self._dump_conflicts(name, parent_id, file_id,
1401
 
                                              set_version=True)
1402
 
            self._raw_conflicts.append(('contents conflict', file_group))
 
1321
            duplicate = False
 
1322
            inhibit_content_conflict = False
 
1323
            if params.this_kind is None: # file_id is not in THIS
 
1324
                # Is the name used for a different file_id ?
 
1325
                dupe_path = self.other_tree.id2path(file_id)
 
1326
                this_id = self.this_tree.path2id(dupe_path)
 
1327
                if this_id is not None:
 
1328
                    # Two entries for the same path
 
1329
                    keep_this = True
 
1330
                    # versioning the merged file will trigger a duplicate
 
1331
                    # conflict
 
1332
                    self.tt.version_file(file_id, trans_id)
 
1333
                    transform.create_from_tree(
 
1334
                        self.tt, trans_id, self.other_tree, file_id,
 
1335
                        filter_tree_path=self._get_filter_tree_path(file_id))
 
1336
                    inhibit_content_conflict = True
 
1337
            elif params.other_kind is None: # file_id is not in OTHER
 
1338
                # Is the name used for a different file_id ?
 
1339
                dupe_path = self.this_tree.id2path(file_id)
 
1340
                other_id = self.other_tree.path2id(dupe_path)
 
1341
                if other_id is not None:
 
1342
                    # Two entries for the same path again, but here, the other
 
1343
                    # entry will also be merged.  We simply inhibit the
 
1344
                    # 'content' conflict creation because we know OTHER will
 
1345
                    # create (or has already created depending on ordering) an
 
1346
                    # entry at the same path. This will trigger a 'duplicate'
 
1347
                    # conflict later.
 
1348
                    keep_this = True
 
1349
                    inhibit_content_conflict = True
 
1350
            if not inhibit_content_conflict:
 
1351
                if params.this_kind is not None:
 
1352
                    self.tt.unversion_file(trans_id)
 
1353
                # This is a contents conflict, because none of the available
 
1354
                # functions could merge it.
 
1355
                file_group = self._dump_conflicts(name, parent_id, file_id,
 
1356
                                                  set_version=True)
 
1357
                self._raw_conflicts.append(('contents conflict', file_group))
1403
1358
        elif hook_status == 'success':
1404
1359
            self.tt.create_file(lines, trans_id)
1405
1360
        elif hook_status == 'conflicted':
1421
1376
            raise AssertionError('unknown hook_status: %r' % (hook_status,))
1422
1377
        if not self.this_tree.has_id(file_id) and result == "modified":
1423
1378
            self.tt.version_file(file_id, trans_id)
1424
 
        # The merge has been performed, so the old contents should not be
1425
 
        # retained.
1426
 
        self.tt.delete_contents(trans_id)
 
1379
        if not keep_this:
 
1380
            # The merge has been performed and produced a new content, so the
 
1381
            # old contents should not be retained.
 
1382
            self.tt.delete_contents(trans_id)
1427
1383
        return result
1428
1384
 
1429
1385
    def _default_other_winner_merge(self, merge_hook_params):
1430
1386
        """Replace this contents with other."""
1431
1387
        file_id = merge_hook_params.file_id
1432
1388
        trans_id = merge_hook_params.trans_id
1433
 
        file_in_this = self.this_tree.has_id(file_id)
1434
1389
        if self.other_tree.has_id(file_id):
1435
1390
            # OTHER changed the file
1436
 
            wt = self.this_tree
1437
 
            if wt.supports_content_filtering():
1438
 
                # We get the path from the working tree if it exists.
1439
 
                # That fails though when OTHER is adding a file, so
1440
 
                # we fall back to the other tree to find the path if
1441
 
                # it doesn't exist locally.
1442
 
                try:
1443
 
                    filter_tree_path = wt.id2path(file_id)
1444
 
                except errors.NoSuchId:
1445
 
                    filter_tree_path = self.other_tree.id2path(file_id)
1446
 
            else:
1447
 
                # Skip the id2path lookup for older formats
1448
 
                filter_tree_path = None
1449
 
            transform.create_from_tree(self.tt, trans_id,
1450
 
                             self.other_tree, file_id,
1451
 
                             filter_tree_path=filter_tree_path)
 
1391
            transform.create_from_tree(
 
1392
                self.tt, trans_id, self.other_tree, file_id,
 
1393
                filter_tree_path=self._get_filter_tree_path(file_id))
1452
1394
            return 'done', None
1453
 
        elif file_in_this:
 
1395
        elif self.this_tree.has_id(file_id):
1454
1396
            # OTHER deleted the file
1455
1397
            return 'delete', None
1456
1398
        else:
1530
1472
                                              other_lines)
1531
1473
            file_group.append(trans_id)
1532
1474
 
 
1475
 
 
1476
    def _get_filter_tree_path(self, file_id):
 
1477
        if self.this_tree.supports_content_filtering():
 
1478
            # We get the path from the working tree if it exists.
 
1479
            # That fails though when OTHER is adding a file, so
 
1480
            # we fall back to the other tree to find the path if
 
1481
            # it doesn't exist locally.
 
1482
            try:
 
1483
                return self.this_tree.id2path(file_id)
 
1484
            except errors.NoSuchId:
 
1485
                return self.other_tree.id2path(file_id)
 
1486
        # Skip the id2path lookup for older formats
 
1487
        return None
 
1488
 
1533
1489
    def _dump_conflicts(self, name, parent_id, file_id, this_lines=None,
1534
1490
                        base_lines=None, other_lines=None, set_version=False,
1535
1491
                        no_base=False):
1653
1609
                for trans_id in conflict[1]:
1654
1610
                    file_id = self.tt.final_file_id(trans_id)
1655
1611
                    if file_id is not None:
 
1612
                        # Ok we found the relevant file-id
1656
1613
                        break
1657
1614
                path = fp.get_path(trans_id)
1658
1615
                for suffix in ('.BASE', '.THIS', '.OTHER'):
1659
1616
                    if path.endswith(suffix):
 
1617
                        # Here is the raw path
1660
1618
                        path = path[:-len(suffix)]
1661
1619
                        break
1662
1620
                c = _mod_conflicts.Conflict.factory(conflict_type,
1917
1875
 
1918
1876
    def _entries_to_incorporate(self):
1919
1877
        """Yields pairs of (inventory_entry, new_parent)."""
1920
 
        other_inv = self.other_tree.inventory
 
1878
        other_inv = self.other_tree.root_inventory
1921
1879
        subdir_id = other_inv.path2id(self._source_subpath)
1922
1880
        if subdir_id is None:
1923
1881
            # XXX: The error would be clearer if it gave the URL of the source
1925
1883
            raise PathNotInTree(self._source_subpath, "Source tree")
1926
1884
        subdir = other_inv[subdir_id]
1927
1885
        parent_in_target = osutils.dirname(self._target_subdir)
1928
 
        target_id = self.this_tree.inventory.path2id(parent_in_target)
 
1886
        target_id = self.this_tree.path2id(parent_in_target)
1929
1887
        if target_id is None:
1930
1888
            raise PathNotInTree(self._target_subdir, "Target tree")
1931
1889
        name_in_target = osutils.basename(self._target_subdir)
1932
1890
        merge_into_root = subdir.copy()
1933
1891
        merge_into_root.name = name_in_target
1934
 
        if self.this_tree.inventory.has_id(merge_into_root.file_id):
 
1892
        if self.this_tree.has_id(merge_into_root.file_id):
1935
1893
            # Give the root a new file-id.
1936
1894
            # This can happen fairly easily if the directory we are
1937
1895
            # incorporating is the root, and both trees have 'TREE_ROOT' as
1997
1955
    merger.set_base_revision(get_revision_id(), this_branch)
1998
1956
    return merger.do_merge()
1999
1957
 
 
1958
 
 
1959
merge_type_registry = registry.Registry()
 
1960
merge_type_registry.register('diff3', Diff3Merger,
 
1961
                             "Merge using external diff3.")
 
1962
merge_type_registry.register('lca', LCAMerger,
 
1963
                             "LCA-newness merge.")
 
1964
merge_type_registry.register('merge3', Merge3Merger,
 
1965
                             "Native diff3-style merge.")
 
1966
merge_type_registry.register('weave', WeaveMerger,
 
1967
                             "Weave-based merge.")
 
1968
 
 
1969
 
2000
1970
def get_merge_type_registry():
2001
 
    """Merge type registry is in bzrlib.option to avoid circular imports.
 
1971
    """Merge type registry was previously in bzrlib.option
2002
1972
 
2003
 
    This method provides a sanctioned way to retrieve it.
 
1973
    This method provides a backwards compatible way to retrieve it.
2004
1974
    """
2005
 
    from bzrlib import option
2006
 
    return option._merge_type_registry
 
1975
    return merge_type_registry
2007
1976
 
2008
1977
 
2009
1978
def _plan_annotate_merge(annotated_a, annotated_b, ancestors_a, ancestors_b):