~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-04-19 08:42:39 UTC
  • mfrom: (1558.15.11 bzr.binaries)
  • Revision ID: pqm@pqm.ubuntu.com-20060419084239-730ca2dccc3bea14
diff and merge handle binaries safely

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
                           UnrelatedBranches,
36
36
                           UnsupportedOperation,
37
37
                           WorkingTreeNotRevision,
 
38
                           BinaryFile,
38
39
                           )
39
40
from bzrlib.merge3 import Merge3
40
41
import bzrlib.osutils
42
43
from progress import DummyProgress, ProgressPhase
43
44
from bzrlib.revision import common_ancestor, is_ancestor, NULL_REVISION
44
45
from bzrlib.symbol_versioning import *
 
46
from bzrlib.textfile import check_text_lines
45
47
from bzrlib.trace import mutter, warning, note
46
48
from bzrlib.transform import (TreeTransform, resolve_conflicts, cook_conflicts,
47
49
                              FinalPaths, create_by_entry, unique_add)
527
529
            else:
528
530
                contents = None
529
531
            return kind, contents
 
532
 
 
533
        def contents_conflict():
 
534
            trans_id = self.tt.trans_id_file_id(file_id)
 
535
            name = self.tt.final_name(trans_id)
 
536
            parent_id = self.tt.final_parent(trans_id)
 
537
            if file_id in self.this_tree.inventory:
 
538
                self.tt.unversion_file(trans_id)
 
539
                self.tt.delete_contents(trans_id)
 
540
            file_group = self._dump_conflicts(name, parent_id, file_id, 
 
541
                                              set_version=True)
 
542
            self._raw_conflicts.append(('contents conflict', file_group))
 
543
 
530
544
        # See SPOT run.  run, SPOT, run.
531
545
        # So we're not QUITE repeating ourselves; we do tricky things with
532
546
        # file kind...
563
577
                # THIS and OTHER are both files, so text merge.  Either
564
578
                # BASE is a file, or both converted to files, so at least we
565
579
                # have agreement that output should be a file.
 
580
                try:
 
581
                    self.text_merge(file_id, trans_id)
 
582
                except BinaryFile:
 
583
                    return contents_conflict()
566
584
                if file_id not in self.this_tree.inventory:
567
585
                    self.tt.version_file(file_id, trans_id)
568
 
                self.text_merge(file_id, trans_id)
569
586
                try:
570
587
                    self.tt.tree_kind(trans_id)
571
588
                    self.tt.delete_contents(trans_id)
574
591
                return "modified"
575
592
            else:
576
593
                # Scalar conflict, can't text merge.  Dump conflicts
577
 
                trans_id = self.tt.trans_id_file_id(file_id)
578
 
                name = self.tt.final_name(trans_id)
579
 
                parent_id = self.tt.final_parent(trans_id)
580
 
                if file_id in self.this_tree.inventory:
581
 
                    self.tt.unversion_file(trans_id)
582
 
                    self.tt.delete_contents(trans_id)
583
 
                file_group = self._dump_conflicts(name, parent_id, file_id, 
584
 
                                                  set_version=True)
585
 
                self._raw_conflicts.append(('contents conflict', file_group))
 
594
                return contents_conflict()
586
595
 
587
596
    def get_lines(self, tree, file_id):
588
597
        """Return the lines in a file, or an empty list."""
819
828
        """
820
829
        self._check_file(file_id)
821
830
        lines, conflicts = self._merged_lines(file_id)
 
831
        lines = list(lines)
 
832
        # Note we're checking whether the OUTPUT is binary in this case, 
 
833
        # because we don't want to get into weave merge guts.
 
834
        check_text_lines(lines)
822
835
        self.tt.create_file(lines, trans_id)
823
836
        if conflicts:
824
837
            self._raw_conflicts.append(('text conflict', trans_id))