~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:58:18 UTC
  • mfrom: (1447)
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1460.
  • Revision ID: abentley@troll-20051013215818-0900f030e3923901
Fixed symlink reverting

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
                raise Exception("%s not in tree" % self.file_id)
43
43
                return ()
44
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
50
45
        base_lines = get_lines(base)
51
46
        other_lines = get_lines(other)
52
47
        m3 = Merge3(base_lines, file(filename, "rb").readlines(), other_lines)
70
65
            conflict_handler.merge_conflict(new_file, filename, base_lines,
71
66
                                            other_lines)
72
67
 
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
 
 
103
68
 
104
69
class BackupBeforeChange:
105
70
    """Contents-change wrapper to back up file first"""
278
243
        elif isinstance(contents.old_contents, changeset.TreeFileCreate) and \
279
244
            isinstance(contents.new_contents, changeset.TreeFileCreate):
280
245
            return make_merge()
281
 
        elif (isinstance(contents.old_contents, changeset.SymlinkCreate)
282
 
              and isinstance(contents.new_contents, changeset.SymlinkCreate)):
283
 
            return make_merge()
284
246
        else:
285
 
            raise Exception("Unhandled merge scenario %r" % contents)
 
247
            this_contents = get_contents(this, entry.id)
 
248
            if this_contents == contents.old_contents:
 
249
                return contents
 
250
            elif this_contents == contents.new_contents:
 
251
                return None
 
252
            elif contents.old_contents == contents.new_contents:
 
253
                return None
 
254
            else:
 
255
                conflict_handler.threeway_contents_conflict(this_contents,
 
256
                    contents.old_contents, contents.new_contents)
 
257
                
286
258
 
287
259
def make_merged_metadata(entry, base, other):
288
260
    metadata = entry.metadata_change