/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

Merge up with bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
388
388
 
389
389
    other_paths = []
390
390
    make_paths_wt_relative = True
 
391
    consider_relpath = True
391
392
    if path_list is None or len(path_list) == 0:
392
 
        # If no path is given, assume the current directory
 
393
        # If no path is given, the current working tree is used
393
394
        default_location = u'.'
 
395
        consider_relpath = False
394
396
    elif old_url is not None and new_url is not None:
395
397
        other_paths = path_list
396
398
        make_paths_wt_relative = False
404
406
        old_url = default_location
405
407
    working_tree, branch, relpath = \
406
408
        bzrdir.BzrDir.open_containing_tree_or_branch(old_url)
407
 
    if relpath != '':
 
409
    if consider_relpath and relpath != '':
408
410
        specific_files.append(relpath)
409
411
    old_tree = _get_tree_to_diff(old_revision_spec, working_tree, branch)
410
412
 
414
416
    if new_url != old_url:
415
417
        working_tree, branch, relpath = \
416
418
            bzrdir.BzrDir.open_containing_tree_or_branch(new_url)
417
 
        if relpath != '':
 
419
        if consider_relpath and relpath != '':
418
420
            specific_files.append(relpath)
419
421
    new_tree = _get_tree_to_diff(new_revision_spec, working_tree, branch,
420
422
        basis_is_default=working_tree is None)
773
775
        return [t % my_map for t in self.command_template]
774
776
 
775
777
    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)
 
778
        command = self._get_command(old_path, new_path)
 
779
        try:
 
780
            proc = subprocess.Popen(command, stdout=subprocess.PIPE,
 
781
                                    cwd=self._root)
 
782
        except OSError, e:
 
783
            if e.errno == errno.ENOENT:
 
784
                raise errors.ExecutableMissing(command[0])
 
785
            else:
 
786
                raise
778
787
        self.to_file.write(proc.stdout.read())
779
788
        return proc.wait()
780
789
 
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)
 
790
    def _try_symlink_root(self, tree, prefix):
 
791
        if not (getattr(tree, 'abspath', None) is not None
 
792
                and osutils.has_symlinks()):
 
793
            return False
 
794
        try:
 
795
            os.symlink(tree.abspath(''), osutils.pathjoin(self._root, prefix))
 
796
        except OSError, e:
 
797
            if e.errno != errno.EEXIST:
 
798
                raise
 
799
        return True
 
800
 
 
801
    def _write_file(self, file_id, tree, prefix, relpath):
 
802
        full_path = osutils.pathjoin(self._root, prefix, relpath)
 
803
        if self._try_symlink_root(tree, prefix):
 
804
            return full_path
 
805
        parent_dir = osutils.dirname(full_path)
784
806
        try:
785
807
            os.makedirs(parent_dir)
786
808
        except OSError, e:
787
809
            if e.errno != errno.EEXIST:
788
810
                raise
789
 
        source = tree.get_file(file_id)
 
811
        source = tree.get_file(file_id, relpath)
790
812
        try:
791
 
            target = open(full_old_path, 'wb')
 
813
            target = open(full_path, 'wb')
792
814
            try:
793
815
                osutils.pumpfile(source, target)
794
816
            finally:
795
817
                target.close()
796
818
        finally:
797
819
            source.close()
798
 
        return full_old_path
 
820
        osutils.make_readonly(full_path)
 
821
        mtime = tree.get_file_mtime(file_id)
 
822
        os.utime(full_path, (mtime, mtime))
 
823
        return full_path
799
824
 
800
825
    def _prepare_files(self, file_id, old_path, new_path):
801
826
        old_disk_path = self._write_file(file_id, self.old_tree, 'old',
805
830
        return old_disk_path, new_disk_path
806
831
 
807
832
    def finish(self):
808
 
        shutil.rmtree(self._root)
 
833
        osutils.rmtree(self._root)
809
834
 
810
835
    def diff(self, file_id, old_path, new_path, old_kind, new_kind):
811
836
        if (old_kind, new_kind) != ('file', 'file'):