~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge_core.py

  • Committer: Aaron Bentley
  • Date: 2005-10-13 21:29:09 UTC
  • mfrom: (1451)
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1460.
  • Revision ID: abentley@troll-20051013212909-cfde7d2d05ccd47e
Merged latest from robert collins

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    def __ne__(self, other):
30
30
        return not (self == other)
31
31
 
32
 
 
33
32
    def apply(self, filename, conflict_handler, reverse=False):
34
33
        new_file = filename+".new" 
35
34
        if not reverse:
43
42
                raise Exception("%s not in tree" % self.file_id)
44
43
                return ()
45
44
            return tree.get_file(self.file_id).readlines()
 
45
        ### garh. 
 
46
        other_entry = other.tree.inventory[self.file_id]
 
47
        if other_entry.kind == 'symlink':
 
48
            self.apply_symlink(other_entry, base, other, filename)
 
49
            return
46
50
        base_lines = get_lines(base)
47
51
        other_lines = get_lines(other)
48
52
        m3 = Merge3(base_lines, file(filename, "rb").readlines(), other_lines)
66
70
            conflict_handler.merge_conflict(new_file, filename, base_lines,
67
71
                                            other_lines)
68
72
 
 
73
    def apply_symlink(self, other_entry, base, other, filename):
 
74
        if self.file_id in base:
 
75
            base_entry = base.tree.inventory[self.file_id]
 
76
            base_entry._read_tree_state(base.tree)
 
77
        else:
 
78
            base_entry = None
 
79
        other_entry._read_tree_state(other.tree)
 
80
        if not base_entry or other_entry.detect_changes(base_entry):
 
81
            other_change = True
 
82
        else:
 
83
            other_change = False
 
84
        this_link = os.readlink(filename)
 
85
        if not base_entry or base_entry.symlink_target != this_link:
 
86
            this_change = True
 
87
        else:
 
88
            this_change = False
 
89
        if this_change and not other_change:
 
90
            pass
 
91
        elif not this_change and other_change:
 
92
            os.unlink(filename)
 
93
            os.symlink(other_entry.symlink_target, filename)
 
94
        elif this_change and other_change:
 
95
            # conflict
 
96
            os.unlink(filename)
 
97
            os.symlink(other_entry.symlink_target, filename + '.OTHER')
 
98
            os.symlink(this_link, filename + '.THIS')
 
99
            if base_entry is not None:
 
100
                os.symlink(other_entry.symlink_target, filename + '.BASE')
 
101
            note("merge3 conflict in '%s'.\n", filename)
 
102
 
69
103
 
70
104
class BackupBeforeChange:
71
105
    """Contents-change wrapper to back up file first"""
244
278
        elif isinstance(contents.old_contents, changeset.TreeFileCreate) and \
245
279
            isinstance(contents.new_contents, changeset.TreeFileCreate):
246
280
            return make_merge()
 
281
        elif (isinstance(contents.old_contents, changeset.SymlinkCreate)
 
282
              and isinstance(contents.new_contents, changeset.SymlinkCreate)):
 
283
            return make_merge()
247
284
        else:
248
285
            raise Exception("Unhandled merge scenario %r" % contents)
249
286