Changeset 1016 in tailor


Ignore:
Timestamp:
11/19/05 16:08:58 (8 years ago)
Author:
lele@…
Hash name:
20051119150858-7a6fb-ef43cb57dcf40ce1a126b2d340e464d332ca57f2
Message:

Use the new encode facility of the Repository

Location:
vcpx
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • vcpx/cvsps.py

    r1007 r1016  
    524524 
    525525        from shwrap import ReopenableNamedTemporaryFile 
    526         from locale import getpreferredencoding 
    527  
    528         encoding = ExternalCommand.FORCE_ENCODING or getpreferredencoding() 
     526 
     527        encode = self.repository.encode 
    529528 
    530529        logmessage = [] 
    531530        if patchname: 
    532             logmessage.append(patchname.encode(encoding)) 
     531            logmessage.append(patchname) 
    533532        if changelog: 
    534             logmessage.append(changelog.encode(encoding)) 
     533            logmessage.append(changelog) 
    535534        logmessage.append('') 
    536         logmessage.append('Original author: %s' % author.encode(encoding)) 
     535        logmessage.append('Original author: %s' % author) 
    537536        logmessage.append('Date: %s' % date) 
    538537 
    539538        rontf = ReopenableNamedTemporaryFile('cvs', 'tailor') 
    540539        log = open(rontf.name, "w") 
    541         log.write('\n'.join(logmessage)) 
     540        log.write(encode('\n'.join(logmessage))) 
    542541        log.close() 
    543542 
  • vcpx/darcs.py

    r1010 r1016  
    455455 
    456456        record = ExternalCommand(cwd=self.basedir, command=cmd) 
    457         record.execute(input='\n'.join(logmessage)) 
     457        record.execute(input=self.repository.encode('\n'.join(logmessage))) 
    458458 
    459459        if record.exit_status: 
  • vcpx/svn.py

    r1007 r1016  
    409409        """ 
    410410 
    411         from locale import getpreferredencoding 
    412  
    413         encoding = ExternalCommand.FORCE_ENCODING or getpreferredencoding() 
     411        encode = self.repository.encode 
    414412 
    415413        logmessage = [] 
    416414        if patchname: 
    417             logmessage.append(patchname.encode(encoding)) 
     415            logmessage.append(patchname) 
    418416        if changelog: 
    419             logmessage.append(changelog.encode(encoding)) 
     417            logmessage.append(changelog) 
    420418 
    421419        # If we cannot use propset, fall back to old behaviour of 
     
    424422        if not self.USE_PROPSET: 
    425423            logmessage.append('') 
    426             logmessage.append('Original author: %s' % author.encode(encoding)) 
     424            logmessage.append('Original author: %s' % encode(author)) 
    427425            logmessage.append('Date: %s' % date) 
    428426 
    429427        rontf = ReopenableNamedTemporaryFile('svn', 'tailor') 
    430428        log = open(rontf.name, "w") 
    431         log.write('\n'.join(logmessage)) 
     429        log.write(encode('\n'.join(logmessage))) 
    432430        log.close() 
    433431 
     
    472470 
    473471            propset.execute(date.isoformat()+".000000Z", propname='svn:date') 
    474             propset.execute(author.encode(encoding), propname='svn:author') 
     472            propset.execute(encode(author), propname='svn:author') 
    475473 
    476474        cmd = self.repository.command("update", "--quiet", 
  • vcpx/shwrap.py

    r987 r1016  
    4949    DRY_RUN = False 
    5050    """Don't really execute the command.""" 
    51  
    52     FORCE_ENCODING = None 
    53     """Force the output encoding to some other charset instead of user prefs.""" 
    5451 
    5552    def __init__(self, command=None, cwd=None): 
     
    201198 
    202199        if input and isinstance(input, unicode): 
    203             input = input.encode(self.FORCE_ENCODING or getpreferredencoding()) 
     200            encoding = getpreferredencoding() 
     201            self.log.warning("Using default %s encoding, ignoring errors; " 
     202                             "caller should use repository's encoding and " 
     203                             "pass an already encoded input") 
     204            input = input.encode(encoding, 'ignore') 
    204205 
    205206        out, err = process.communicate(input=input) 
  • vcpx/tailor.py

    r988 r1016  
    126126        from target import SyncronizableTargetWorkingDir 
    127127        from changes import Changeset 
    128         from locale import getpreferredencoding 
    129128 
    130129        def pconfig(option, raw=False): 
     
    132131 
    133132        ExternalCommand.DEBUG = pconfig('debug') 
    134         encoding = pconfig('encoding') 
    135         if encoding: 
    136             ExternalCommand.FORCE_ENCODING = encoding 
    137  
    138             # Make printouts be encoded as well. A better solution would be 
    139             # using the replace mechanism of the encoder, and keep printing 
    140             # in the user's LC_CTYPE/LANG setting. 
    141  
    142             import codecs, sys 
    143             sys.stdout = codecs.getwriter(encoding)(sys.stdout) 
    144         else: 
    145             encoding = getpreferredencoding() 
    146133 
    147134        pname_format = pconfig('patch-name-format', raw=True) 
     
    158145            self.update() 
    159146        except UnicodeEncodeError, exc: 
    160             raise ConfigurationError('%s: it seems that current encoding "%s" ' 
     147            raise ConfigurationError('%s: it seems that the encoding ' 
     148                                     'used by either the source ("%s") or the ' 
     149                                     'target ("%s") repository ' 
    161150                                     'cannot properly represent at least one ' 
    162151                                     'of the characters in the upstream ' 
    163152                                     'changelog. You need to use a wider ' 
    164                                      'character set, using "encoding" option.' 
    165                                      % (exc, encoding)) 
     153                                     'character set, using "encoding" option, ' 
     154                                     'or even "encoding-errors-policy".' 
     155                                     % (exc, self.source.encoding, 
     156                                        self.target.encoding)) 
    166157 
    167158class RecogOption(Option): 
  • vcpx/monotone.py

    r1006 r1016  
    707707        """ 
    708708 
    709         from locale import getpreferredencoding 
    710  
    711         encoding = ExternalCommand.FORCE_ENCODING or getpreferredencoding() 
     709        encode = self.repository.encode 
    712710 
    713711        logmessage = [] 
    714712        if patchname: 
    715             logmessage.append(patchname.encode(encoding)) 
     713            logmessage.append(patchname) 
    716714        if changelog: 
    717             logmessage.append(changelog.encode(encoding)) 
     715            logmessage.append(changelog) 
    718716 
    719717        rontf = ReopenableNamedTemporaryFile('mtn', 'tailor') 
    720718        log = open(rontf.name, "w") 
    721         log.write('\n'.join(logmessage)) 
     719        log.write(encode('\n'.join(logmessage))) 
    722720        log.close() 
    723721 
    724722        cmd = self.repository.command("commit", 
    725                                       "--author", author.encode(encoding), 
     723                                      "--author", encode(author), 
    726724                                      "--date", date.isoformat(), 
    727725                                      "--message-file", rontf.name) 
  • vcpx/cdv.py

    r850 r1016  
    4444        """ 
    4545 
    46         from locale import getpreferredencoding 
    47  
    48         encoding = ExternalCommand.FORCE_ENCODING or getpreferredencoding() 
     46        encode = self.repository.encode 
    4947 
    5048        logmessage = [] 
    5149        if patchname: 
    52             logmessage.append(patchname.encode(encoding)) 
     50            logmessage.append(patchname) 
    5351        if changelog: 
    54             logmessage.append(changelog.replace('%', '%%').encode(encoding)) 
     52            logmessage.append(changelog.replace('%', '%%')) 
    5553 
    56         cmd = self.repository.command("-u", author.encode(encoding), "commit", 
    57                                       "-m", '\n'.join(logmessage), 
     54        cmd = self.repository.command("-u", encode(author), "commit", 
     55                                      "-m", encode('\n'.join(logmessage)), 
    5856                                      "-D", date.strftime('%Y/%m/%d %H:%M:%S UTC')) 
    5957 
  • vcpx/hg.py

    r992 r1016  
    4242 
    4343        from time import mktime 
    44         from locale import getpreferredencoding 
    4544 
    46         encoding = ExternalCommand.FORCE_ENCODING or getpreferredencoding() 
     45        encode = self.repository.encode 
    4746 
    4847        logmessage = [] 
    4948        if patchname: 
    50             logmessage.append(patchname.encode(encoding)) 
     49            logmessage.append(patchname) 
    5150        if changelog: 
    52             logmessage.append(changelog.encode(encoding)) 
     51            logmessage.append(changelog) 
    5352 
    54         cmd = self.repository.command("commit", "-u", author.encode(encoding), 
     53        cmd = self.repository.command("commit", "-u", encode(author), 
    5554                                      "-l", "%(logfile)s", 
    5655                                      "-d", "%(time)d 0") 
     
    5958        rontf = ReopenableNamedTemporaryFile('hg', 'tailor') 
    6059        log = open(rontf.name, "w") 
    61         log.write('\n'.join(logmessage) or "Empty changelog") 
     60        log.write(encode('\n'.join(logmessage)) or "Empty changelog") 
    6261        log.close() 
    6362 
  • vcpx/arx.py

    r850 r1016  
    3535 
    3636        from time import mktime 
    37         from locale import getpreferredencoding 
    3837 
    39         encoding = ExternalCommand.FORCE_ENCODING or getpreferredencoding() 
     38        encode = self.repository.encode 
    4039 
    4140        logmessage = [] 
    4241        if patchname: 
    43             logmessage.append(patchname.encode(encoding)) 
     42            logmessage.append(patchname) 
    4443        if changelog: 
    45             logmessage.append(changelog.replace('%', '%%').encode(encoding)) 
     44            logmessage.append(changelog.replace('%', '%%')) 
    4645 
    47         cmd = self.repository.command("commit", "-s", '\n'.join(logmessage), 
    48                                       "--author", author.encode(encoding), 
     46        cmd = self.repository.command("commit", 
     47                                      "-s", encode('\n'.join(logmessage)), 
     48                                      "--author", encode(author), 
    4949                                      "--date", date.isoformat()) 
    5050        c = ExternalCommand(cwd=self.basedir, command=cmd) 
  • vcpx/cg.py

    r992 r1016  
    6262        from os import environ 
    6363 
     64        encode = self.repository.encode 
     65 
    6466        logmessage = [] 
    6567        if patchname: 
     
    7375        (name, email) = self.__parse_author(author) 
    7476        if name: 
    75             env['GIT_AUTHOR_NAME']=name 
     77            env['GIT_AUTHOR_NAME'] = encode(name) 
    7678        if email: 
    7779            env['GIT_AUTHOR_EMAIL']=email 
     
    8385        c = ExternalCommand(cwd=self.basedir, command=cmd) 
    8486 
    85         c.execute(env=env, input='\n'.join(logmessage)) 
     87        c.execute(env=env, input=encode('\n'.join(logmessage))) 
    8688        if c.exit_status: 
    8789            raise ChangesetApplicationFailure("%s returned status %d" % 
     
    178180            ignore.write('\n') 
    179181        ignore.close() 
    180  
  • vcpx/git.py

    r1013 r1016  
    198198        from os import environ 
    199199 
     200        encode = self.repository.encode 
     201 
    200202        logmessage = [] 
    201203        if patchname: 
     
    209211        (name, email) = self.__parse_author(author) 
    210212        if name: 
    211             env['GIT_AUTHOR_NAME']=name 
    212             env['GIT_COMMITTER_NAME']=name 
     213            env['GIT_AUTHOR_NAME'] = encode(name) 
     214            env['GIT_COMMITTER_NAME'] = encode(name) 
    213215        if email: 
    214216            env['GIT_AUTHOR_EMAIL']=email 
     
    222224        c = ExternalCommand(cwd=self.basedir, command=cmd) 
    223225 
    224         logmessage = '\n'.join(logmessage) 
     226        logmessage = encode('\n'.join(logmessage)) 
    225227        if not logmessage.endswith('\n'): 
    226228            logmessage += '\n' 
  • vcpx/hglib.py

    r1008 r1016  
    185185        from time import mktime 
    186186 
    187         encoding = self.repository.encoding 
     187        encode = self.repository.encode 
    188188 
    189189        logmessage = [] 
     
    193193            logmessage.append(changelog) 
    194194        if logmessage: 
    195             logmessage = '\n'.join(logmessage).encode(encoding) 
     195            logmessage = encode('\n'.join(logmessage)) 
    196196        else: 
    197197            logmessage = "Empty changelog" 
    198         self._hg.commit(names and [n.encode(encoding) for n in names] or [], 
    199                         logmessage, author.encode(encoding), 
     198        self._hg.commit(names and [encode(n) for n in names] or [], 
     199                        logmessage, encode(author), 
    200200                        "%d 0" % mktime(date.timetuple())) 
    201201 
     
    208208        # This seems gross. I don't get why I'm getting a unicode tag when 
    209209        # it's just ascii underneath. Something weird is happening in CVS. 
    210         tag = tag.encode(self.repository.encoding) 
     210        tag = self.repository.encode(tag) 
     211 
    211212        # CVS can't tell when a tag was applied so it tends to pass around 
    212213        # too many. We want to support retagging so we can't just ignore 
Note: See TracChangeset for help on using the changeset viewer.