~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge_core.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:
6
6
 
7
7
class ApplyMerge3:
8
8
    """Contents-change wrapper around merge3.Merge3"""
9
 
    def __init__(self, base_file, other_file):
10
 
        self.base_file = base_file
11
 
        self.other_file = other_file
 
9
    def __init__(self, file_id, base, other):
 
10
        self.file_id = file_id
 
11
        self.base = base
 
12
        self.other = other
12
13
 
13
14
    def __eq__(self, other):
14
15
        if not isinstance(other, ApplyMerge3):
15
16
            return False
16
 
        return (self.base_file == other.base_file and 
17
 
                self.other_file == other.other_file)
 
17
        return (self.base == other.base and 
 
18
                self.other == other.other and self.file_id == other.file_id)
18
19
 
19
20
    def __ne__(self, other):
20
21
        return not (self == other)
23
24
    def apply(self, filename, conflict_handler, reverse=False):
24
25
        new_file = filename+".new" 
25
26
        if not reverse:
26
 
            base = self.base_file
27
 
            other = self.other_file
 
27
            base = self.base
 
28
            other = self.other
28
29
        else:
29
 
            base = self.other_file
30
 
            other = self.base_file
31
 
        m3 = Merge3(file(base, "rb").readlines(), 
32
 
                    file(filename, "rb").readlines(), 
33
 
                    file(other, "rb").readlines())
 
30
            base = self.other
 
31
            other = self.base
 
32
        def get_lines(tree):
 
33
            if self.file_id not in tree:
 
34
                raise Exception("%s not in tree" % self.file_id)
 
35
                return ()
 
36
            return tree.get_file(self.file_id).readlines()
 
37
        base_lines = get_lines(base)
 
38
        other_lines = get_lines(other)
 
39
        m3 = Merge3(base_lines, file(filename, "rb").readlines(), other_lines)
34
40
 
35
41
        new_conflicts = False
36
42
        output_file = file(new_file, "wb")
48
54
            os.rename(new_file, filename)
49
55
            return
50
56
        else:
51
 
            conflict_handler.merge_conflict(new_file, filename, base, other)
 
57
            conflict_handler.merge_conflict(new_file, filename, base_lines,
 
58
                                            other_lines)
52
59
 
53
60
 
54
61
class BackupBeforeChange:
197
204
        if this_path is None:
198
205
            return conflict_handler.missing_for_merge(entry.id, 
199
206
                                                      other.id2path(entry.id))
200
 
        base_path = base.readonly_path(entry.id)
201
 
        other_path = other.readonly_path(entry.id)    
202
 
        return merge_factory(base_path, other_path)
 
207
        return merge_factory(entry.id, base, other)
203
208
 
204
209
    if isinstance(contents, changeset.ReplaceContents):
205
210
        if contents.old_contents is None and contents.new_contents is None:
336
341
    def __contains__(self, file_id):
337
342
        return file_id in self.inventory
338
343
 
 
344
    def get_file(self, file_id):
 
345
        path = self.readonly_path(file_id)
 
346
        return file(path, "rb")
 
347
 
339
348
    def id2path(self, file_id):
340
349
        return self.inventory[file_id]
341
350
 
605
614
 
606
615
    def test_contents_merge3(self):
607
616
        """Test diff3 merging"""
608
 
        def backup_merge(base_file, other_file):
609
 
            return BackupBeforeChange(ApplyMerge3(base_file, other_file))
 
617
        def backup_merge(file_id, base, other):
 
618
            return BackupBeforeChange(ApplyMerge3(file_id, base, other))
610
619
        builder = self.contents_test_success(backup_merge)
611
620
        def backup_exists(file_id):
612
621
            return os.path.exists(builder.this.full_path(file_id)+"~")