/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/diff.py

  • Committer: Robert Collins
  • Date: 2008-01-03 21:02:06 UTC
  • mfrom: (3162 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3163.
  • Revision ID: robertc@robertcollins.net-20080103210206-eqvta89m37jgjjfi
Resolve conflicts with bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
773
773
        return [t % my_map for t in self.command_template]
774
774
 
775
775
    def _execute(self, old_path, new_path):
776
 
        proc = subprocess.Popen(self._get_command(old_path, new_path),
777
 
                                stdout=subprocess.PIPE, cwd=self._root)
 
776
        command = self._get_command(old_path, new_path)
 
777
        try:
 
778
            proc = subprocess.Popen(command, stdout=subprocess.PIPE,
 
779
                                    cwd=self._root)
 
780
        except OSError, e:
 
781
            if e.errno == errno.ENOENT:
 
782
                raise errors.ExecutableMissing(command[0])
 
783
            else:
 
784
                raise
778
785
        self.to_file.write(proc.stdout.read())
779
786
        return proc.wait()
780
787
 
781
 
    def _write_file(self, file_id, tree, prefix, old_path):
782
 
        full_old_path = osutils.pathjoin(self._root, prefix, old_path)
783
 
        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)
784
804
        try:
785
805
            os.makedirs(parent_dir)
786
806
        except OSError, e:
787
807
            if e.errno != errno.EEXIST:
788
808
                raise
789
 
        source = tree.get_file(file_id)
 
809
        source = tree.get_file(file_id, relpath)
790
810
        try:
791
 
            target = open(full_old_path, 'wb')
 
811
            target = open(full_path, 'wb')
792
812
            try:
793
813
                osutils.pumpfile(source, target)
794
814
            finally:
795
815
                target.close()
796
816
        finally:
797
817
            source.close()
798
 
        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
799
822
 
800
823
    def _prepare_files(self, file_id, old_path, new_path):
801
824
        old_disk_path = self._write_file(file_id, self.old_tree, 'old',
805
828
        return old_disk_path, new_disk_path
806
829
 
807
830
    def finish(self):
808
 
        shutil.rmtree(self._root)
 
831
        osutils.rmtree(self._root)
809
832
 
810
833
    def diff(self, file_id, old_path, new_path, old_kind, new_kind):
811
834
        if (old_kind, new_kind) != ('file', 'file'):