changeset 2723:04d9b31faeca

mq: do not hold a reference to repo in tags override Instead, replace repo's class object with a subclass.
author Brendan Cully <brendan@kublai.com>
date Fri, 28 Jul 2006 13:08:21 -0700
parents 10e95059ffd7
children 9c41ae1908c7
files hgext/mq.py
diffstat 1 files changed, 19 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Fri Jul 28 22:17:32 2006 +0200
+++ b/hgext/mq.py	Fri Jul 28 13:08:21 2006 -0700
@@ -1388,31 +1388,30 @@
     return 0
 
 def reposetup(ui, repo):
-    repomap[repo] = queue(ui, repo.join(""))
-    oldtags = repo.tags
+    class MqRepo(repo.__class__):
+        def tags(self):
+            if self.tagscache:
+                return self.tagscache
+
+            tagscache = super(self.__class__, self).tags()
 
-    def qtags():
-        if repo.tagscache:
-            return repo.tagscache
+            q = repomap[repo]
+            if not q.applied:
+                return tagscache
 
-        tagscache = oldtags()
+            mqtags = [patch.split(':') for patch in q.applied]
+            mqtags.append((mqtags[-1][0], 'qtip'))
+            mqtags.append((mqtags[0][0], 'qbase'))
+            for patch in mqtags:
+                if patch[1] in tagscache:
+                    self.ui.warn('Tag %s overrides mq patch of the same name\n' % patch[1])
+                else:
+                    tagscache[patch[1]] = revlog.bin(patch[0])
 
-        q = repomap[repo]
-        if len(q.applied) == 0:
             return tagscache
 
-        mqtags = [patch.split(':') for patch in q.applied]
-        mqtags.append((mqtags[-1][0], 'qtip'))
-        mqtags.append((mqtags[0][0], 'qbase'))
-        for patch in mqtags:
-            if patch[1] in tagscache:
-                repo.ui.warn('Tag %s overrides mq patch of the same name\n' % patch[1])
-            else:
-                tagscache[patch[1]] = revlog.bin(patch[0])
-
-        return tagscache
-
-    repo.tags = qtags
+    repo.__class__ = MqRepo
+    repomap[repo] = queue(ui, repo.join(""))
 
 cmdtable = {
     "qapplied": (applied, [], 'hg qapplied [PATCH]'),