~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Aaron Bentley
  • Date: 2005-08-11 19:06:02 UTC
  • mto: (1092.1.41) (1185.3.4) (974.1.47)
  • mto: This revision was merged to the branch mainline in revision 1110.
  • Revision ID: abentley@panoramicfeedback.com-20050811190602-12035bb1621de724
Avoided unnecessary temp files

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
            d_file.write(line)
37
37
        os.chmod(dest, 0777 & os.stat(source).st_mode)
38
38
 
 
39
    def dump(self, lines, dest):
 
40
        """Copy the text and mode of a file
 
41
        :param source: The path of the file to copy
 
42
        :param dest: The distination file to create
 
43
        """
 
44
        d_file = file(dest, "wb")
 
45
        for line in lines:
 
46
            d_file.write(line)
 
47
 
39
48
    def add_suffix(self, name, suffix, last_new_name=None):
40
49
        """Rename a file to append a suffix.  If the new name exists, the
41
50
        suffix is added repeatedly until a non-existant name is found
60
69
        self.conflicts += 1
61
70
        
62
71
 
63
 
    def merge_conflict(self, new_file, this_path, base_path, other_path):
 
72
    def merge_conflict(self, new_file, this_path, base_lines, other_lines):
64
73
        """
65
74
        Handle diff3 conflicts by producing a .THIS, .BASE and .OTHER.  The
66
75
        main file will be a version with diff3 conflicts.
70
79
        :param other_path: Path to the file text for the OTHER tree
71
80
        """
72
81
        self.add_suffix(this_path, ".THIS")
73
 
        self.copy(base_path, this_path+".BASE")
74
 
        self.copy(other_path, this_path+".OTHER")
 
82
        self.dump(base_lines, this_path+".BASE")
 
83
        self.dump(other_lines, this_path+".OTHER")
75
84
        os.rename(new_file, this_path)
76
85
        self.conflict("Diff3 conflict encountered in %s" % this_path)
77
86
 
126
135
    def __contains__(self, file_id):
127
136
        return file_id in self.tree
128
137
 
 
138
    def get_file(self, file_id):
 
139
        return self.tree.get_file(file_id)
 
140
 
129
141
    def get_file_sha1(self, id):
130
142
        return self.tree.get_file_sha1(id)
131
143
 
236
248
                ignore_zero=False, merge_type=ApplyMerge3, backup_files=False,
237
249
                interesting_ids=None):
238
250
 
239
 
    def merge_factory(base_file, other_file):
240
 
        contents_change = merge_type(base_file, other_file)
 
251
    def merge_factory(file_id, base, other):
 
252
        contents_change = merge_type(file_id, base, other)
241
253
        if backup_files:
242
254
            contents_change = BackupBeforeChange(contents_change)
243
255
        return contents_change