Commits

Brodie Rao  committed d78aaac

Refreshing queue

  • Participants
  • Parent commits adfeab6

Comments (0)

Files changed (4)

File branch-cache

 # HG changeset patch
-# Parent 0027a5cec9d00873ca14129b4589975083e5e71d
+# User Brodie Rao <brodie@sf.io>
+# Date 1364871676 25200
+# Node ID 382311eea5cd047d02277b78ae8bb0578890786f
+# Parent 37f8baaf31d2dbec094a582169b61a0ee0c717db
 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,32 @@ class branchcache(dict):
+@@ -124,9 +136,27 @@ class branchcache(dict):
          except IndexError:
              return False
  
 +    def branchtip(self, branch):
 +        return self._branchtip(self[branch])[0]
 +
-+    def iterheads(self):
-+        for bn, heads in self.iteritems():
-+            for head in heads:
-+                yield (bn, head, head in self._closednodes)
-+
 +    def itertips(self):
 +        for bn, heads in self.iteritems():
 +            yield (bn,) + self._branchtip(heads)
  
      def write(self, repo):
          try:
-@@ -137,7 +172,12 @@ class branchcache(dict):
+@@ -137,7 +167,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 +191,13 @@ class branchcache(dict):
+@@ -151,9 +186,13 @@ class branchcache(dict):
          cl = repo.changelog
          # collect new branch entries
          newbranches = {}
 -        return encoding.tolocal(self.read(rev)[5].get("branch"))
 +        extra = self.read(rev)[5]
 +        return encoding.tolocal(extra.get("branch")), 'close' in extra
+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
+             # Recomputing branch cache might be slow on big repos,
+             # so just copy it
+             dstcachedir = os.path.join(destpath, 'cache')
+-            srcbranchcache = srcrepo.sjoin('cache/branchheads')
+-            dstbranchcache = os.path.join(dstcachedir, 'branchheads')
++            srcbranchcache = srcrepo.sjoin('cache/branch2')
++            dstbranchcache = os.path.join(dstcachedir, 'branch2')
+             if os.path.exists(srcbranchcache):
+                 if not os.path.exists(dstcachedir):
+                     os.mkdir(dstcachedir)
+diff --git a/tests/test-fncache.t b/tests/test-fncache.t
+--- a/tests/test-fncache.t
++++ b/tests/test-fncache.t
+@@ -70,7 +70,7 @@ Non store repo:
+   .hg/00changelog.i
+   .hg/00manifest.i
+   .hg/cache
+-  .hg/cache/branchheads-served
++  .hg/cache/branch2-served
+   .hg/data
+   .hg/data/tst.d.hg
+   .hg/data/tst.d.hg/foo.i
+@@ -98,7 +98,7 @@ Non fncache repo:
+   .hg
+   .hg/00changelog.i
+   .hg/cache
+-  .hg/cache/branchheads-served
++  .hg/cache/branch2-served
+   .hg/dirstate
+   .hg/last-message.txt
+   .hg/requires
+diff --git a/tests/test-hardlinks.t b/tests/test-hardlinks.t
+--- a/tests/test-hardlinks.t
++++ b/tests/test-hardlinks.t
+@@ -196,7 +196,7 @@ r4 has hardlinks in the working dir (not
+   $ nlinksdir r4
+   2 r4/.hg/00changelog.i
+   2 r4/.hg/branch
+-  2 r4/.hg/cache/branchheads-served
++  2 r4/.hg/cache/branch2-served
+   2 r4/.hg/dirstate
+   2 r4/.hg/hgrc
+   2 r4/.hg/last-message.txt
+@@ -226,7 +226,7 @@ Update back to revision 11 in r4 should 
+   $ nlinksdir r4
+   2 r4/.hg/00changelog.i
+   1 r4/.hg/branch
+-  2 r4/.hg/cache/branchheads-served
++  2 r4/.hg/cache/branch2-served
+   1 r4/.hg/dirstate
+   2 r4/.hg/hgrc
+   2 r4/.hg/last-message.txt
+diff --git a/tests/test-inherit-mode.t b/tests/test-inherit-mode.t
+--- a/tests/test-inherit-mode.t
++++ b/tests/test-inherit-mode.t
+@@ -66,7 +66,7 @@ new directories are setgid
+   00700 ./.hg/
+   00600 ./.hg/00changelog.i
+   00770 ./.hg/cache/
+-  00660 ./.hg/cache/branchheads-served
++  00660 ./.hg/cache/branch2-served
+   00660 ./.hg/dirstate
+   00660 ./.hg/last-message.txt
+   00600 ./.hg/requires
+@@ -111,7 +111,7 @@ group can still write everything
+   00770 ../push/.hg/
+   00660 ../push/.hg/00changelog.i
+   00770 ../push/.hg/cache/
+-  00660 ../push/.hg/cache/branchheads-base
++  00660 ../push/.hg/cache/branch2-base
+   00660 ../push/.hg/requires
+   00770 ../push/.hg/store/
+   00660 ../push/.hg/store/00changelog.i
+diff --git a/tests/test-newbranch.t b/tests/test-newbranch.t
+--- a/tests/test-newbranch.t
++++ b/tests/test-newbranch.t
+@@ -1,13 +1,13 @@
+-  $ branchcache=.hg/cache/branchheads
++  $ branchcache=.hg/cache/branch2
+ 
+   $ listbranchcaches() {
+-  >    for f in .hg/cache/branchheads*;
++  >    for f in .hg/cache/branch2*;
+   >       do echo === $f ===;
+   >       cat $f;
+   >     done;
+   > }
+   $ purgebranchcaches() {
+-  >     rm .hg/cache/branchheads*
++  >     rm .hg/cache/branch2*
+   > }
+ 
+   $ hg init t
+@@ -158,13 +158,13 @@ Test for invalid branch cache:
+   4:adf1a74a7f7b
+ 
+   $ listbranchcaches
+-  === .hg/cache/branchheads ===
++  === .hg/cache/branch2 ===
+   corrupted
+-  === .hg/cache/branchheads-served ===
++  === .hg/cache/branch2-served ===
+   adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 4
+-  c21617b13b220988e7a2e26290fbe4325ffa7139 bar
+-  1c28f494dae69a2f8fc815059d257eccf3fcfe75 default
+-  adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 foo
++  c21617b13b220988e7a2e26290fbe4325ffa7139 o bar
++  1c28f494dae69a2f8fc815059d257eccf3fcfe75 o default
++  adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 o foo
+ 
+ Push should update the branch cache:
+ 
+@@ -175,20 +175,20 @@ Pushing just rev 0:
+   $ hg push -qr 0 ../target
+ 
+   $ (cd ../target/; listbranchcaches)
+-  === .hg/cache/branchheads-base ===
++  === .hg/cache/branch2-base ===
+   db01e8ea3388fd3c7c94e1436ea2bd6a53d581c5 0
+-  db01e8ea3388fd3c7c94e1436ea2bd6a53d581c5 default
++  db01e8ea3388fd3c7c94e1436ea2bd6a53d581c5 o default
+ 
+ Pushing everything:
+ 
+   $ hg push -qf ../target
+ 
+   $ (cd ../target/; listbranchcaches)
+-  === .hg/cache/branchheads-base ===
++  === .hg/cache/branch2-base ===
+   adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 4
+-  c21617b13b220988e7a2e26290fbe4325ffa7139 bar
+-  1c28f494dae69a2f8fc815059d257eccf3fcfe75 default
+-  adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 foo
++  c21617b13b220988e7a2e26290fbe4325ffa7139 o bar
++  1c28f494dae69a2f8fc815059d257eccf3fcfe75 o default
++  adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 o foo
+ 
+ Update with no arguments: tipmost revision of the current branch:
+ 
+diff --git a/tests/test-phases.t b/tests/test-phases.t
+--- a/tests/test-phases.t
++++ b/tests/test-phases.t
+@@ -175,28 +175,28 @@ visible shared between the initial repo 
+ 
+ check that branch cache with "served" filter are properly computed and stored
+ 
+-  $ ls ../push-dest/.hg/cache/branchheads*
+-  ../push-dest/.hg/cache/branchheads-served
+-  $ cat ../push-dest/.hg/cache/branchheads-served
++  $ ls ../push-dest/.hg/cache/branch2*
++  ../push-dest/.hg/cache/branch2-served
++  $ cat ../push-dest/.hg/cache/branch2-served
+   6d6770faffce199f1fddd1cf87f6f026138cf061 6 465891ffab3c47a3c23792f7dc84156e19a90722
+-  b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e default
+-  6d6770faffce199f1fddd1cf87f6f026138cf061 default
++  b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e o default
++  6d6770faffce199f1fddd1cf87f6f026138cf061 o default
+   $ hg heads -R ../push-dest --template '{rev}:{node} {phase}\n'  #update visible cache too
+   6:6d6770faffce199f1fddd1cf87f6f026138cf061 draft
+   5:2713879da13d6eea1ff22b442a5a87cb31a7ce6a secret
+   3:b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e draft
+-  $ ls ../push-dest/.hg/cache/branchheads*
+-  ../push-dest/.hg/cache/branchheads-served
+-  ../push-dest/.hg/cache/branchheads-visible
+-  $ cat ../push-dest/.hg/cache/branchheads-served
++  $ ls ../push-dest/.hg/cache/branch2*
++  ../push-dest/.hg/cache/branch2-served
++  ../push-dest/.hg/cache/branch2-visible
++  $ cat ../push-dest/.hg/cache/branch2-served
+   6d6770faffce199f1fddd1cf87f6f026138cf061 6 465891ffab3c47a3c23792f7dc84156e19a90722
+-  b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e default
+-  6d6770faffce199f1fddd1cf87f6f026138cf061 default
+-  $ cat ../push-dest/.hg/cache/branchheads-visible
++  b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e o default
++  6d6770faffce199f1fddd1cf87f6f026138cf061 o default
++  $ cat ../push-dest/.hg/cache/branch2-visible
+   6d6770faffce199f1fddd1cf87f6f026138cf061 6
+-  b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e default
+-  2713879da13d6eea1ff22b442a5a87cb31a7ce6a default
+-  6d6770faffce199f1fddd1cf87f6f026138cf061 default
++  b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e o default
++  2713879da13d6eea1ff22b442a5a87cb31a7ce6a o default
++  6d6770faffce199f1fddd1cf87f6f026138cf061 o default
+ 
+ 
+ Restore condition prior extra insertion.
+diff --git a/tests/test-rebase-collapse.t b/tests/test-rebase-collapse.t
+--- a/tests/test-rebase-collapse.t
++++ b/tests/test-rebase-collapse.t
+@@ -275,18 +275,18 @@ We keep it the test this way in case new
+   7:c65502d4178782309ce0574c5ae6ee9485a9bafa default
+   6:c772a8b2dc17629cec88a19d09c926c4814b12c7 default
+ 
+-  $ cat $TESTTMP/b2/.hg/cache/branchheads-served
++  $ cat $TESTTMP/b2/.hg/cache/branch2-served
+   c65502d4178782309ce0574c5ae6ee9485a9bafa 7
+-  c772a8b2dc17629cec88a19d09c926c4814b12c7 default
+-  c65502d4178782309ce0574c5ae6ee9485a9bafa default
++  c772a8b2dc17629cec88a19d09c926c4814b12c7 o default
++  c65502d4178782309ce0574c5ae6ee9485a9bafa o default
+ 
+   $ hg strip 4
+   saved backup bundle to $TESTTMP/b2/.hg/strip-backup/8a5212ebc852-backup.hg (glob)
+ 
+-  $ cat $TESTTMP/b2/.hg/cache/branchheads-served
++  $ cat $TESTTMP/b2/.hg/cache/branch2-served
+   c65502d4178782309ce0574c5ae6ee9485a9bafa 4
+-  2870ad076e541e714f3c2bc32826b5c6a6e5b040 default
+-  c65502d4178782309ce0574c5ae6ee9485a9bafa default
++  2870ad076e541e714f3c2bc32826b5c6a6e5b040 o default
++  c65502d4178782309ce0574c5ae6ee9485a9bafa o default
+ 
+   $ hg heads --template="{rev}:{node} {branch}\n"
+   4:c65502d4178782309ce0574c5ae6ee9485a9bafa default

File 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)
+ 

File branch-cache-2

 # HG changeset patch
-# Parent 77313a9e328d05542987c5fa221d485bba99ee8c
+# User Brodie Rao <brodie@sf.io>
+# Date 1364871676 25200
+# Node ID fe6ae59b5ccdad59b22a31c94351a904024a359c
+# Parent 9b739c40831b4416efa376a07b5a7c3bb73b0861
 localrepo: use new branchcache methods that provide open/closed info
+* * *
+branches: use new branchcache methods that provide open/closed info
 
+diff --git a/hgext/mq.py b/hgext/mq.py
+--- a/hgext/mq.py
++++ b/hgext/mq.py
+@@ -1202,9 +1202,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:
+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 itertips(self):
+         for bn, heads in self.iteritems():
+             yield (bn,) + self._branchtip(heads)
+diff --git a/mercurial/commands.py b/mercurial/commands.py
+--- a/mercurial/commands.py
++++ b/mercurial/commands.py
+@@ -1006,17 +1006,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, closed in repo.branchmap().itertips():
++        isactive = tag in activebranches and not closed
++        branches.append((repo[tip], isactive, not closed))
+     branches.sort(key=lambda i: (i[1], i[0].rev(), i[0].branch(), i[2]),
+                   reverse=True)
+ 
+@@ -2119,11 +2111,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 = ['']
+@@ -3339,7 +3328,7 @@ def heads(ui, repo, *branchrevs, **opts)
+     else:
+         heads = []
+         for branch in repo.branchmap():
+-            heads += repo.branchheads(branch, start, opts.get('closed'))
++            heads += repo.branchheads(branch, start, opts.get('closed')) # XXX
+         heads = [repo[h] for h in heads]
+ 
+     if branchrevs:
+diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
+--- a/mercurial/hgweb/webcommands.py
++++ b/mercurial/hgweb/webcommands.py
+@@ -452,18 +452,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 ctx, closed: (not ctx.closesbranch(), ctx.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'
+@@ -511,8 +511,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,
 diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
 --- a/mercurial/localrepo.py
 +++ b/mercurial/localrepo.py
-@@ -634,29 +634,17 @@ class localrepository(object):
+@@ -637,29 +637,12 @@ class localrepository(object):
          branchmap.updatecache(self)
          return self._branchcaches[self.filtername]
  
 +        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
-         the branch, open heads come before closed'''
+-
+-    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
-+        return dict(self.branchmap().itertips())
  
      def lookup(self, key):
          return self[key].node()
+@@ -1610,13 +1593,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):
+branch-cache-0
 branch-cache
 branch-cache-2
-branch-cache-3
 profile-run-tests
 testing-stuff
 branchcache