Edgewall Software

Ticket #8538: filename_encoding-mercurial-0.11-r7849.diff

File filename_encoding-mercurial-0.11-r7849.diff, 3.6 KB (added by cboos, 3 years ago)

minimal fix - not very well tested

  • tracext/hg/backend.py

     
    291291 
    292292    def __init__(self, path, log, ui, options): 
    293293        self.ui = ui 
     294        self.filename_encoding = options.get('filename_encoding') 
    294295        # TODO: per repository ui and options? 
     296        # Note: here we're dealing with the local fs encoding, 
     297        #       not necessarily the same as the filename_encoding 
    295298        if isinstance(path, unicode): 
    296299            str_path = path.encode('utf-8') 
    297300            if not os.path.exists(str_path): 
     
    350353        else: 
    351354            return nodestr 
    352355 
     356    def _hgpath_to_unicode(self, path): 
     357        """Convert a Mercurial filename (bytes) to unicode using configured 
     358           encoding. 
     359        """ 
     360        return to_unicode(path, self.filename_encoding) 
     361 
     362    def _unicode_to_hgpath(self, path): 
     363        """Convert a path in unicode to a Mercurial filename (bytes) using  
     364           configured encoding. 
     365        """ 
     366        if isinstance(path, unicode): 
     367            path = path.encode(self.filename_encoding or 'utf-8', 'replace') 
     368        return path 
     369 
    353370    def close(self): 
    354371        self.repo = None 
    355372 
     
    584601        self.manifest = manifest 
    585602        self._dirnode = dirnode 
    586603 
    587         if isinstance(path, unicode): 
    588             try: 
    589                 self._init_path(log, path.encode('utf-8')) 
    590             except NoSuchNode: 
    591                 self._init_path(log, path.encode('latin-1')) 
    592                 # TODO: configurable charset for the repository, i.e. #3809 
    593         else: 
    594             self._init_path(log, path) 
     604        self._init_path(log, path) 
    595605 
    596606    def findnode(self, n_rev, dirnames): 
    597607        dirnodes = {} 
    598608        log = self.repos.repo.changelog 
    599609        for rev in xrange(n_rev, -1, -1): 
    600610            for f in self.repos.repo.changectx(rev).files(): 
     611                f = self.repos._hgpath_to_unicode(f) 
    601612                for d in dirnames[:]: 
    602613                    if f.startswith(d): 
    603614                        dirnodes[d] = log.node(rev) 
     
    612623 
    613624    def _init_path(self, log, path): 
    614625        kind = None 
    615         if path in self.manifest: # then it's a file 
     626        hgpath = self.repos._unicode_to_hgpath(path) 
     627        if hgpath in self.manifest: 
     628            # it's a file 
    616629            kind = Node.FILE 
    617             self.filectx = self.repos.repo.filectx(path, self.n) 
     630            self.filectx = self.repos.repo.filectx(hgpath, self.n) 
    618631            log_rev = self.filectx.linkrev() 
    619632            node = log.node(log_rev) 
    620         else: # it will be a directory if there are matching entries 
     633        else: 
     634            # it will be a directory if there are matching entries 
    621635            dir = path and path+'/' or '' 
    622636            entries = {} 
    623             for file in self.manifest.keys(): 
     637            for hgfile in self.manifest.keys(): 
     638                file = self.repos._hgpath_to_unicode(hgfile) 
    624639                if file.startswith(dir): 
    625640                    entry = file[len(dir):].split('/', 1)[0] 
    626641                    entries[entry] = 1 
     
    633648                        node = self._dirnode 
    634649                    else: 
    635650                        # we find the most recent change for a file below dir 
    636                         node = self.findnode(log.rev(self.n), [dir,] ).values()[0] 
     651                        node = self.findnode(log.rev(self.n), 
     652                                             [dir,]).values()[0] 
    637653                else: 
    638654                    node = log.tip() 
    639655        if not kind: