make mq play nicely with the branch cache
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Mon, 23 Oct 2006 23:32:56 -0300
changeset 3492 fbf8320f25c8
parent 3491 23cffef5d424
child 3493 1b9494d2b070
make mq play nicely with the branch cache - if no patches are applied, don't do anything different - if the cache includes valid data from one of the patch revisions, use the cache, but don't save anything new - if the cache has data from before the patch revisions only, save what the list of branches would be without the patch revisions
hgext/mq.py
tests/test-mq-caches
tests/test-mq-caches.out
--- a/hgext/mq.py	Mon Oct 23 23:32:56 2006 -0300
+++ b/hgext/mq.py	Mon Oct 23 23:32:56 2006 -0300
@@ -2003,6 +2003,35 @@
 
             return tagscache
 
+        def branchtags(self):
+            if self.branchcache != None:
+                return self.branchcache
+
+            q = self.mq
+            if not q.applied:
+                return super(mqrepo, self).branchtags()
+
+            self.branchcache = {} # avoid recursion in changectx
+            cl = self.changelog
+            partial, last, lrev = self._readbranchcache()
+
+            qbase = cl.rev(revlog.bin(q.applied[0].rev))
+            start = lrev + 1
+            if start < qbase:
+                # update the cache (excluding the patches) and save it
+                self._updatebranchcache(partial, lrev+1, qbase)
+                self._writebranchcache(partial, cl.node(qbase-1), qbase-1)
+                start = qbase
+            # if start = qbase, the cache is as updated as it should be.
+            # if start > qbase, the cache includes (part of) the patches.
+            # we might as well use it, but we won't save it.
+
+            # update the cache up to the tip
+            self._updatebranchcache(partial, start, cl.count())
+
+            self.branchcache = partial
+            return self.branchcache
+
     if repo.local():
         repo.__class__ = mqrepo
         repo.mq = queue(ui, repo.join(""))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-mq-caches	Mon Oct 23 23:32:56 2006 -0300
@@ -0,0 +1,76 @@
+#!/bin/sh
+
+echo '[extensions]' >> $HGRCPATH
+echo 'hgext.mq=' >> $HGRCPATH
+
+show_branch_cache()
+{
+    branches=.hg/branches.cache
+    hg log -r tip --template 'tip: #rev#\n'
+    if [ -f $branches ]; then
+	sort $branches
+    else
+	echo No $branches
+    fi
+    if [ "$1" = 1 ]; then
+	for b in foo bar; do
+	    hg log -r $b --template "branch $b: "'#rev#\n'
+	done
+    fi
+}
+
+hg init a
+cd a
+hg qinit -c
+
+echo '# mq patch on an empty repo'
+hg qnew p1
+show_branch_cache
+
+echo > pfile
+hg add pfile
+hg qrefresh -m 'patch 1'
+show_branch_cache
+
+echo
+echo '# some regular revisions'
+hg qpop
+echo foo > foo
+hg add foo
+echo foo > .hg/branch
+hg ci -m 'branch foo' -d '1000000 0'
+
+echo bar > bar
+hg add bar
+echo bar > .hg/branch
+hg ci -m 'branch bar' -d '1000000 0'
+show_branch_cache
+
+echo
+echo '# add some mq patches'
+hg qpush
+show_branch_cache
+
+hg qnew p2
+echo foo > .hg/branch
+echo foo2 >> foo
+hg qrefresh -m 'patch 2'
+show_branch_cache 1
+
+echo
+echo '# removing the cache'
+rm -f .hg/branches.cache
+show_branch_cache 1
+
+echo
+echo '# importing rev 1 (the cache now ends in one of the patches)'
+hg qimport -r 1 -n p0
+show_branch_cache 1
+hg log -r qbase --template 'qbase: #rev#\n'
+
+echo
+echo '# detect an invalid cache'
+hg qpop -a
+hg qpush -a
+show_branch_cache
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-mq-caches.out	Mon Oct 23 23:32:56 2006 -0300
@@ -0,0 +1,53 @@
+# mq patch on an empty repo
+tip: 0
+No .hg/branches.cache
+tip: 0
+No .hg/branches.cache
+
+# some regular revisions
+Patch queue now empty
+tip: 1
+3f910abad313ff802d3a23a7529433872df9b3ae 1
+3f910abad313ff802d3a23a7529433872df9b3ae bar
+9539f35bdc80732cc9a3f84e46508f1ed1ec8cff foo
+
+# add some mq patches
+applying p1
+Now at: p1
+tip: 2
+3f910abad313ff802d3a23a7529433872df9b3ae 1
+3f910abad313ff802d3a23a7529433872df9b3ae bar
+9539f35bdc80732cc9a3f84e46508f1ed1ec8cff foo
+tip: 3
+3f910abad313ff802d3a23a7529433872df9b3ae 1
+3f910abad313ff802d3a23a7529433872df9b3ae bar
+9539f35bdc80732cc9a3f84e46508f1ed1ec8cff foo
+branch foo: 3
+branch bar: 2
+
+# removing the cache
+tip: 3
+3f910abad313ff802d3a23a7529433872df9b3ae 1
+3f910abad313ff802d3a23a7529433872df9b3ae bar
+9539f35bdc80732cc9a3f84e46508f1ed1ec8cff foo
+branch foo: 3
+branch bar: 2
+
+# importing rev 1 (the cache now ends in one of the patches)
+tip: 3
+3f910abad313ff802d3a23a7529433872df9b3ae 1
+3f910abad313ff802d3a23a7529433872df9b3ae bar
+9539f35bdc80732cc9a3f84e46508f1ed1ec8cff foo
+branch foo: 3
+branch bar: 2
+qbase: 1
+
+# detect an invalid cache
+Patch queue now empty
+applying p0
+applying p1
+applying p2
+Now at: p2
+tip: 3
+9539f35bdc80732cc9a3f84e46508f1ed1ec8cff 0
+9539f35bdc80732cc9a3f84e46508f1ed1ec8cff foo