~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Martin von Gagern
  • Date: 2011-06-01 12:53:56 UTC
  • mto: This revision was merged to the branch mainline in revision 6009.
  • Revision ID: martin.vgagern@gmx.net-20110601125356-lwozv2vecea6hxfz
Change from no_decorate to classify as name for the argument.

The command line switch remains as --no-classify, to keep backwards
compatibility.  Users are free to include --no-classify in an alias, and
still use --classify to change back.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    versionedfile,
39
39
    workingtree,
40
40
    )
41
 
from bzrlib.i18n import gettext
42
41
""")
43
42
from bzrlib import (
44
43
    decorators,
712
711
        merge = operation.run_simple()
713
712
        if len(merge.cooked_conflicts) == 0:
714
713
            if not self.ignore_zero and not trace.is_quiet():
715
 
                trace.note(gettext("All changes applied successfully."))
 
714
                trace.note("All changes applied successfully.")
716
715
        else:
717
 
            trace.note(gettext("%d conflicts encountered.")
 
716
            trace.note("%d conflicts encountered."
718
717
                       % len(merge.cooked_conflicts))
719
718
 
720
719
        return len(merge.cooked_conflicts)
859
858
            self.active_hooks = [hook for hook in hooks if hook is not None]
860
859
            for num, (file_id, changed, parents3, names3,
861
860
                      executable3) in enumerate(entries):
862
 
                child_pb.update(gettext('Preparing file merge'), num, len(entries))
 
861
                child_pb.update('Preparing file merge', num, len(entries))
863
862
                self._merge_names(file_id, parents3, names3, resolver=resolver)
864
863
                if changed:
865
864
                    file_status = self._do_merge_contents(file_id)
869
868
                    executable3, file_status, resolver=resolver)
870
869
        finally:
871
870
            child_pb.finished()
872
 
        self.tt.fixup_new_roots()
 
871
        self.fix_root()
873
872
        self._finish_computing_transform()
874
873
 
875
874
    def _finish_computing_transform(self):
991
990
                else:
992
991
                    lca_entries.append(lca_ie)
993
992
 
994
 
            if base_inventory.has_id(file_id):
 
993
            if file_id in base_inventory:
995
994
                base_ie = base_inventory[file_id]
996
995
            else:
997
996
                base_ie = _none_entry
998
997
 
999
 
            if this_inventory.has_id(file_id):
 
998
            if file_id in this_inventory:
1000
999
                this_ie = this_inventory[file_id]
1001
1000
            else:
1002
1001
                this_ie = _none_entry
1094
1093
                          ))
1095
1094
        return result
1096
1095
 
1097
 
    @deprecated_method(deprecated_in((2, 4, 0)))
1098
1096
    def fix_root(self):
1099
1097
        if self.tt.final_kind(self.tt.root) is None:
1100
1098
            self.tt.cancel_deletion(self.tt.root)
1107
1105
        other_root = self.tt.trans_id_file_id(other_root_file_id)
1108
1106
        if other_root == self.tt.root:
1109
1107
            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)
 
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)
1114
1111
            return
1115
1112
        if self.tt.final_kind(other_root) is not None:
1116
1113
            other_root_is_present = True
1168
1165
    @staticmethod
1169
1166
    def contents_sha1(tree, file_id):
1170
1167
        """Determine the sha1 of the file contents (used as a key method)."""
1171
 
        if not tree.has_id(file_id):
 
1168
        if file_id not in tree:
1172
1169
            return None
1173
1170
        return tree.get_file_sha1(file_id)
1174
1171
 
1319
1316
            self._raw_conflicts.append(('path conflict', trans_id, file_id,
1320
1317
                                        this_parent, this_name,
1321
1318
                                        other_parent, other_name))
1322
 
        if not self.other_tree.has_id(file_id):
 
1319
        if other_name is None:
1323
1320
            # it doesn't matter whether the result was 'other' or
1324
 
            # 'conflict'-- if it has no file id, we leave it alone.
 
1321
            # 'conflict'-- if there's no 'other', we leave it alone.
1325
1322
            return
1326
1323
        parent_id = parents[self.winner_idx[parent_id_winner]]
1327
 
        name = names[self.winner_idx[name_winner]]
1328
 
        if parent_id is not None or name is not None:
 
1324
        if parent_id is not None:
1329
1325
            # if we get here, name_winner and parent_winner are set to safe
1330
1326
            # values.
1331
 
            if parent_id is None and name is not None:
1332
 
                # if parent_id is None and name is non-None, current file is
1333
 
                # the tree root.
1334
 
                if names[self.winner_idx[parent_id_winner]] != '':
1335
 
                    raise AssertionError(
1336
 
                        'File looks like a root, but named %s' %
1337
 
                        names[self.winner_idx[parent_id_winner]])
1338
 
                parent_trans_id = transform.ROOT_PARENT
1339
 
            else:
1340
 
                parent_trans_id = self.tt.trans_id_file_id(parent_id)
1341
 
            self.tt.adjust_path(name, parent_trans_id,
 
1327
            self.tt.adjust_path(names[self.winner_idx[name_winner]],
 
1328
                                self.tt.trans_id_file_id(parent_id),
1342
1329
                                self.tt.trans_id_file_id(file_id))
1343
1330
 
1344
1331
    def _do_merge_contents(self, file_id):
1345
1332
        """Performs a merge on file_id contents."""
1346
1333
        def contents_pair(tree):
1347
 
            if not tree.has_id(file_id):
 
1334
            if file_id not in tree:
1348
1335
                return (None, None)
1349
1336
            kind = tree.kind(file_id)
1350
1337
            if kind == "file":
1618
1605
 
1619
1606
    def cook_conflicts(self, fs_conflicts):
1620
1607
        """Convert all conflicts into a form that doesn't depend on trans_id"""
1621
 
        content_conflict_file_ids = set()
1622
 
        cooked_conflicts = transform.cook_conflicts(fs_conflicts, self.tt)
 
1608
        self.cooked_conflicts.extend(transform.cook_conflicts(
 
1609
                fs_conflicts, self.tt))
1623
1610
        fp = transform.FinalPaths(self.tt)
1624
1611
        for conflict in self._raw_conflicts:
1625
1612
            conflict_type = conflict[0]
1636
1623
                if other_parent is None or other_name is None:
1637
1624
                    other_path = '<deleted>'
1638
1625
                else:
1639
 
                    if other_parent == self.other_tree.get_root_id():
1640
 
                        # The tree transform doesn't know about the other root,
1641
 
                        # so we special case here to avoid a NoFinalPath
1642
 
                        # exception
1643
 
                        parent_path = ''
1644
 
                    else:
1645
 
                        parent_path =  fp.get_path(
1646
 
                            self.tt.trans_id_file_id(other_parent))
 
1626
                    parent_path =  fp.get_path(
 
1627
                        self.tt.trans_id_file_id(other_parent))
1647
1628
                    other_path = osutils.pathjoin(parent_path, other_name)
1648
1629
                c = _mod_conflicts.Conflict.factory(
1649
1630
                    'path conflict', path=this_path,
1661
1642
                        break
1662
1643
                c = _mod_conflicts.Conflict.factory(conflict_type,
1663
1644
                                                    path=path, file_id=file_id)
1664
 
                content_conflict_file_ids.add(file_id)
1665
1645
            elif conflict_type == 'text conflict':
1666
1646
                trans_id = conflict[1]
1667
1647
                path = fp.get_path(trans_id)
1670
1650
                                                    path=path, file_id=file_id)
1671
1651
            else:
1672
1652
                raise AssertionError('bad conflict type: %r' % (conflict,))
1673
 
            cooked_conflicts.append(c)
1674
 
 
1675
 
        self.cooked_conflicts = []
1676
 
        # We want to get rid of path conflicts when a corresponding contents
1677
 
        # conflict exists. This can occur when one branch deletes a file while
1678
 
        # the other renames *and* modifies it. In this case, the content
1679
 
        # conflict is enough.
1680
 
        for c in cooked_conflicts:
1681
 
            if (c.typestring == 'path conflict'
1682
 
                and c.file_id in content_conflict_file_ids):
1683
 
                continue
1684
1653
            self.cooked_conflicts.append(c)
1685
1654
        self.cooked_conflicts.sort(key=_mod_conflicts.Conflict.sort_key)
1686
1655
 
1907
1876
            entries = self._entries_to_incorporate()
1908
1877
            entries = list(entries)
1909
1878
            for num, (entry, parent_id) in enumerate(entries):
1910
 
                child_pb.update(gettext('Preparing file merge'), num, len(entries))
 
1879
                child_pb.update('Preparing file merge', num, len(entries))
1911
1880
                parent_trans_id = self.tt.trans_id_file_id(parent_id)
1912
1881
                trans_id = transform.new_by_entry(self.tt, entry,
1913
1882
                    parent_trans_id, self.other_tree)
1931
1900
        name_in_target = osutils.basename(self._target_subdir)
1932
1901
        merge_into_root = subdir.copy()
1933
1902
        merge_into_root.name = name_in_target
1934
 
        if self.this_tree.inventory.has_id(merge_into_root.file_id):
 
1903
        if merge_into_root.file_id in self.this_tree.inventory:
1935
1904
            # Give the root a new file-id.
1936
1905
            # This can happen fairly easily if the directory we are
1937
1906
            # incorporating is the root, and both trees have 'TREE_ROOT' as
1974
1943
    """
1975
1944
    if this_tree is None:
1976
1945
        raise errors.BzrError("bzrlib.merge.merge_inner requires a this_tree "
1977
 
                              "parameter")
 
1946
                              "parameter as of bzrlib version 0.8.")
1978
1947
    merger = Merger(this_branch, other_tree, base_tree, this_tree=this_tree,
1979
1948
                    pb=pb, change_reporter=change_reporter)
1980
1949
    merger.backup_files = backup_files