~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-01-03 16:01:06 UTC
  • mfrom: (3123.6.8 no-inventory2)
  • Revision ID: pqm@pqm.ubuntu.com-20080103160106-v6qfwv4ta8sorx1q
diff --using uses symlinks if possible,
        marks temp files read-only (abentley)

Show diffs side-by-side

added added

removed removed

Lines of Context:
785
785
        self.to_file.write(proc.stdout.read())
786
786
        return proc.wait()
787
787
 
788
 
    def _write_file(self, file_id, tree, prefix, old_path):
789
 
        full_old_path = osutils.pathjoin(self._root, prefix, old_path)
790
 
        parent_dir = osutils.dirname(full_old_path)
 
788
    def _try_symlink_root(self, tree, prefix):
 
789
        if not (getattr(tree, 'abspath', None) is not None
 
790
                and osutils.has_symlinks()):
 
791
            return False
 
792
        try:
 
793
            os.symlink(tree.abspath(''), osutils.pathjoin(self._root, prefix))
 
794
        except OSError, e:
 
795
            if e.errno != errno.EEXIST:
 
796
                raise
 
797
        return True
 
798
 
 
799
    def _write_file(self, file_id, tree, prefix, relpath):
 
800
        full_path = osutils.pathjoin(self._root, prefix, relpath)
 
801
        if self._try_symlink_root(tree, prefix):
 
802
            return full_path
 
803
        parent_dir = osutils.dirname(full_path)
791
804
        try:
792
805
            os.makedirs(parent_dir)
793
806
        except OSError, e:
794
807
            if e.errno != errno.EEXIST:
795
808
                raise
796
 
        source = tree.get_file(file_id)
 
809
        source = tree.get_file(file_id, relpath)
797
810
        try:
798
 
            target = open(full_old_path, 'wb')
 
811
            target = open(full_path, 'wb')
799
812
            try:
800
813
                osutils.pumpfile(source, target)
801
814
            finally:
802
815
                target.close()
803
816
        finally:
804
817
            source.close()
805
 
        return full_old_path
 
818
        osutils.make_readonly(full_path)
 
819
        mtime = tree.get_file_mtime(file_id)
 
820
        os.utime(full_path, (mtime, mtime))
 
821
        return full_path
806
822
 
807
823
    def _prepare_files(self, file_id, old_path, new_path):
808
824
        old_disk_path = self._write_file(file_id, self.old_tree, 'old',
812
828
        return old_disk_path, new_disk_path
813
829
 
814
830
    def finish(self):
815
 
        shutil.rmtree(self._root)
 
831
        osutils.rmtree(self._root)
816
832
 
817
833
    def diff(self, file_id, old_path, new_path, old_kind, new_kind):
818
834
        if (old_kind, new_kind) != ('file', 'file'):