diff hgext/mq.py @ 2682:4e2dc5c16e61

Add mq patch names to tagscache instead of overriding lookup. This makes mq patch names visible in hg log and hg tags. It also resolves the names only once, rather than on every lookup.
author Brendan Cully <brendan@kublai.com>
date Wed, 26 Jul 2006 12:22:04 -0700
parents ec05ce9cbf47
children 0fb28dbf0dc7
line wrap: on
line diff
--- a/hgext/mq.py	Tue Jul 25 17:15:44 2006 -0700
+++ b/hgext/mq.py	Wed Jul 26 12:22:04 2006 -0700
@@ -1280,28 +1280,30 @@
 
 def reposetup(ui, repo):
     repomap[repo] = queue(ui, repo.join(""))
-    oldlookup = repo.lookup
+    oldtags = repo.tags
+
+    def qtags():
+        if repo.tagscache:
+            return repo.tagscache
 
-    def qlookup(key):
-        try:
-            return oldlookup(key)
-        except hg.RepoError:
-            q = repomap[repo]
+        tagscache = oldtags()
+
+        q = repomap[repo]
+        if len(q.applied) == 0:
+            return tagscache
 
-            qpatchnames = { 'qtip': -1, 'qbase': 0 }
-            if key in qpatchnames:
-                if len(q.applied) == 0:
-                    self.ui.warn('No patches applied\n')
-                    raise
-                patch = q.applied[qpatchnames[key]].split(':')[0]
-                return revlog.bin(patch)
+        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])
 
-            patch = q.isapplied(key)
-            if not patch:
-                raise
-            return revlog.bin(patch[1])
+        return tagscache
 
-    repo.lookup = qlookup
+    repo.tags = qtags
 
 cmdtable = {
     "qapplied": (applied, [], 'hg qapplied [PATCH]'),