~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Martin Pool
  • Date: 2008-04-24 07:22:53 UTC
  • mto: This revision was merged to the branch mainline in revision 3415.
  • Revision ID: mbp@sourcefrog.net-20080424072253-opmjij7xfy38w27f
Remove every assert statement from bzrlib!

Depending on the context they are:

 * turned into an explicit if/raise of either AssertionError 
   or something more specific -- particularly where they protect
   programming interfaces, complex invariants, or data file integrity
 * removed, if they're redundant with a later check, not protecting
   a meaningful invariant
 * turned into a selftest method on tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
                 this_tree=None, pb=DummyProgress(), change_reporter=None,
69
69
                 recurse='down', revision_graph=None):
70
70
        object.__init__(self)
71
 
        assert this_tree is not None, "this_tree is required"
72
71
        self.this_branch = this_branch
73
72
        self.this_basis = _mod_revision.ensure_null(
74
73
            this_branch.last_revision())
236
235
        self.ensure_revision_trees()
237
236
        def get_id(tree, file_id):
238
237
            revision_id = tree.inventory[file_id].revision
239
 
            assert revision_id is not None
240
238
            return revision_id
241
239
        if self.this_rev_id is None:
242
240
            if self.this_basis_tree.get_file_sha1(file_id) != \
490
488
            merge.
491
489
        """
492
490
        object.__init__(self)
493
 
        if interesting_files is not None:
494
 
            assert interesting_ids is None
 
491
        if interesting_files is not None and interesting_ids is not None:
 
492
            raise ValueError(
 
493
                'specify either interesting_ids or interesting_files')
495
494
        self.interesting_ids = interesting_ids
496
495
        self.interesting_files = interesting_files
497
496
        self.this_tree = working_tree
712
711
        if key_base == key_other:
713
712
            return "this"
714
713
        key_this = key(this_tree, file_id)
715
 
        if key_this not in (key_base, key_other):
 
714
        # "Ambiguous clean merge"
 
715
        if key_this == key_other:
 
716
            return "this"
 
717
        elif key_this == key_base:
 
718
            return "other"
 
719
        else:
716
720
            return "conflict"
717
 
        # "Ambiguous clean merge"
718
 
        elif key_this == key_other:
719
 
            return "this"
720
 
        else:
721
 
            assert key_this == key_base
722
 
            return "other"
723
721
 
724
722
    def merge_names(self, file_id):
725
723
        def get_entry(tree):
969
967
        if winner == "this":
970
968
            executability = this_executable
971
969
        else:
972
 
            assert winner == "other"
973
970
            if file_id in self.other_tree:
974
971
                executability = other_executable
975
972
            elif file_id in self.this_tree:
1017
1014
        for trans_id, conflicts in name_conflicts.iteritems():
1018
1015
            try:
1019
1016
                this_parent, other_parent = conflicts['parent conflict']
1020
 
                assert this_parent != other_parent
 
1017
                if this_parent == other_parent:
 
1018
                    raise AssertionError()
1021
1019
            except KeyError:
1022
1020
                this_parent = other_parent = \
1023
1021
                    self.tt.final_file_id(self.tt.final_parent(trans_id))
1024
1022
            try:
1025
1023
                this_name, other_name = conflicts['name conflict']
1026
 
                assert this_name != other_name
 
1024
                if this_name == other_name:
 
1025
                    raise AssertionError()
1027
1026
            except KeyError:
1028
1027
                this_name = other_name = self.tt.final_name(trans_id)
1029
1028
            other_path = fp.get_path(trans_id)
1182
1181
    merger.interesting_ids = interesting_ids
1183
1182
    merger.ignore_zero = ignore_zero
1184
1183
    if interesting_files:
1185
 
        assert not interesting_ids, ('Only supply interesting_ids'
1186
 
                                     ' or interesting_files')
 
1184
        if interesting_ids:
 
1185
            raise ValueError('Only supply interesting_ids'
 
1186
                             ' or interesting_files')
1187
1187
        merger.interesting_files = interesting_files
1188
1188
    merger.show_base = show_base
1189
1189
    merger.reprocess = reprocess
1236
1236
        a_cur = ai + l
1237
1237
        b_cur = bi + l
1238
1238
        for text_a, text_b in zip(plain_a[ai:a_cur], plain_b[bi:b_cur]):
1239
 
            assert text_a == text_b
1240
1239
            yield "unchanged", text_a
1241
1240
 
1242
1241