comparison mercurial/localrepo.py @ 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 f73c7b70df68
children ff2d907a5af8
comparison
equal deleted inserted replaced
14901:a773119f30ba 14902:96a72cbc6c29
8 from node import bin, hex, nullid, nullrev, short 8 from node import bin, hex, nullid, nullrev, short
9 from i18n import _ 9 from i18n import _
10 import repo, changegroup, subrepo, discovery, pushkey 10 import repo, changegroup, subrepo, discovery, pushkey
11 import changelog, dirstate, filelog, manifest, context, bookmarks 11 import changelog, dirstate, filelog, manifest, context, bookmarks
12 import lock, transaction, store, encoding 12 import lock, transaction, store, encoding
13 import scmutil, util, extensions, hook, error 13 import scmutil, util, extensions, hook, error, revset
14 import match as matchmod 14 import match as matchmod
15 import merge as mergemod 15 import merge as mergemod
16 import tags as tagsmod 16 import tags as tagsmod
17 from lock import release 17 from lock import release
18 import weakref, errno, os, time, inspect 18 import weakref, errno, os, time, inspect
214 return len(self.changelog) 214 return len(self.changelog)
215 215
216 def __iter__(self): 216 def __iter__(self):
217 for i in xrange(len(self)): 217 for i in xrange(len(self)):
218 yield i 218 yield i
219
220 def set(self, expr, *args):
221 '''
222 Yield a context for each matching revision, after doing arg
223 replacement via formatrevspec
224 '''
225
226 expr = revset.formatspec(expr, *args)
227 m = revset.match(None, expr)
228 for r in m(self, range(len(self))):
229 yield self[r]
219 230
220 def url(self): 231 def url(self):
221 return 'file:' + self.root 232 return 'file:' + self.root
222 233
223 def hook(self, name, throw=False, **args): 234 def hook(self, name, throw=False, **args):