##// END OF EJS Templates
localrepo: add branchtip() method for faster single-branch lookups...
Brodie Rao -
r16719:e7bf09ac default
parent child Browse files
Show More
@@ -38,7 +38,10 b" def fetch(ui, repo, source='default', **"
38
38
39 parent, p2 = repo.dirstate.parents()
39 parent, p2 = repo.dirstate.parents()
40 branch = repo.dirstate.branch()
40 branch = repo.dirstate.branch()
41 branchnode = repo.branchtags().get(branch)
41 try:
42 branchnode = repo.branchtip(branch)
43 except error.RepoLookupError:
44 branchnode = None
42 if parent != branchnode:
45 if parent != branchnode:
43 raise util.Abort(_('working dir not at branch tip '
46 raise util.Abort(_('working dir not at branch tip '
44 '(use "hg update" to check out branch tip)'))
47 '(use "hg update" to check out branch tip)'))
@@ -7,7 +7,7 b''
7
7
8 from mercurial.i18n import _
8 from mercurial.i18n import _
9 from mercurial.node import hex
9 from mercurial.node import hex
10 from mercurial import encoding, util
10 from mercurial import encoding, error, util
11 import errno, os
11 import errno, os
12
12
13 def valid(mark):
13 def valid(mark):
@@ -140,8 +140,8 b' def unsetcurrent(repo):'
140
140
141 def updatecurrentbookmark(repo, oldnode, curbranch):
141 def updatecurrentbookmark(repo, oldnode, curbranch):
142 try:
142 try:
143 return update(repo, oldnode, repo.branchtags()[curbranch])
143 return update(repo, oldnode, repo.branchtip(curbranch))
144 except KeyError:
144 except error.RepoLookupError:
145 if curbranch == "default": # no default branch!
145 if curbranch == "default": # no default branch!
146 return update(repo, oldnode, repo.lookup("tip"))
146 return update(repo, oldnode, repo.lookup("tip"))
147 else:
147 else:
@@ -827,7 +827,7 b' def bookmark(ui, repo, mark=None, rev=No'
827 if mark in marks and not force:
827 if mark in marks and not force:
828 raise util.Abort(_("bookmark '%s' already exists "
828 raise util.Abort(_("bookmark '%s' already exists "
829 "(use -f to force)") % mark)
829 "(use -f to force)") % mark)
830 if ((mark in repo.branchtags() or mark == repo.dirstate.branch())
830 if ((mark in repo.branchmap() or mark == repo.dirstate.branch())
831 and not force):
831 and not force):
832 raise util.Abort(
832 raise util.Abort(
833 _("a bookmark cannot have the name of an existing branch"))
833 _("a bookmark cannot have the name of an existing branch"))
@@ -903,7 +903,7 b' def branch(ui, repo, label=None, **opts)'
903 repo.dirstate.setbranch(label)
903 repo.dirstate.setbranch(label)
904 ui.status(_('reset working directory to branch %s\n') % label)
904 ui.status(_('reset working directory to branch %s\n') % label)
905 elif label:
905 elif label:
906 if not opts.get('force') and label in repo.branchtags():
906 if not opts.get('force') and label in repo.branchmap():
907 if label not in [p.branch() for p in repo.parents()]:
907 if label not in [p.branch() for p in repo.parents()]:
908 raise util.Abort(_('a branch of the same name already'
908 raise util.Abort(_('a branch of the same name already'
909 ' exists'),
909 ' exists'),
@@ -78,10 +78,12 b' class changectx(object):'
78 self._node = repo._tagscache.tags[changeid]
78 self._node = repo._tagscache.tags[changeid]
79 self._rev = repo.changelog.rev(self._node)
79 self._rev = repo.changelog.rev(self._node)
80 return
80 return
81 if changeid in repo.branchtags():
81 try:
82 self._node = repo.branchtags()[changeid]
82 self._node = repo.branchtip(changeid)
83 self._rev = repo.changelog.rev(self._node)
83 self._rev = repo.changelog.rev(self._node)
84 return
84 return
85 except error.RepoLookupError:
86 pass
85
87
86 self._node = repo.changelog._partialmatch(changeid)
88 self._node = repo.changelog._partialmatch(changeid)
87 if self._node is not None:
89 if self._node is not None:
@@ -794,7 +794,11 b' def graph(web, req, tmpl):'
794 desc = cgi.escape(templatefilters.nonempty(desc))
794 desc = cgi.escape(templatefilters.nonempty(desc))
795 user = cgi.escape(templatefilters.person(ctx.user()))
795 user = cgi.escape(templatefilters.person(ctx.user()))
796 branch = ctx.branch()
796 branch = ctx.branch()
797 branch = branch, web.repo.branchtags().get(branch) == ctx.node()
797 try:
798 branchnode = web.repo.branchtip(branch)
799 except error.RepoLookupError:
800 branchnode = None
801 branch = branch, branchnode == ctx.node()
798 data.append((node, vtx, edges, desc, user, age, branch, ctx.tags(),
802 data.append((node, vtx, edges, desc, user, age, branch, ctx.tags(),
799 ctx.bookmarks()))
803 ctx.bookmarks()))
800
804
@@ -98,16 +98,23 b' def nodebranchdict(repo, ctx):'
98 branches = []
98 branches = []
99 branch = ctx.branch()
99 branch = ctx.branch()
100 # If this is an empty repo, ctx.node() == nullid,
100 # If this is an empty repo, ctx.node() == nullid,
101 # ctx.branch() == 'default', but branchtags() is
101 # ctx.branch() == 'default'.
102 # an empty dict. Using dict.get avoids a traceback.
102 try:
103 if repo.branchtags().get(branch) == ctx.node():
103 branchnode = repo.branchtip(branch)
104 except error.RepoLookupError:
105 branchnode = None
106 if branchnode == ctx.node():
104 branches.append({"name": branch})
107 branches.append({"name": branch})
105 return branches
108 return branches
106
109
107 def nodeinbranch(repo, ctx):
110 def nodeinbranch(repo, ctx):
108 branches = []
111 branches = []
109 branch = ctx.branch()
112 branch = ctx.branch()
110 if branch != 'default' and repo.branchtags().get(branch) != ctx.node():
113 try:
114 branchnode = repo.branchtip(branch)
115 except error.RepoLookupError:
116 branchnode = None
117 if branch != 'default' and branchnode != ctx.node():
111 branches.append({"name": branch})
118 branches.append({"name": branch})
112 return branches
119 return branches
113
120
@@ -507,17 +507,27 b' class localrepository(repo.repository):'
507 self.updatebranchcache()
507 self.updatebranchcache()
508 return self._branchcache
508 return self._branchcache
509
509
510 def _branchtip(self, heads):
511 '''return the tipmost branch head in heads'''
512 tip = heads[-1]
513 for h in reversed(heads):
514 if 'close' not in self.changelog.read(h)[5]:
515 tip = h
516 break
517 return tip
518
519 def branchtip(self, branch):
520 '''return the tip node for a given branch'''
521 if branch not in self.branchmap():
522 raise error.RepoLookupError(_("unknown branch '%s'") % branch)
523 return self._branchtip(self.branchmap()[branch])
524
510 def branchtags(self):
525 def branchtags(self):
511 '''return a dict where branch names map to the tipmost head of
526 '''return a dict where branch names map to the tipmost head of
512 the branch, open heads come before closed'''
527 the branch, open heads come before closed'''
513 bt = {}
528 bt = {}
514 for bn, heads in self.branchmap().iteritems():
529 for bn, heads in self.branchmap().iteritems():
515 tip = heads[-1]
530 bt[bn] = self._branchtip(heads)
516 for h in reversed(heads):
517 if 'close' not in self.changelog.read(h)[5]:
518 tip = h
519 break
520 bt[bn] = tip
521 return bt
531 return bt
522
532
523 def _readbranchcache(self):
533 def _readbranchcache(self):
@@ -7,7 +7,7 b''
7
7
8 from node import nullid, nullrev, hex, bin
8 from node import nullid, nullrev, hex, bin
9 from i18n import _
9 from i18n import _
10 import scmutil, util, filemerge, copies, subrepo
10 import error, scmutil, util, filemerge, copies, subrepo
11 import errno, os, shutil
11 import errno, os, shutil
12
12
13 class mergestate(object):
13 class mergestate(object):
@@ -529,8 +529,8 b' def update(repo, node, branchmerge, forc'
529 if node is None:
529 if node is None:
530 # tip of current branch
530 # tip of current branch
531 try:
531 try:
532 node = repo.branchtags()[wc.branch()]
532 node = repo.branchtip(wc.branch())
533 except KeyError:
533 except error.RepoLookupError:
534 if wc.branch() == "default": # no default branch!
534 if wc.branch() == "default": # no default branch!
535 node = repo.lookup("tip") # update to tip
535 node = repo.lookup("tip") # update to tip
536 else:
536 else:
General Comments 0
You need to be logged in to leave comments. Login now