~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: INADA Naoki
  • Date: 2010-03-03 12:14:16 UTC
  • mfrom: (4634.171.4 fix-523746-2)
  • mto: This revision was merged to the branch mainline in revision 5892.
  • Revision ID: inada-n@klab.jp-20100303121416-uemvz4l5y1ilclv6
merge #523746 fix from lp:~songofacandy/bzr/fix-523746-2

Show diffs side-by-side

added added

removed removed

Lines of Context:
698
698
 
699
699
    def _get_command(self, old_path, new_path):
700
700
        my_map = {'old_path': old_path, 'new_path': new_path}
701
 
        return [AtTemplate(t).substitute(my_map) for t in
702
 
                self.command_template]
 
701
        command = [AtTemplate(t).substitute(my_map) for t in
 
702
                   self.command_template]
 
703
        if sys.platform == 'win32': # Popen doesn't accept unicode on win32
 
704
            command_encoded = []
 
705
            for c in command:
 
706
                if isinstance(c, unicode):
 
707
                    command_encoded.append(c.encode('mbcs'))
 
708
                else:
 
709
                    command_encoded.append(c)
 
710
            return command_encoded
 
711
        else:
 
712
            return command
703
713
 
704
714
    def _execute(self, old_path, new_path):
705
715
        command = self._get_command(old_path, new_path)
729
739
                    allow_write=False):
730
740
        if not force_temp and isinstance(tree, WorkingTree):
731
741
            return tree.abspath(tree.id2path(file_id))
732
 
        
733
 
        full_path = osutils.pathjoin(self._root, prefix, relpath)
 
742
 
 
743
        if sys.platform == 'win32':
 
744
            fenc = 'mbcs'
 
745
        else:
 
746
            fenc = sys.getfilesystemencoding() or 'ascii'
 
747
        # encoded_str.replace('?', '_') may break multibyte char.
 
748
        # So we should encode, decode, then replace(u'?', u'_')
 
749
        relpath_tmp = relpath.encode(fenc, 'replace').decode(fenc, 'replace')
 
750
        relpath_tmp = relpath_tmp.replace(u'?', u'_')
 
751
        full_path = osutils.pathjoin(self._root, prefix, relpath_tmp)
734
752
        if not force_temp and self._try_symlink_root(tree, prefix):
735
753
            return full_path
736
754
        parent_dir = osutils.dirname(full_path)
792
810
        """
793
811
        old_path = self.old_tree.id2path(file_id)
794
812
        new_path = self.new_tree.id2path(file_id)
795
 
        new_abs_path = self._prepare_files(file_id, old_path, new_path,
796
 
                                           allow_write_new=True,
797
 
                                           force_temp=True)[1]
798
 
        command = self._get_command(osutils.pathjoin('old', old_path),
799
 
                                    osutils.pathjoin('new', new_path))
 
813
        old_abs_path, new_abs_path = self._prepare_files(
 
814
                                            file_id, old_path, new_path,
 
815
                                            allow_write_new=True,
 
816
                                            force_temp=True)
 
817
        command = self._get_command(old_abs_path, new_abs_path)
800
818
        subprocess.call(command, cwd=self._root)
801
 
        new_file = open(new_abs_path, 'r')
 
819
        new_file = open(new_abs_path, 'rb')
802
820
        try:
803
821
            return new_file.read()
804
822
        finally: