~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/changeset.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:
319
319
 
320
320
 
321
321
class Diff3Merge(object):
322
 
    def __init__(self, base_file, other_file):
323
 
        self.base_file = base_file
324
 
        self.other_file = other_file
 
322
    def __init__(self, file_id, base, other):
 
323
        self.file_id = file_id
 
324
        self.base = base
 
325
        self.other = other
325
326
 
326
327
    def __eq__(self, other):
327
328
        if not isinstance(other, Diff3Merge):
328
329
            return False
329
 
        return (self.base_file == other.base_file and 
330
 
                self.other_file == other.other_file)
 
330
        return (self.base == other.base and 
 
331
                self.other == other.other and self.file_id == other.file_id)
331
332
 
332
333
    def __ne__(self, other):
333
334
        return not (self == other)
334
335
 
335
336
    def apply(self, filename, conflict_handler, reverse=False):
336
 
        new_file = filename+".new" 
 
337
        new_file = filename+".new"
 
338
        base_file = self.base.readonly_path(self.file_id)
 
339
        other_file = self.other.readonly_path(self.file_id)
337
340
        if not reverse:
338
 
            base = self.base_file
339
 
            other = self.other_file
 
341
            base = base_file
 
342
            other = other_file
340
343
        else:
341
 
            base = self.other_file
342
 
            other = self.base_file
 
344
            base = other_file
 
345
            other = base_file
343
346
        status = patch.diff3(new_file, filename, base, other)
344
347
        if status == 0:
345
348
            os.chmod(new_file, os.stat(filename).st_mode)
347
350
            return
348
351
        else:
349
352
            assert(status == 1)
350
 
            conflict_handler.merge_conflict(new_file, filename, base, other)
 
353
            def get_lines(filename):
 
354
                my_file = file(base, "rb")
 
355
                lines = my_file.readlines()
 
356
                my_file.close()
 
357
            base_lines = get_lines(base)
 
358
            other_lines = get_lines(other)
 
359
            conflict_handler.merge_conflict(new_file, filename, base_lines, 
 
360
                                            other_lines)
351
361
 
352
362
 
353
363
def CreateDir():
1002
1012
    def move_conflict(self, id, this_dir, base_dir, other_dir):
1003
1013
        raise MoveConflict(id, this_dir, base_dir, other_dir)
1004
1014
 
1005
 
    def merge_conflict(self, new_file, this_path, base_path, other_path):
 
1015
    def merge_conflict(self, new_file, this_path, base_lines, other_lines):
1006
1016
        os.unlink(new_file)
1007
1017
        raise MergeConflict(this_path)
1008
1018