/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/changeset.py

  • Committer: abentley
  • Date: 2005-10-14 01:53:07 UTC
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1460.
  • Revision ID: abentley@lappy-20051014015307-8b917f78d9f61b99
Avoided readonly_path in ApplyDiff3

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import errno
18
18
import patch
19
19
import stat
 
20
from tempfile import mkdtemp
 
21
from shutil import rmtree
20
22
from bzrlib.trace import mutter
21
23
from bzrlib.osutils import rename, sha_file
22
24
import bzrlib
429
431
    def __ne__(self, other):
430
432
        return not (self == other)
431
433
 
 
434
    def dump_file(self, temp_dir, name, tree):
 
435
        out_path = os.path.join(temp_dir, name)
 
436
        out_file = file(out_path, "wb")
 
437
        in_file = tree.get_file(self.file_id)
 
438
        for line in in_file:
 
439
            out_file.write(line)
 
440
        return out_path
 
441
 
432
442
    def apply(self, filename, conflict_handler, reverse=False):
433
 
        new_file = filename+".new"
434
 
        base_file = self.base.readonly_path(self.file_id)
435
 
        other_file = self.other.readonly_path(self.file_id)
436
 
        if not reverse:
437
 
            base = base_file
438
 
            other = other_file
439
 
        else:
440
 
            base = other_file
441
 
            other = base_file
442
 
        status = patch.diff3(new_file, filename, base, other)
443
 
        if status == 0:
444
 
            os.chmod(new_file, os.stat(filename).st_mode)
445
 
            rename(new_file, filename)
446
 
            return
447
 
        else:
448
 
            assert(status == 1)
449
 
            def get_lines(filename):
450
 
                my_file = file(filename, "rb")
451
 
                lines = my_file.readlines()
452
 
                my_file.close()
453
 
                return lines
454
 
            base_lines = get_lines(base)
455
 
            other_lines = get_lines(other)
456
 
            conflict_handler.merge_conflict(new_file, filename, base_lines, 
457
 
                                            other_lines)
 
443
        temp_dir = mkdtemp(prefix="bzr-")
 
444
        try:
 
445
            new_file = filename+".new"
 
446
            base_file = self.dump_file(temp_dir, "base", self.base)
 
447
            other_file = self.dump_file(temp_dir, "other", self.other)
 
448
            if not reverse:
 
449
                base = base_file
 
450
                other = other_file
 
451
            else:
 
452
                base = other_file
 
453
                other = base_file
 
454
            status = patch.diff3(new_file, filename, base, other)
 
455
            if status == 0:
 
456
                os.chmod(new_file, os.stat(filename).st_mode)
 
457
                rename(new_file, filename)
 
458
                return
 
459
            else:
 
460
                assert(status == 1)
 
461
                def get_lines(filename):
 
462
                    my_file = file(filename, "rb")
 
463
                    lines = my_file.readlines()
 
464
                    my_file.close()
 
465
                    return lines
 
466
                base_lines = get_lines(base)
 
467
                other_lines = get_lines(other)
 
468
                conflict_handler.merge_conflict(new_file, filename, base_lines, 
 
469
                                                other_lines)
 
470
        finally:
 
471
            rmtree(temp_dir)
458
472
 
459
473
 
460
474
def CreateDir():