Mercurial > public > mercurial-scm > hg
comparison mercurial/localrepo.py @ 13047:6c375e07d673
branch: operate on branch names in local string space where possible
Previously, branch names were ideally manipulated as UTF-8 strings,
because they were stored as UTF-8 in the dirstate and the changelog
and could not be safely converted to the local encoding and back.
However, only about 80% of branch name code was actually using the
right encoding conventions. This patch uses the localstr addition to
allow working on branch names as local strings, which simplifies
handling so that the previously incorrect code becomes correct.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 24 Nov 2010 15:56:32 -0600 |
parents | 9beac11b8c56 |
children | d73c3034deee |
comparison
equal
deleted
inserted
replaced
13046:7cc4263e07a9 | 13047:6c375e07d673 |
---|---|
103 # heads, and local tags are defined in .hg/localtags.) They | 103 # heads, and local tags are defined in .hg/localtags.) They |
104 # constitute the in-memory cache of tags. | 104 # constitute the in-memory cache of tags. |
105 self._tags = None | 105 self._tags = None |
106 self._tagtypes = None | 106 self._tagtypes = None |
107 | 107 |
108 self._branchcache = None # in UTF-8 | 108 self._branchcache = None |
109 self._branchcachetip = None | 109 self._branchcachetip = None |
110 self.nodetagscache = None | 110 self.nodetagscache = None |
111 self.filterpats = {} | 111 self.filterpats = {} |
112 self._datafilters = {} | 112 self._datafilters = {} |
113 self._transref = self._lockref = self._wlockref = None | 113 self._transref = self._lockref = self._wlockref = None |
433 tip = h | 433 tip = h |
434 break | 434 break |
435 bt[bn] = tip | 435 bt[bn] = tip |
436 return bt | 436 return bt |
437 | 437 |
438 | |
439 def _readbranchcache(self): | 438 def _readbranchcache(self): |
440 partial = {} | 439 partial = {} |
441 try: | 440 try: |
442 f = self.opener("branchheads.cache") | 441 f = self.opener("branchheads.cache") |
443 lines = f.read().split('\n') | 442 lines = f.read().split('\n') |
453 raise ValueError('invalidating branch cache (tip differs)') | 452 raise ValueError('invalidating branch cache (tip differs)') |
454 for l in lines: | 453 for l in lines: |
455 if not l: | 454 if not l: |
456 continue | 455 continue |
457 node, label = l.split(" ", 1) | 456 node, label = l.split(" ", 1) |
458 partial.setdefault(label.strip(), []).append(bin(node)) | 457 label = encoding.tolocal(label.strip()) |
458 partial.setdefault(label, []).append(bin(node)) | |
459 except KeyboardInterrupt: | 459 except KeyboardInterrupt: |
460 raise | 460 raise |
461 except Exception, inst: | 461 except Exception, inst: |
462 if self.ui.debugflag: | 462 if self.ui.debugflag: |
463 self.ui.warn(str(inst), '\n') | 463 self.ui.warn(str(inst), '\n') |
468 try: | 468 try: |
469 f = self.opener("branchheads.cache", "w", atomictemp=True) | 469 f = self.opener("branchheads.cache", "w", atomictemp=True) |
470 f.write("%s %s\n" % (hex(tip), tiprev)) | 470 f.write("%s %s\n" % (hex(tip), tiprev)) |
471 for label, nodes in branches.iteritems(): | 471 for label, nodes in branches.iteritems(): |
472 for node in nodes: | 472 for node in nodes: |
473 f.write("%s %s\n" % (hex(node), label)) | 473 f.write("%s %s\n" % (hex(node), encoding.fromlocal(label))) |
474 f.rename() | 474 f.rename() |
475 except (IOError, OSError): | 475 except (IOError, OSError): |
476 pass | 476 pass |
477 | 477 |
478 def _updatebranchcache(self, partial, ctxgen): | 478 def _updatebranchcache(self, partial, ctxgen): |
657 try: | 657 try: |
658 ds = self.opener("dirstate").read() | 658 ds = self.opener("dirstate").read() |
659 except IOError: | 659 except IOError: |
660 ds = "" | 660 ds = "" |
661 self.opener("journal.dirstate", "w").write(ds) | 661 self.opener("journal.dirstate", "w").write(ds) |
662 self.opener("journal.branch", "w").write(self.dirstate.branch()) | 662 self.opener("journal.branch", "w").write( |
663 encoding.fromlocal(self.dirstate.branch())) | |
663 self.opener("journal.desc", "w").write("%d\n%s\n" % (len(self), desc)) | 664 self.opener("journal.desc", "w").write("%d\n%s\n" % (len(self), desc)) |
664 | 665 |
665 renames = [(self.sjoin("journal"), self.sjoin("undo")), | 666 renames = [(self.sjoin("journal"), self.sjoin("undo")), |
666 (self.join("journal.dirstate"), self.join("undo.dirstate")), | 667 (self.join("journal.dirstate"), self.join("undo.dirstate")), |
667 (self.join("journal.branch"), self.join("undo.branch")), | 668 (self.join("journal.branch"), self.join("undo.branch")), |
715 branch = self.opener("undo.branch").read() | 716 branch = self.opener("undo.branch").read() |
716 self.dirstate.setbranch(branch) | 717 self.dirstate.setbranch(branch) |
717 except IOError: | 718 except IOError: |
718 self.ui.warn(_("Named branch could not be reset, " | 719 self.ui.warn(_("Named branch could not be reset, " |
719 "current branch still is: %s\n") | 720 "current branch still is: %s\n") |
720 % encoding.tolocal(self.dirstate.branch())) | 721 % self.dirstate.branch()) |
721 self.invalidate() | 722 self.invalidate() |
722 self.dirstate.invalidate() | 723 self.dirstate.invalidate() |
723 self.destroyed() | 724 self.destroyed() |
724 else: | 725 else: |
725 self.ui.warn(_("no rollback information available\n")) | 726 self.ui.warn(_("no rollback information available\n")) |