comparison mercurial/wireproto.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 40bb5853fc4b
children d588326f6321
comparison
equal deleted inserted replaced
13046:7cc4263e07a9 13047:6c375e07d673
42 d = self._call("branchmap") 42 d = self._call("branchmap")
43 try: 43 try:
44 branchmap = {} 44 branchmap = {}
45 for branchpart in d.splitlines(): 45 for branchpart in d.splitlines():
46 branchname, branchheads = branchpart.split(' ', 1) 46 branchname, branchheads = branchpart.split(' ', 1)
47 branchname = urllib.unquote(branchname) 47 branchname = encoding.tolocal(urllib.unquote(branchname))
48 # Earlier servers (1.3.x) send branch names in (their) local
49 # charset. The best we can do is assume it's identical to our
50 # own local charset, in case it's not utf-8.
51 try:
52 branchname.decode('utf-8')
53 except UnicodeDecodeError:
54 branchname = encoding.fromlocal(branchname)
55 branchheads = decodelist(branchheads) 48 branchheads = decodelist(branchheads)
56 branchmap[branchname] = branchheads 49 branchmap[branchname] = branchheads
57 return branchmap 50 return branchmap
58 except TypeError: 51 except TypeError:
59 self._abort(error.ResponseError(_("unexpected response:"), d)) 52 self._abort(error.ResponseError(_("unexpected response:"), d))
160 153
161 def branchmap(repo, proto): 154 def branchmap(repo, proto):
162 branchmap = repo.branchmap() 155 branchmap = repo.branchmap()
163 heads = [] 156 heads = []
164 for branch, nodes in branchmap.iteritems(): 157 for branch, nodes in branchmap.iteritems():
165 branchname = urllib.quote(branch) 158 branchname = urllib.quote(encoding.fromlocal(branch))
166 branchnodes = encodelist(nodes) 159 branchnodes = encodelist(nodes)
167 heads.append('%s %s' % (branchname, branchnodes)) 160 heads.append('%s %s' % (branchname, branchnodes))
168 return '\n'.join(heads) 161 return '\n'.join(heads)
169 162
170 def branches(repo, proto, nodes): 163 def branches(repo, proto, nodes):