comparison mercurial/context.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 3da456d0c885
children 6bf39d88c857
comparison
equal deleted inserted replaced
13046:7cc4263e07a9 13047:6c375e07d673
5 # This software may be used and distributed according to the terms of the 5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 from node import nullid, nullrev, short, hex 8 from node import nullid, nullrev, short, hex
9 from i18n import _ 9 from i18n import _
10 import ancestor, bdiff, error, util, subrepo, patch 10 import ancestor, bdiff, error, util, subrepo, patch, encoding
11 import os, errno, stat 11 import os, errno, stat
12 12
13 propertycache = util.propertycache 13 propertycache = util.propertycache
14 14
15 class changectx(object): 15 class changectx(object):
107 def files(self): 107 def files(self):
108 return self._changeset[3] 108 return self._changeset[3]
109 def description(self): 109 def description(self):
110 return self._changeset[4] 110 return self._changeset[4]
111 def branch(self): 111 def branch(self):
112 return self._changeset[5].get("branch") 112 return encoding.tolocal(self._changeset[5].get("branch"))
113 def extra(self): 113 def extra(self):
114 return self._changeset[5] 114 return self._changeset[5]
115 def tags(self): 115 def tags(self):
116 return self._repo.nodetags(self._node) 116 return self._repo.nodetags(self._node)
117 117
589 589
590 self._extra = {} 590 self._extra = {}
591 if extra: 591 if extra:
592 self._extra = extra.copy() 592 self._extra = extra.copy()
593 if 'branch' not in self._extra: 593 if 'branch' not in self._extra:
594 branch = self._repo.dirstate.branch()
595 try: 594 try:
596 branch = branch.decode('UTF-8').encode('UTF-8') 595 branch = encoding.fromlocal(self._repo.dirstate.branch())
597 except UnicodeDecodeError: 596 except UnicodeDecodeError:
598 raise util.Abort(_('branch name not in UTF-8!')) 597 raise util.Abort(_('branch name not in UTF-8!'))
599 self._extra['branch'] = branch 598 self._extra['branch'] = branch
600 if self._extra['branch'] == '': 599 if self._extra['branch'] == '':
601 self._extra['branch'] = 'default' 600 self._extra['branch'] = 'default'
713 return self._ignored 712 return self._ignored
714 def clean(self): 713 def clean(self):
715 assert self._clean is not None # must call status first 714 assert self._clean is not None # must call status first
716 return self._clean 715 return self._clean
717 def branch(self): 716 def branch(self):
718 return self._extra['branch'] 717 return encoding.tolocal(self._extra['branch'])
719 def extra(self): 718 def extra(self):
720 return self._extra 719 return self._extra
721 720
722 def tags(self): 721 def tags(self):
723 t = [] 722 t = []
1046 def ignored(self): 1045 def ignored(self):
1047 return self._status[5] 1046 return self._status[5]
1048 def clean(self): 1047 def clean(self):
1049 return self._status[6] 1048 return self._status[6]
1050 def branch(self): 1049 def branch(self):
1051 return self._extra['branch'] 1050 return encoding.tolocal(self._extra['branch'])
1052 def extra(self): 1051 def extra(self):
1053 return self._extra 1052 return self._extra
1054 def flags(self, f): 1053 def flags(self, f):
1055 return self[f].flags() 1054 return self[f].flags()
1056 1055