~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge_core.py

[merge] config file and other things from robert

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    def __ne__(self, other):
23
23
        return not (self == other)
24
24
 
25
 
 
26
25
    def apply(self, filename, conflict_handler, reverse=False):
27
26
        new_file = filename+".new" 
28
27
        if not reverse:
36
35
                raise Exception("%s not in tree" % self.file_id)
37
36
                return ()
38
37
            return tree.get_file(self.file_id).readlines()
 
38
        ### garh. 
 
39
        other_entry = other.tree.inventory[self.file_id]
 
40
        if other_entry.kind == 'symlink':
 
41
            self.apply_symlink(other_entry, base, other, filename)
 
42
            return
39
43
        base_lines = get_lines(base)
40
44
        other_lines = get_lines(other)
41
45
        m3 = Merge3(base_lines, file(filename, "rb").readlines(), other_lines)
59
63
            conflict_handler.merge_conflict(new_file, filename, base_lines,
60
64
                                            other_lines)
61
65
 
 
66
    def apply_symlink(self, other_entry, base, other, filename):
 
67
        if self.file_id in base:
 
68
            base_entry = base.tree.inventory[self.file_id]
 
69
            base_entry._read_tree_state(base.tree)
 
70
        else:
 
71
            base_entry = None
 
72
        other_entry._read_tree_state(other.tree)
 
73
        if not base_entry or other_entry.detect_changes(base_entry):
 
74
            other_change = True
 
75
        else:
 
76
            other_change = False
 
77
        this_link = os.readlink(filename)
 
78
        if not base_entry or base_entry.symlink_target != this_link:
 
79
            this_change = True
 
80
        else:
 
81
            this_change = False
 
82
        if this_change and not other_change:
 
83
            pass
 
84
        elif not this_change and other_change:
 
85
            os.unlink(filename)
 
86
            os.symlink(other_entry.symlink_target, filename)
 
87
        elif this_change and other_change:
 
88
            # conflict
 
89
            os.unlink(filename)
 
90
            os.symlink(other_entry.symlink_target, filename + '.OTHER')
 
91
            os.symlink(this_link, filename + '.THIS')
 
92
            if base_entry is not None:
 
93
                os.symlink(other_entry.symlink_target, filename + '.BASE')
 
94
            note("merge3 conflict in '%s'.\n", filename)
 
95
 
62
96
 
63
97
class BackupBeforeChange:
64
98
    """Contents-change wrapper to back up file first"""
214
248
        assert tree_entry.kind in ("root_directory", "directory")
215
249
        return changeset.dir_create
216
250
 
217
 
 
218
251
def make_merged_contents(entry, this, base, other, conflict_handler,
219
252
                         merge_factory):
220
253
    contents = entry.contents_change
250
283
                    other_path = other.readonly_path(entry.id)    
251
284
                    conflict_handler.new_contents_conflict(this_path, 
252
285
                                                           other_path)
253
 
        elif isinstance(contents.old_contents, changeset.FileCreate) and \
254
 
            isinstance(contents.new_contents, changeset.FileCreate):
 
286
        elif (isinstance(contents.old_contents, changeset.FileCreate)
 
287
              and isinstance(contents.new_contents, changeset.FileCreate)):
 
288
            return make_merge()
 
289
        elif (isinstance(contents.old_contents, changeset.SymlinkCreate)
 
290
              and isinstance(contents.new_contents, changeset.SymlinkCreate)):
255
291
            return make_merge()
256
292
        else:
257
293
            raise Exception("Unhandled merge scenario")