~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Vincent Ladeuil
  • Date: 2011-10-27 15:38:14 UTC
  • mfrom: (6015.44.4 2.4)
  • mto: This revision was merged to the branch mainline in revision 6236.
  • Revision ID: v.ladeuil+lp@free.fr-20111027153814-0r4nd2io1jv6t47f
Merge 2.4 into trunk including fix for bug #880701

Show diffs side-by-side

added added

removed removed

Lines of Context:
592
592
                else:
593
593
                    self.base_rev_id = self.revision_graph.find_unique_lca(
594
594
                                            *lcas)
595
 
                sorted_lca_keys = self.revision_graph.find_merge_order(                
 
595
                sorted_lca_keys = self.revision_graph.find_merge_order(
596
596
                    revisions[0], lcas)
597
597
                if self.base_rev_id == _mod_revision.NULL_REVISION:
598
598
                    self.base_rev_id = sorted_lca_keys[0]
599
 
                
 
599
 
600
600
            if self.base_rev_id == _mod_revision.NULL_REVISION:
601
601
                raise errors.UnrelatedBranches()
602
602
            if self._is_criss_cross:
605
605
                trace.mutter('Criss-cross lcas: %r' % lcas)
606
606
                if self.base_rev_id in lcas:
607
607
                    trace.mutter('Unable to find unique lca. '
608
 
                                 'Fallback %r as best option.' % self.base_rev_id)
 
608
                                 'Fallback %r as best option.'
 
609
                                 % self.base_rev_id)
609
610
                interesting_revision_ids = set(lcas)
610
611
                interesting_revision_ids.add(self.base_rev_id)
611
612
                interesting_trees = dict((t.get_revision_id(), t)
690
691
                    continue
691
692
                sub_merge = Merger(sub_tree.branch, this_tree=sub_tree)
692
693
                sub_merge.merge_type = self.merge_type
693
 
                other_branch = self.other_branch.reference_parent(file_id, relpath)
 
694
                other_branch = self.other_branch.reference_parent(file_id,
 
695
                                                                  relpath)
694
696
                sub_merge.set_other_revision(other_revision, other_branch)
695
697
                base_revision = self.base_tree.get_reference_revision(file_id)
696
698
                sub_merge.base_tree = \
1388
1390
            if hook_status != 'not_applicable':
1389
1391
                # Don't try any more hooks, this one applies.
1390
1392
                break
 
1393
        # If the merge ends up replacing the content of the file, we get rid of
 
1394
        # it at the end of this method (this variable is used to track the
 
1395
        # exceptions to this rule).
 
1396
        keep_this = False
1391
1397
        result = "modified"
1392
1398
        if hook_status == 'not_applicable':
1393
 
            # This is a contents conflict, because none of the available
1394
 
            # functions could merge it.
 
1399
            # No merge hook was able to resolve the situation. Two cases exist:
 
1400
            # a content conflict or a duplicate one.
1395
1401
            result = None
1396
1402
            name = self.tt.final_name(trans_id)
1397
1403
            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))
 
1404
            duplicate = False
 
1405
            inhibit_content_conflict = False
 
1406
            if params.this_kind is None: # file_id is not in THIS
 
1407
                # Is the name used for a different file_id ?
 
1408
                dupe_path = self.other_tree.id2path(file_id)
 
1409
                this_id = self.this_tree.path2id(dupe_path)
 
1410
                if this_id is not None:
 
1411
                    # Two entries for the same path
 
1412
                    keep_this = True
 
1413
                    # versioning the merged file will trigger a duplicate
 
1414
                    # conflict
 
1415
                    self.tt.version_file(file_id, trans_id)
 
1416
                    transform.create_from_tree(
 
1417
                        self.tt, trans_id, self.other_tree, file_id,
 
1418
                        filter_tree_path=self._get_filter_tree_path(file_id))
 
1419
                    inhibit_content_conflict = True
 
1420
            elif params.other_kind is None: # file_id is not in OTHER
 
1421
                # Is the name used for a different file_id ?
 
1422
                dupe_path = self.this_tree.id2path(file_id)
 
1423
                other_id = self.other_tree.path2id(dupe_path)
 
1424
                if other_id is not None:
 
1425
                    # Two entries for the same path again, but here, the other
 
1426
                    # entry will also be merged.  We simply inhibit the
 
1427
                    # 'content' conflict creation because we know OTHER will
 
1428
                    # create (or has already created depending on ordering) an
 
1429
                    # entry at the same path. This will trigger a 'duplicate'
 
1430
                    # conflict later.
 
1431
                    keep_this = True
 
1432
                    inhibit_content_conflict = True
 
1433
            if not inhibit_content_conflict:
 
1434
                if params.this_kind is not None:
 
1435
                    self.tt.unversion_file(trans_id)
 
1436
                # This is a contents conflict, because none of the available
 
1437
                # functions could merge it.
 
1438
                file_group = self._dump_conflicts(name, parent_id, file_id,
 
1439
                                                  set_version=True)
 
1440
                self._raw_conflicts.append(('contents conflict', file_group))
1403
1441
        elif hook_status == 'success':
1404
1442
            self.tt.create_file(lines, trans_id)
1405
1443
        elif hook_status == 'conflicted':
1421
1459
            raise AssertionError('unknown hook_status: %r' % (hook_status,))
1422
1460
        if not self.this_tree.has_id(file_id) and result == "modified":
1423
1461
            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)
 
1462
        if not keep_this:
 
1463
            # The merge has been performed and produced a new content, so the
 
1464
            # old contents should not be retained.
 
1465
            self.tt.delete_contents(trans_id)
1427
1466
        return result
1428
1467
 
1429
1468
    def _default_other_winner_merge(self, merge_hook_params):
1430
1469
        """Replace this contents with other."""
1431
1470
        file_id = merge_hook_params.file_id
1432
1471
        trans_id = merge_hook_params.trans_id
1433
 
        file_in_this = self.this_tree.has_id(file_id)
1434
1472
        if self.other_tree.has_id(file_id):
1435
1473
            # 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)
 
1474
            transform.create_from_tree(
 
1475
                self.tt, trans_id, self.other_tree, file_id,
 
1476
                filter_tree_path=self._get_filter_tree_path(file_id))
1452
1477
            return 'done', None
1453
 
        elif file_in_this:
 
1478
        elif self.this_tree.has_id(file_id):
1454
1479
            # OTHER deleted the file
1455
1480
            return 'delete', None
1456
1481
        else:
1530
1555
                                              other_lines)
1531
1556
            file_group.append(trans_id)
1532
1557
 
 
1558
 
 
1559
    def _get_filter_tree_path(self, file_id):
 
1560
        if self.this_tree.supports_content_filtering():
 
1561
            # We get the path from the working tree if it exists.
 
1562
            # That fails though when OTHER is adding a file, so
 
1563
            # we fall back to the other tree to find the path if
 
1564
            # it doesn't exist locally.
 
1565
            try:
 
1566
                return self.this_tree.id2path(file_id)
 
1567
            except errors.NoSuchId:
 
1568
                return self.other_tree.id2path(file_id)
 
1569
        # Skip the id2path lookup for older formats
 
1570
        return None
 
1571
 
1533
1572
    def _dump_conflicts(self, name, parent_id, file_id, this_lines=None,
1534
1573
                        base_lines=None, other_lines=None, set_version=False,
1535
1574
                        no_base=False):
1653
1692
                for trans_id in conflict[1]:
1654
1693
                    file_id = self.tt.final_file_id(trans_id)
1655
1694
                    if file_id is not None:
 
1695
                        # Ok we found the relevant file-id
1656
1696
                        break
1657
1697
                path = fp.get_path(trans_id)
1658
1698
                for suffix in ('.BASE', '.THIS', '.OTHER'):
1659
1699
                    if path.endswith(suffix):
 
1700
                        # Here is the raw path
1660
1701
                        path = path[:-len(suffix)]
1661
1702
                        break
1662
1703
                c = _mod_conflicts.Conflict.factory(conflict_type,