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) |
|---|
-
tracext/hg/backend.py
291 291 292 292 def __init__(self, path, log, ui, options): 293 293 self.ui = ui 294 self.filename_encoding = options.get('filename_encoding') 294 295 # 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 295 298 if isinstance(path, unicode): 296 299 str_path = path.encode('utf-8') 297 300 if not os.path.exists(str_path): … … 350 353 else: 351 354 return nodestr 352 355 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 353 370 def close(self): 354 371 self.repo = None 355 372 … … 584 601 self.manifest = manifest 585 602 self._dirnode = dirnode 586 603 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) 595 605 596 606 def findnode(self, n_rev, dirnames): 597 607 dirnodes = {} 598 608 log = self.repos.repo.changelog 599 609 for rev in xrange(n_rev, -1, -1): 600 610 for f in self.repos.repo.changectx(rev).files(): 611 f = self.repos._hgpath_to_unicode(f) 601 612 for d in dirnames[:]: 602 613 if f.startswith(d): 603 614 dirnodes[d] = log.node(rev) … … 612 623 613 624 def _init_path(self, log, path): 614 625 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 616 629 kind = Node.FILE 617 self.filectx = self.repos.repo.filectx( path, self.n)630 self.filectx = self.repos.repo.filectx(hgpath, self.n) 618 631 log_rev = self.filectx.linkrev() 619 632 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 621 635 dir = path and path+'/' or '' 622 636 entries = {} 623 for file in self.manifest.keys(): 637 for hgfile in self.manifest.keys(): 638 file = self.repos._hgpath_to_unicode(hgfile) 624 639 if file.startswith(dir): 625 640 entry = file[len(dir):].split('/', 1)[0] 626 641 entries[entry] = 1 … … 633 648 node = self._dirnode 634 649 else: 635 650 # 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] 637 653 else: 638 654 node = log.tip() 639 655 if not kind:
