~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Jonathan Riddell
  • Date: 2011-06-24 13:57:59 UTC
  • mto: This revision was merged to the branch mainline in revision 6003.
  • Revision ID: jriddell@canonical.com-20110624135759-263hx2et2kl1in39
change directory option to location argument

Show diffs side-by-side

added added

removed removed

Lines of Context:
990
990
                else:
991
991
                    lca_entries.append(lca_ie)
992
992
 
993
 
            if base_inventory.has_id(file_id):
 
993
            if file_id in base_inventory:
994
994
                base_ie = base_inventory[file_id]
995
995
            else:
996
996
                base_ie = _none_entry
997
997
 
998
 
            if this_inventory.has_id(file_id):
 
998
            if file_id in this_inventory:
999
999
                this_ie = this_inventory[file_id]
1000
1000
            else:
1001
1001
                this_ie = _none_entry
1106
1106
        other_root = self.tt.trans_id_file_id(other_root_file_id)
1107
1107
        if other_root == self.tt.root:
1108
1108
            return
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)
 
1109
        if self.other_tree.inventory.root.file_id in self.this_tree.inventory:
 
1110
            # the other tree's root is a non-root in the current tree (as when
 
1111
            # a previously unrelated branch is merged into another)
1113
1112
            return
1114
1113
        if self.tt.final_kind(other_root) is not None:
1115
1114
            other_root_is_present = True
1167
1166
    @staticmethod
1168
1167
    def contents_sha1(tree, file_id):
1169
1168
        """Determine the sha1 of the file contents (used as a key method)."""
1170
 
        if not tree.has_id(file_id):
 
1169
        if file_id not in tree:
1171
1170
            return None
1172
1171
        return tree.get_file_sha1(file_id)
1173
1172
 
1343
1342
    def _do_merge_contents(self, file_id):
1344
1343
        """Performs a merge on file_id contents."""
1345
1344
        def contents_pair(tree):
1346
 
            if not tree.has_id(file_id):
 
1345
            if file_id not in tree:
1347
1346
                return (None, None)
1348
1347
            kind = tree.kind(file_id)
1349
1348
            if kind == "file":
1617
1616
 
1618
1617
    def cook_conflicts(self, fs_conflicts):
1619
1618
        """Convert all conflicts into a form that doesn't depend on trans_id"""
1620
 
        content_conflict_file_ids = set()
1621
 
        cooked_conflicts = transform.cook_conflicts(fs_conflicts, self.tt)
 
1619
        self.cooked_conflicts.extend(transform.cook_conflicts(
 
1620
                fs_conflicts, self.tt))
1622
1621
        fp = transform.FinalPaths(self.tt)
1623
1622
        for conflict in self._raw_conflicts:
1624
1623
            conflict_type = conflict[0]
1635
1634
                if other_parent is None or other_name is None:
1636
1635
                    other_path = '<deleted>'
1637
1636
                else:
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))
 
1637
                    parent_path =  fp.get_path(
 
1638
                        self.tt.trans_id_file_id(other_parent))
1646
1639
                    other_path = osutils.pathjoin(parent_path, other_name)
1647
1640
                c = _mod_conflicts.Conflict.factory(
1648
1641
                    'path conflict', path=this_path,
1660
1653
                        break
1661
1654
                c = _mod_conflicts.Conflict.factory(conflict_type,
1662
1655
                                                    path=path, file_id=file_id)
1663
 
                content_conflict_file_ids.add(file_id)
1664
1656
            elif conflict_type == 'text conflict':
1665
1657
                trans_id = conflict[1]
1666
1658
                path = fp.get_path(trans_id)
1669
1661
                                                    path=path, file_id=file_id)
1670
1662
            else:
1671
1663
                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
1683
1664
            self.cooked_conflicts.append(c)
1684
1665
        self.cooked_conflicts.sort(key=_mod_conflicts.Conflict.sort_key)
1685
1666
 
1930
1911
        name_in_target = osutils.basename(self._target_subdir)
1931
1912
        merge_into_root = subdir.copy()
1932
1913
        merge_into_root.name = name_in_target
1933
 
        if self.this_tree.inventory.has_id(merge_into_root.file_id):
 
1914
        if merge_into_root.file_id in self.this_tree.inventory:
1934
1915
            # Give the root a new file-id.
1935
1916
            # This can happen fairly easily if the directory we are
1936
1917
            # incorporating is the root, and both trees have 'TREE_ROOT' as
1973
1954
    """
1974
1955
    if this_tree is None:
1975
1956
        raise errors.BzrError("bzrlib.merge.merge_inner requires a this_tree "
1976
 
                              "parameter")
 
1957
                              "parameter as of bzrlib version 0.8.")
1977
1958
    merger = Merger(this_branch, other_tree, base_tree, this_tree=this_tree,
1978
1959
                    pb=pb, change_reporter=change_reporter)
1979
1960
    merger.backup_files = backup_files