~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Jelmer Vernooij
  • Date: 2011-08-04 13:30:30 UTC
  • mfrom: (6050 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6052.
  • Revision ID: jelmer@samba.org-20110804133030-uwo00unp8b0n782c
merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
868
868
                    executable3, file_status, resolver=resolver)
869
869
        finally:
870
870
            child_pb.finished()
871
 
        self.fix_root()
 
871
        self.tt.fixup_new_roots()
872
872
        self._finish_computing_transform()
873
873
 
874
874
    def _finish_computing_transform(self):
888
888
                self.tt.iter_changes(), self.change_reporter)
889
889
        self.cook_conflicts(fs_conflicts)
890
890
        for conflict in self.cooked_conflicts:
891
 
            trace.warning(conflict)
 
891
            trace.warning(unicode(conflict))
892
892
 
893
893
    def _entries3(self):
894
894
        """Gather data about files modified between three trees.
990
990
                else:
991
991
                    lca_entries.append(lca_ie)
992
992
 
993
 
            if file_id in base_inventory:
 
993
            if base_inventory.has_id(file_id):
994
994
                base_ie = base_inventory[file_id]
995
995
            else:
996
996
                base_ie = _none_entry
997
997
 
998
 
            if file_id in this_inventory:
 
998
            if this_inventory.has_id(file_id):
999
999
                this_ie = this_inventory[file_id]
1000
1000
            else:
1001
1001
                this_ie = _none_entry
1093
1093
                          ))
1094
1094
        return result
1095
1095
 
 
1096
    @deprecated_method(deprecated_in((2, 4, 0)))
1096
1097
    def fix_root(self):
1097
1098
        if self.tt.final_kind(self.tt.root) is None:
1098
1099
            self.tt.cancel_deletion(self.tt.root)
1105
1106
        other_root = self.tt.trans_id_file_id(other_root_file_id)
1106
1107
        if other_root == self.tt.root:
1107
1108
            return
1108
 
        if self.other_tree.inventory.root.file_id in self.this_tree.inventory:
1109
 
            # the other tree's root is a non-root in the current tree (as when
1110
 
            # a previously unrelated branch is merged into another)
 
1109
        if self.this_tree.inventory.has_id(
 
1110
            self.other_tree.inventory.root.file_id):
 
1111
            # the other tree's root is a non-root in the current tree (as
 
1112
            # when a previously unrelated branch is merged into another)
1111
1113
            return
1112
1114
        if self.tt.final_kind(other_root) is not None:
1113
1115
            other_root_is_present = True
1165
1167
    @staticmethod
1166
1168
    def contents_sha1(tree, file_id):
1167
1169
        """Determine the sha1 of the file contents (used as a key method)."""
1168
 
        if file_id not in tree:
 
1170
        if not tree.has_id(file_id):
1169
1171
            return None
1170
1172
        return tree.get_file_sha1(file_id)
1171
1173
 
1316
1318
            self._raw_conflicts.append(('path conflict', trans_id, file_id,
1317
1319
                                        this_parent, this_name,
1318
1320
                                        other_parent, other_name))
1319
 
        if other_name is None:
 
1321
        if not self.other_tree.has_id(file_id):
1320
1322
            # it doesn't matter whether the result was 'other' or
1321
 
            # 'conflict'-- if there's no 'other', we leave it alone.
 
1323
            # 'conflict'-- if it has no file id, we leave it alone.
1322
1324
            return
1323
1325
        parent_id = parents[self.winner_idx[parent_id_winner]]
1324
 
        if parent_id is not None:
 
1326
        name = names[self.winner_idx[name_winner]]
 
1327
        if parent_id is not None or name is not None:
1325
1328
            # if we get here, name_winner and parent_winner are set to safe
1326
1329
            # values.
1327
 
            self.tt.adjust_path(names[self.winner_idx[name_winner]],
1328
 
                                self.tt.trans_id_file_id(parent_id),
 
1330
            if parent_id is None and name is not None:
 
1331
                # if parent_id is None and name is non-None, current file is
 
1332
                # the tree root.
 
1333
                if names[self.winner_idx[parent_id_winner]] != '':
 
1334
                    raise AssertionError(
 
1335
                        'File looks like a root, but named %s' %
 
1336
                        names[self.winner_idx[parent_id_winner]])
 
1337
                parent_trans_id = transform.ROOT_PARENT
 
1338
            else:
 
1339
                parent_trans_id = self.tt.trans_id_file_id(parent_id)
 
1340
            self.tt.adjust_path(name, parent_trans_id,
1329
1341
                                self.tt.trans_id_file_id(file_id))
1330
1342
 
1331
1343
    def _do_merge_contents(self, file_id):
1332
1344
        """Performs a merge on file_id contents."""
1333
1345
        def contents_pair(tree):
1334
 
            if file_id not in tree:
 
1346
            if not tree.has_id(file_id):
1335
1347
                return (None, None)
1336
1348
            kind = tree.kind(file_id)
1337
1349
            if kind == "file":
1605
1617
 
1606
1618
    def cook_conflicts(self, fs_conflicts):
1607
1619
        """Convert all conflicts into a form that doesn't depend on trans_id"""
1608
 
        self.cooked_conflicts.extend(transform.cook_conflicts(
1609
 
                fs_conflicts, self.tt))
 
1620
        content_conflict_file_ids = set()
 
1621
        cooked_conflicts = transform.cook_conflicts(fs_conflicts, self.tt)
1610
1622
        fp = transform.FinalPaths(self.tt)
1611
1623
        for conflict in self._raw_conflicts:
1612
1624
            conflict_type = conflict[0]
1623
1635
                if other_parent is None or other_name is None:
1624
1636
                    other_path = '<deleted>'
1625
1637
                else:
1626
 
                    parent_path =  fp.get_path(
1627
 
                        self.tt.trans_id_file_id(other_parent))
 
1638
                    if other_parent == self.other_tree.get_root_id():
 
1639
                        # The tree transform doesn't know about the other root,
 
1640
                        # so we special case here to avoid a NoFinalPath
 
1641
                        # exception
 
1642
                        parent_path = ''
 
1643
                    else:
 
1644
                        parent_path =  fp.get_path(
 
1645
                            self.tt.trans_id_file_id(other_parent))
1628
1646
                    other_path = osutils.pathjoin(parent_path, other_name)
1629
1647
                c = _mod_conflicts.Conflict.factory(
1630
1648
                    'path conflict', path=this_path,
1642
1660
                        break
1643
1661
                c = _mod_conflicts.Conflict.factory(conflict_type,
1644
1662
                                                    path=path, file_id=file_id)
 
1663
                content_conflict_file_ids.add(file_id)
1645
1664
            elif conflict_type == 'text conflict':
1646
1665
                trans_id = conflict[1]
1647
1666
                path = fp.get_path(trans_id)
1650
1669
                                                    path=path, file_id=file_id)
1651
1670
            else:
1652
1671
                raise AssertionError('bad conflict type: %r' % (conflict,))
 
1672
            cooked_conflicts.append(c)
 
1673
 
 
1674
        self.cooked_conflicts = []
 
1675
        # We want to get rid of path conflicts when a corresponding contents
 
1676
        # conflict exists. This can occur when one branch deletes a file while
 
1677
        # the other renames *and* modifies it. In this case, the content
 
1678
        # conflict is enough.
 
1679
        for c in cooked_conflicts:
 
1680
            if (c.typestring == 'path conflict'
 
1681
                and c.file_id in content_conflict_file_ids):
 
1682
                continue
1653
1683
            self.cooked_conflicts.append(c)
1654
1684
        self.cooked_conflicts.sort(key=_mod_conflicts.Conflict.sort_key)
1655
1685
 
1900
1930
        name_in_target = osutils.basename(self._target_subdir)
1901
1931
        merge_into_root = subdir.copy()
1902
1932
        merge_into_root.name = name_in_target
1903
 
        if merge_into_root.file_id in self.this_tree.inventory:
 
1933
        if self.this_tree.inventory.has_id(merge_into_root.file_id):
1904
1934
            # Give the root a new file-id.
1905
1935
            # This can happen fairly easily if the directory we are
1906
1936
            # incorporating is the root, and both trees have 'TREE_ROOT' as
1943
1973
    """
1944
1974
    if this_tree is None:
1945
1975
        raise errors.BzrError("bzrlib.merge.merge_inner requires a this_tree "
1946
 
                              "parameter as of bzrlib version 0.8.")
 
1976
                              "parameter")
1947
1977
    merger = Merger(this_branch, other_tree, base_tree, this_tree=this_tree,
1948
1978
                    pb=pb, change_reporter=change_reporter)
1949
1979
    merger.backup_files = backup_files