changeset 14902:96a72cbc6c29

localrepo: add set method to iterate over a given revset This should allow replacing a number of hand-rolled graph algorithms.
author Matt Mackall <mpm@selenic.com>
date Thu, 21 Jul 2011 14:06:55 -0500
parents a773119f30ba
children ff2d907a5af8
files mercurial/localrepo.py
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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