localrepo: add set method to iterate over a given revset
authorMatt Mackall <mpm@selenic.com>
Thu, 21 Jul 2011 14:06:55 -0500
changeset 14902 96a72cbc6c29
parent 14901 a773119f30ba
child 14904 ff2d907a5af8
localrepo: add set method to iterate over a given revset This should allow replacing a number of hand-rolled graph algorithms.
mercurial/localrepo.py
--- a/mercurial/localrepo.py	Thu Jul 21 14:05:45 2011 -0500
+++ b/mercurial/localrepo.py	Thu Jul 21 14:06:55 2011 -0500
@@ -10,7 +10,7 @@
 import repo, changegroup, subrepo, discovery, pushkey
 import changelog, dirstate, filelog, manifest, context, bookmarks
 import lock, transaction, store, encoding
-import scmutil, util, extensions, hook, error
+import scmutil, util, extensions, hook, error, revset
 import match as matchmod
 import merge as mergemod
 import tags as tagsmod
@@ -217,6 +217,17 @@
         for i in xrange(len(self)):
             yield i
 
+    def set(self, expr, *args):
+        '''
+        Yield a context for each matching revision, after doing arg
+        replacement via formatrevspec
+        '''
+
+        expr = revset.formatspec(expr, *args)
+        m = revset.match(None, expr)
+        for r in m(self, range(len(self))):
+            yield self[r]
+
     def url(self):
         return 'file:' + self.root