##// END OF EJS Templates
branch: operate on branch names in local string space where possible...
Matt Mackall -
r13047:6c375e07 default
parent child Browse files
Show More
@@ -8,7 +8,7 b''
8 from i18n import _
8 from i18n import _
9 from node import hex
9 from node import hex
10 import cmdutil
10 import cmdutil
11 import util
11 import util, encoding
12 import cStringIO, os, stat, tarfile, time, zipfile
12 import cStringIO, os, stat, tarfile, time, zipfile
13 import zlib, gzip
13 import zlib, gzip
14
14
@@ -243,7 +243,7 b' def archive(repo, dest, node, kind, deco'
243 if repo.ui.configbool("ui", "archivemeta", True):
243 if repo.ui.configbool("ui", "archivemeta", True):
244 def metadata():
244 def metadata():
245 base = 'repo: %s\nnode: %s\nbranch: %s\n' % (
245 base = 'repo: %s\nnode: %s\nbranch: %s\n' % (
246 repo[0].hex(), hex(node), ctx.branch())
246 repo[0].hex(), hex(node), encoding.fromlocal(ctx.branch()))
247
247
248 tags = ''.join('tag: %s\n' % t for t in ctx.tags()
248 tags = ''.join('tag: %s\n' % t for t in ctx.tags()
249 if repo.tagtype(t) == 'global')
249 if repo.tagtype(t) == 'global')
@@ -801,7 +801,6 b' class changeset_printer(object):'
801 branch = ctx.branch()
801 branch = ctx.branch()
802 # don't show the default branch name
802 # don't show the default branch name
803 if branch != 'default':
803 if branch != 'default':
804 branch = encoding.tolocal(branch)
805 self.ui.write(_("branch: %s\n") % branch,
804 self.ui.write(_("branch: %s\n") % branch,
806 label='log.branch')
805 label='log.branch')
807 for tag in self.repo.nodetags(changenode):
806 for tag in self.repo.nodetags(changenode):
@@ -1357,8 +1356,7 b' def commitforceeditor(repo, ctx, subs):'
1357 if ctx.p2():
1356 if ctx.p2():
1358 edittext.append(_("HG: branch merge"))
1357 edittext.append(_("HG: branch merge"))
1359 if ctx.branch():
1358 if ctx.branch():
1360 edittext.append(_("HG: branch '%s'")
1359 edittext.append(_("HG: branch '%s'") % ctx.branch())
1361 % encoding.tolocal(ctx.branch()))
1362 edittext.extend([_("HG: subrepo %s") % s for s in subs])
1360 edittext.extend([_("HG: subrepo %s") % s for s in subs])
1363 edittext.extend([_("HG: added %s") % f for f in added])
1361 edittext.extend([_("HG: added %s") % f for f in added])
1364 edittext.extend([_("HG: changed %s") % f for f in modified])
1362 edittext.extend([_("HG: changed %s") % f for f in modified])
@@ -488,15 +488,14 b' def branch(ui, repo, label=None, **opts)'
488 repo.dirstate.setbranch(label)
488 repo.dirstate.setbranch(label)
489 ui.status(_('reset working directory to branch %s\n') % label)
489 ui.status(_('reset working directory to branch %s\n') % label)
490 elif label:
490 elif label:
491 utflabel = encoding.fromlocal(label)
491 if not opts.get('force') and label in repo.branchtags():
492 if not opts.get('force') and utflabel in repo.branchtags():
493 if label not in [p.branch() for p in repo.parents()]:
492 if label not in [p.branch() for p in repo.parents()]:
494 raise util.Abort(_('a branch of the same name already exists'
493 raise util.Abort(_('a branch of the same name already exists'
495 " (use 'hg update' to switch to it)"))
494 " (use 'hg update' to switch to it)"))
496 repo.dirstate.setbranch(utflabel)
495 repo.dirstate.setbranch(label)
497 ui.status(_('marked working directory as branch %s\n') % label)
496 ui.status(_('marked working directory as branch %s\n') % label)
498 else:
497 else:
499 ui.write("%s\n" % encoding.tolocal(repo.dirstate.branch()))
498 ui.write("%s\n" % repo.dirstate.branch())
500
499
501 def branches(ui, repo, active=False, closed=False):
500 def branches(ui, repo, active=False, closed=False):
502 """list repository named branches
501 """list repository named branches
@@ -525,9 +524,8 b' def branches(ui, repo, active=False, clo'
525
524
526 for isactive, node, tag in branches:
525 for isactive, node, tag in branches:
527 if (not active) or isactive:
526 if (not active) or isactive:
528 encodedtag = encoding.tolocal(tag)
529 if ui.quiet:
527 if ui.quiet:
530 ui.write("%s\n" % encodedtag)
528 ui.write("%s\n" % tag)
531 else:
529 else:
532 hn = repo.lookup(node)
530 hn = repo.lookup(node)
533 if isactive:
531 if isactive:
@@ -543,10 +541,10 b' def branches(ui, repo, active=False, clo'
543 notice = _(' (inactive)')
541 notice = _(' (inactive)')
544 if tag == repo.dirstate.branch():
542 if tag == repo.dirstate.branch():
545 label = 'branches.current'
543 label = 'branches.current'
546 rev = str(node).rjust(31 - encoding.colwidth(encodedtag))
544 rev = str(node).rjust(31 - encoding.colwidth(tag))
547 rev = ui.label('%s:%s' % (rev, hexfunc(hn)), 'log.changeset')
545 rev = ui.label('%s:%s' % (rev, hexfunc(hn)), 'log.changeset')
548 encodedtag = ui.label(encodedtag, label)
546 tag = ui.label(tag, label)
549 ui.write("%s %s%s\n" % (encodedtag, rev, notice))
547 ui.write("%s %s%s\n" % (tag, rev, notice))
550
548
551 def bundle(ui, repo, fname, dest=None, **opts):
549 def bundle(ui, repo, fname, dest=None, **opts):
552 """create a changegroup file
550 """create a changegroup file
@@ -1830,8 +1828,7 b' def heads(ui, repo, *branchrevs, **opts)'
1830 heads += [repo[h] for h in ls if rev(h) in descendants]
1828 heads += [repo[h] for h in ls if rev(h) in descendants]
1831
1829
1832 if branchrevs:
1830 if branchrevs:
1833 decode, encode = encoding.fromlocal, encoding.tolocal
1831 branches = set(repo[br].branch() for br in branchrevs)
1834 branches = set(repo[decode(br)].branch() for br in branchrevs)
1835 heads = [h for h in heads if h.branch() in branches]
1832 heads = [h for h in heads if h.branch() in branches]
1836
1833
1837 if not opts.get('closed'):
1834 if not opts.get('closed'):
@@ -1844,7 +1841,7 b' def heads(ui, repo, *branchrevs, **opts)'
1844 if branchrevs:
1841 if branchrevs:
1845 haveheads = set(h.branch() for h in heads)
1842 haveheads = set(h.branch() for h in heads)
1846 if branches - haveheads:
1843 if branches - haveheads:
1847 headless = ', '.join(encode(b) for b in branches - haveheads)
1844 headless = ', '.join(b for b in branches - haveheads)
1848 msg = _('no open branch heads found on branches %s')
1845 msg = _('no open branch heads found on branches %s')
1849 if opts.get('rev'):
1846 if opts.get('rev'):
1850 msg += _(' (started at %s)' % opts['rev'])
1847 msg += _(' (started at %s)' % opts['rev'])
@@ -2209,7 +2206,7 b' def identify(ui, repo, source=None,'
2209 output.append(str(ctx.rev()))
2206 output.append(str(ctx.rev()))
2210
2207
2211 if repo.local() and default and not ui.quiet:
2208 if repo.local() and default and not ui.quiet:
2212 b = encoding.tolocal(ctx.branch())
2209 b = ctx.branch()
2213 if b != 'default':
2210 if b != 'default':
2214 output.append("(%s)" % b)
2211 output.append("(%s)" % b)
2215
2212
@@ -2219,7 +2216,7 b' def identify(ui, repo, source=None,'
2219 output.append(t)
2216 output.append(t)
2220
2217
2221 if branch:
2218 if branch:
2222 output.append(encoding.tolocal(ctx.branch()))
2219 output.append(ctx.branch())
2223
2220
2224 if tags:
2221 if tags:
2225 output.extend(ctx.tags())
2222 output.extend(ctx.tags())
@@ -2623,7 +2620,7 b' def merge(ui, repo, node=None, **opts):'
2623 node = opts.get('rev')
2620 node = opts.get('rev')
2624
2621
2625 if not node:
2622 if not node:
2626 branch = repo.changectx(None).branch()
2623 branch = repo[None].branch()
2627 bheads = repo.branchheads(branch)
2624 bheads = repo.branchheads(branch)
2628 if len(bheads) > 2:
2625 if len(bheads) > 2:
2629 raise util.Abort(_(
2626 raise util.Abort(_(
@@ -7,7 +7,7 b''
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
@@ -109,7 +109,7 b' class changectx(object):'
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):
@@ -591,9 +591,8 b' class workingctx(changectx):'
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
@@ -715,7 +714,7 b' class workingctx(changectx):'
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
@@ -1048,7 +1047,7 b' class memctx(object):'
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):
@@ -7,7 +7,7 b''
7
7
8 from node import nullid
8 from node import nullid
9 from i18n import _
9 from i18n import _
10 import util, ignore, osutil, parsers
10 import util, ignore, osutil, parsers, encoding
11 import struct, os, stat, errno
11 import struct, os, stat, errno
12 import cStringIO
12 import cStringIO
13
13
@@ -201,7 +201,7 b' class dirstate(object):'
201 return [self._validate(p) for p in self._pl]
201 return [self._validate(p) for p in self._pl]
202
202
203 def branch(self):
203 def branch(self):
204 return self._branch
204 return encoding.tolocal(self._branch)
205
205
206 def setparents(self, p1, p2=nullid):
206 def setparents(self, p1, p2=nullid):
207 self._dirty = self._dirtypl = True
207 self._dirty = self._dirtypl = True
@@ -210,8 +210,8 b' class dirstate(object):'
210 def setbranch(self, branch):
210 def setbranch(self, branch):
211 if branch in ['tip', '.', 'null']:
211 if branch in ['tip', '.', 'null']:
212 raise util.Abort(_('the name \'%s\' is reserved') % branch)
212 raise util.Abort(_('the name \'%s\' is reserved') % branch)
213 self._branch = branch
213 self._branch = encoding.fromlocal(branch)
214 self._opener("branch", "w").write(branch + '\n')
214 self._opener("branch", "w").write(self._branch + '\n')
215
215
216 def _read(self):
216 def _read(self):
217 self._map = {}
217 self._map = {}
@@ -32,24 +32,22 b' def addbranchrevs(lrepo, repo, branches,'
32 return revs, revs[0]
32 return revs, revs[0]
33 branchmap = repo.branchmap()
33 branchmap = repo.branchmap()
34
34
35 def primary(butf8):
35 def primary(branch):
36 if butf8 == '.':
36 if branch == '.':
37 if not lrepo or not lrepo.local():
37 if not lrepo or not lrepo.local():
38 raise util.Abort(_("dirstate branch not accessible"))
38 raise util.Abort(_("dirstate branch not accessible"))
39 butf8 = lrepo.dirstate.branch()
39 branch = lrepo.dirstate.branch()
40 if butf8 in branchmap:
40 if branch in branchmap:
41 revs.extend(node.hex(r) for r in reversed(branchmap[butf8]))
41 revs.extend(node.hex(r) for r in reversed(branchmap[branch]))
42 return True
42 return True
43 else:
43 else:
44 return False
44 return False
45
45
46 for branch in branches:
46 for branch in branches:
47 butf8 = encoding.fromlocal(branch)
47 if not primary(branch):
48 if not primary(butf8):
49 raise error.RepoLookupError(_("unknown branch '%s'") % branch)
48 raise error.RepoLookupError(_("unknown branch '%s'") % branch)
50 if hashbranch:
49 if hashbranch:
51 butf8 = encoding.fromlocal(hashbranch)
50 if not primary(hashbranch):
52 if not primary(butf8):
53 revs.append(hashbranch)
51 revs.append(hashbranch)
54 return revs, revs[0]
52 return revs, revs[0]
55
53
@@ -365,8 +363,7 b' def clone(ui, source, dest=None, pull=Fa'
365 except error.RepoLookupError:
363 except error.RepoLookupError:
366 continue
364 continue
367 bn = dest_repo[uprev].branch()
365 bn = dest_repo[uprev].branch()
368 dest_repo.ui.status(_("updating to branch %s\n")
366 dest_repo.ui.status(_("updating to branch %s\n") % bn)
369 % encoding.tolocal(bn))
370 _update(dest_repo, uprev)
367 _update(dest_repo, uprev)
371
368
372 return src_repo, dest_repo
369 return src_repo, dest_repo
@@ -105,7 +105,7 b' class localrepository(repo.repository):'
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 = {}
@@ -435,7 +435,6 b' class localrepository(repo.repository):'
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:
@@ -455,7 +454,8 b' class localrepository(repo.repository):'
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:
@@ -470,7 +470,7 b' class localrepository(repo.repository):'
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
@@ -659,7 +659,8 b' class localrepository(repo.repository):'
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")),
@@ -717,7 +718,7 b' class localrepository(repo.repository):'
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()
@@ -148,7 +148,6 b' def showauthor(repo, ctx, templ, **args)'
148 def showbranches(**args):
148 def showbranches(**args):
149 branch = args['ctx'].branch()
149 branch = args['ctx'].branch()
150 if branch != 'default':
150 if branch != 'default':
151 branch = encoding.tolocal(branch)
152 return showlist('branch', [branch], plural='branches', **args)
151 return showlist('branch', [branch], plural='branches', **args)
153
152
154 def showchildren(**args):
153 def showchildren(**args):
@@ -44,14 +44,7 b' class wirerepository(repo.repository):'
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
@@ -162,7 +155,7 b' 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)
@@ -240,6 +240,4 b' hg log (dolphin)'
240 abort: decoding near '\xe9': 'ascii' codec can't decode byte 0xe9 in position 0: ordinal not in range(128)! (esc)
240 abort: decoding near '\xe9': 'ascii' codec can't decode byte 0xe9 in position 0: ordinal not in range(128)! (esc)
241 [255]
241 [255]
242 $ cp latin-1-tag .hg/branch
242 $ cp latin-1-tag .hg/branch
243 $ HGENCODING=latin-1 hg ci -m 'should fail'
243 $ HGENCODING=latin-1 hg ci -m 'auto-promote legacy name'
244 abort: branch name not in UTF-8!
245 [255]
General Comments 0
You need to be logged in to leave comments. Login now