Commits

Brodie Rao committed 0a87972

Refreshing queue

Comments (0)

Files changed (15)

 # HG changeset patch
-# User Brodie Rao <brodie@sf.io>
-# Date 1364871676 25200
-# Node ID 382311eea5cd047d02277b78ae8bb0578890786f
-# Parent 37f8baaf31d2dbec094a582169b61a0ee0c717db
+# Parent 57b92d431ffcc2a0f42ed1f4fd6ff9182f57a2c6
 branchmap: cache open/closed branch head information
 
 diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
  
      def _hashfiltered(self, repo):
          """build hash of revision filtered in the current cache
-@@ -124,9 +136,27 @@ class branchcache(dict):
-         except IndexError:
-             return False
+@@ -126,7 +138,8 @@ class branchcache(dict):
  
-+    def _branchtip(self, heads):
-+        tip = heads[-1]
-+        closed = True
-+        for h in reversed(heads):
-+            if h not in self._closednodes:
-+                tip = h
-+                closed = False
-+                break
-+        return tip, closed
-+
-+    def branchtip(self, branch):
-+        return self._branchtip(self[branch])[0]
-+
-+    def itertips(self):
-+        for bn, heads in self.iteritems():
-+            yield (bn,) + self._branchtip(heads)
-+
      def copy(self):
          """return an deep copy of the branchcache object"""
 -        return branchcache(self, self.tipnode, self.tiprev, self.filteredhash)
  
      def write(self, repo):
          try:
-@@ -137,7 +167,12 @@ class branchcache(dict):
+@@ -137,7 +150,12 @@ class branchcache(dict):
              f.write(" ".join(cachekey) + '\n')
              for label, nodes in sorted(self.iteritems()):
                  for node in nodes:
              f.close()
          except (IOError, OSError, util.Abort):
              # Abort may be raise by read only opener
-@@ -151,9 +186,13 @@ class branchcache(dict):
+@@ -151,9 +169,13 @@ class branchcache(dict):
          cl = repo.changelog
          # collect new branch entries
          newbranches = {}
 diff --git a/mercurial/hg.py b/mercurial/hg.py
 --- a/mercurial/hg.py
 +++ b/mercurial/hg.py
-@@ -336,8 +336,8 @@ def clone(ui, peeropts, source, dest=Non
+@@ -337,8 +337,8 @@ def clone(ui, peeropts, source, dest=Non
              # Recomputing branch cache might be slow on big repos,
              # so just copy it
              dstcachedir = os.path.join(destpath, 'cache')

branch-cache-0

-# HG changeset patch
-# Parent 59cdd3a7e2817b8518415058549549a0706c63bb
-mq: remove unused repo._committingpatch-related code
-
-diff --git a/hgext/mq.py b/hgext/mq.py
---- a/hgext/mq.py
-+++ b/hgext/mq.py
-@@ -281,15 +281,11 @@ def newcommit(repo, phase, *args, **kwar
-             phase = phases.secret
-     if phase is not None:
-         backup = repo.ui.backupconfig('phases', 'new-commit')
--    # Marking the repository as committing an mq patch can be used
--    # to optimize operations like branchtags().
--    repo._committingpatch = True
-     try:
-         if phase is not None:
-             repo.ui.setconfig('phases', 'new-commit', phase)
-         return repo.commit(*args, **kwargs)
-     finally:
--        repo._committingpatch = False
-         if phase is not None:
-             repo.ui.restoreconfig(backup)
- 

branchmap-branchheads

+# HG changeset patch
+# Parent f24543c2517b2f86ca78cb5d0f1f857ff9aa27ac
+branchmap: introduce branchheads() method
+
+diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
+--- a/mercurial/branchmap.py
++++ b/mercurial/branchmap.py
+@@ -149,6 +149,12 @@ class branchcache(dict):
+     def branchtip(self, branch):
+         return self._branchtip(self[branch])[0]
+ 
++    def branchheads(self, branch, closed=False):
++        heads = self[branch]
++        if not closed:
++            heads = [h for h in heads if h not in self._closednodes]
++        return heads
++
+     def copy(self):
+         """return an deep copy of the branchcache object"""
+         return branchcache(self, self.tipnode, self.tiprev, self.filteredhash,

branchmap-branchheads-2

+# HG changeset patch
+# Parent aa136e62860e79d2ef205a6b63844d8a5f6d02b0
+localrepo: refactor repo.branchheads() to use repo.branchmap().branchheads()
+
+diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
+--- a/mercurial/localrepo.py
++++ b/mercurial/localrepo.py
+@@ -1607,13 +1607,11 @@ class localrepository(object):
+         if branch not in branches:
+             return []
+         # the cache returns heads ordered lowest to highest
+-        bheads = list(reversed(branches[branch]))
++        bheads = list(reversed(branches.branchheads(branch, closed=closed)))
+         if start is not None:
+             # filter out the heads that cannot be reached from startrev
+             fbheads = set(self.changelog.nodesbetween([start], bheads)[2])
+             bheads = [h for h in bheads if h in fbheads]
+-        if not closed:
+-            bheads = [h for h in bheads if not self[h].closesbranch()]
+         return bheads
+ 
+     def branches(self, nodes):
+# HG changeset patch
+# Parent 5d923ac0d5b26050f2d98593b4e55e0106015818
+branchmap: introduce branchtip() method
+
+diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
+--- a/mercurial/branchmap.py
++++ b/mercurial/branchmap.py
+@@ -136,6 +136,19 @@ class branchcache(dict):
+         except IndexError:
+             return False
+ 
++    def _branchtip(self, heads):
++        tip = heads[-1]
++        closed = True
++        for h in reversed(heads):
++            if h not in self._closednodes:
++                tip = h
++                closed = False
++                break
++        return tip, closed
++
++    def branchtip(self, branch):
++        return self._branchtip(self[branch])[0]
++
+     def copy(self):
+         """return an deep copy of the branchcache object"""
+         return branchcache(self, self.tipnode, self.tiprev, self.filteredhash,

branchmap-branchtip-2

+# HG changeset patch
+# Parent 0636d0df8486e8c06986143d1f1228e318a2e670
+localrepo: refactor repo.branchtip() to use repo.branchmap().branchtip()
+
+diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
+--- a/mercurial/localrepo.py
++++ b/mercurial/localrepo.py
+@@ -651,9 +651,10 @@ class localrepository(object):
+ 
+     def branchtip(self, branch):
+         '''return the tip node for a given branch'''
+-        if branch not in self.branchmap():
++        try:
++            return self.branchmap().branchtip(branch)
++        except KeyError:
+             raise error.RepoLookupError(_("unknown branch '%s'") % branch)
+-        return self._branchtip(self.branchmap()[branch])
+ 
+     def branchtags(self):
+         '''return a dict where branch names map to the tipmost head of
+# HG changeset patch
+# Parent 5eed405e436ab1484fb91b015623cdd00629e043
+branchmap: introduce itertips() method
+
+diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
+--- a/mercurial/branchmap.py
++++ b/mercurial/branchmap.py
+@@ -155,6 +155,10 @@ class branchcache(dict):
+             heads = [h for h in heads if h not in self._closednodes]
+         return heads
+ 
++    def itertips(self):
++        for bn, heads in self.iteritems():
++            yield (bn,) + self._branchtip(heads)
++
+     def copy(self):
+         """return an deep copy of the branchcache object"""
+         return branchcache(self, self.tipnode, self.tiprev, self.filteredhash,
+# HG changeset patch
+# Parent adae22a441d492e0e11f77522d129f571a598f15
+debuglabelcomplete: simplify branch gathering with repo.branchmap().itertips()
+
+diff --git a/mercurial/commands.py b/mercurial/commands.py
+--- a/mercurial/commands.py
++++ b/mercurial/commands.py
+@@ -2137,11 +2137,8 @@ def debuglabelcomplete(ui, repo, *args):
+     labels = set()
+     labels.update(t[0] for t in repo.tagslist())
+     labels.update(repo._bookmarks.keys())
+-    for heads in repo.branchmap().itervalues():
+-        for h in heads:
+-            ctx = repo[h]
+-            if not ctx.closesbranch():
+-                labels.add(ctx.branch())
++    labels.update(tag for (tag, tip, closed) in repo.branchmap().itertips()
++                  if not closed)
+     completions = set()
+     if not args:
+         args = ['']
+# HG changeset patch
+# Parent 3a750aa316a9719bbce69e7984ab63bd467ca40c
+branches: simplify branch gathering with repo.branchmap().itertips()
+
+diff --git a/mercurial/commands.py b/mercurial/commands.py
+--- a/mercurial/commands.py
++++ b/mercurial/commands.py
+@@ -1009,17 +1009,9 @@ def branches(ui, repo, active=False, clo
+ 
+     activebranches = set([repo[n].branch() for n in repo.heads()])
+     branches = []
+-    for tag, heads in repo.branchmap().iteritems():
+-        for h in reversed(heads):
+-            ctx = repo[h]
+-            isopen = not ctx.closesbranch()
+-            if isopen:
+-                tip = ctx
+-                break
+-        else:
+-            tip = repo[heads[-1]]
+-        isactive = tag in activebranches and isopen
+-        branches.append((tip, isactive, isopen))
++    for tag, tip, isclosed in repo.branchmap().itertips():
++        isactive = tag in activebranches and not isclosed
++        branches.append((repo[tip], isactive, not isclosed))
+     branches.sort(key=lambda i: (i[1], i[0].rev(), i[0].branch(), i[2]),
+                   reverse=True)
+ 
+# HG changeset patch
+# Parent 249d02656160b4b0929b0c656cd7f034edc8c9d5
+hgweb: simplify branch gathering in summary with repo.branchmap().itertips()
+
+diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
+--- a/mercurial/hgweb/webcommands.py
++++ b/mercurial/hgweb/webcommands.py
+@@ -569,8 +569,9 @@ def summary(web, req, tmpl):
+     def branches(**map):
+         parity = paritygen(web.stripecount)
+ 
+-        b = web.repo.branchtags()
+-        l = [(-web.repo.changelog.rev(n), n, t) for t, n in b.iteritems()]
++        b = web.repo.branchmap()
++        l = [(-web.repo.changelog.rev(tip), tip, tag)
++             for tag, tip, closed in b.itertips()]
+         for r, n, t in sorted(l):
+             yield {'parity': parity.next(),
+                    'branch': t,
+# HG changeset patch
+# Parent 580e2245b19d04c3625f935b685a9d3cc4f03fee
+hgweb: simplify branch gathering in branches with repo.branchmap().itertips()
+
+diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
+--- a/mercurial/hgweb/webcommands.py
++++ b/mercurial/hgweb/webcommands.py
+@@ -510,18 +510,18 @@ def branches(web, req, tmpl):
+     tips = []
+     heads = web.repo.heads()
+     parity = paritygen(web.stripecount)
+-    sortkey = lambda ctx: (not ctx.closesbranch(), ctx.rev())
++    sortkey = lambda item: (not item[0].closesbranch(), item[0].rev())
+ 
+     def entries(limit, **map):
+         count = 0
+         if not tips:
+-            for t, n in web.repo.branchtags().iteritems():
+-                tips.append(web.repo[n])
+-        for ctx in sorted(tips, key=sortkey, reverse=True):
++            for tag, tip, closed in web.repo.branchmap().itertips():
++                tips.append((web.repo[tip], closed))
++        for ctx, closed in sorted(tips, key=sortkey, reverse=True):
+             if limit > 0 and count >= limit:
+                 return
+             count += 1
+-            if not web.repo.branchheads(ctx.branch()):
++            if closed:
+                 status = 'closed'
+             elif ctx.node() not in heads:
+                 status = 'inactive'
+# HG changeset patch
+# Parent 71727b958d3cc9e3e844b3c7b0e2ee3d4e0935b4
+localrepo: remove unused repo.branchtags()/_branchtip() methods
+
+diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
+--- a/mercurial/localrepo.py
++++ b/mercurial/localrepo.py
+@@ -639,16 +639,6 @@ class localrepository(object):
+         branchmap.updatecache(self)
+         return self._branchcaches[self.filtername]
+ 
+-
+-    def _branchtip(self, heads):
+-        '''return the tipmost branch head in heads'''
+-        tip = heads[-1]
+-        for h in reversed(heads):
+-            if not self[h].closesbranch():
+-                tip = h
+-                break
+-        return tip
+-
+     def branchtip(self, branch):
+         '''return the tip node for a given branch'''
+         try:
+@@ -656,14 +646,6 @@ class localrepository(object):
+         except KeyError:
+             raise error.RepoLookupError(_("unknown branch '%s'") % branch)
+ 
+-    def branchtags(self):
+-        '''return a dict where branch names map to the tipmost head of
+-        the branch, open heads come before closed'''
+-        bt = {}
+-        for bn, heads in self.branchmap().iteritems():
+-            bt[bn] = self._branchtip(heads)
+-        return bt
+-
+     def lookup(self, key):
+         return self[key].node()
+ 
+# HG changeset patch
+# Parent 7999f4fa155a30e9c7a28fe775d1d7a75c7711a0
+mq: remove unused repo._committingpatch-related code
+
+This was introduced in 20ad8f0512a2 but its usage was removed in
+46cc3b74e1c5.
+
+diff --git a/hgext/mq.py b/hgext/mq.py
+--- a/hgext/mq.py
++++ b/hgext/mq.py
+@@ -283,15 +283,11 @@ def newcommit(repo, phase, *args, **kwar
+             phase = phases.secret
+     if phase is not None:
+         backup = repo.ui.backupconfig('phases', 'new-commit')
+-    # Marking the repository as committing an mq patch can be used
+-    # to optimize operations like branchtags().
+-    repo._committingpatch = True
+     try:
+         if phase is not None:
+             repo.ui.setconfig('phases', 'new-commit', phase)
+         return repo.commit(*args, **kwargs)
+     finally:
+-        repo._committingpatch = False
+         if phase is not None:
+             repo.ui.restoreconfig(backup)
+ 
+# HG changeset patch
+# User Brodie Rao <brodie@sf.io>
+# Date 1364871676 25200
+# Node ID fe6ae59b5ccdad59b22a31c94351a904024a359c
+# Parent 9f9d907a1744fc5de9ea2e0ec1476e3306ec9116
+mq: refactor usage of repo.branchmap().iteritems() with itervalues()
+
+diff --git a/hgext/mq.py b/hgext/mq.py
+--- a/hgext/mq.py
++++ b/hgext/mq.py
+@@ -1222,9 +1222,7 @@ class queue(object):
+         diffopts = self.diffopts()
+         wlock = repo.wlock()
+         try:
+-            heads = []
+-            for b, ls in repo.branchmap().iteritems():
+-                heads += ls
++            heads = [h for hs in repo.branchmap().itervalues() for h in hs]
+             if not heads:
+                 heads = [nullid]
+             if repo.dirstate.p1() not in heads and not exact:
-branch-cache-0
+mq-cleanup-1
+mq-cleanup-2
 branch-cache
-branch-cache-2
+branchmap-branchtip
+branchmap-branchtip-2
+branchmap-branchheads
+branchmap-branchheads-2
+branchmap-itertips
+branchmap-itertips-2
+branchmap-itertips-3
+branchmap-itertips-4
+branchmap-itertips-5
+localrepo-cleanup
 profile-run-tests
 testing-stuff
 branchcache