comparison mercurial/context.py @ 6764:8db64464d136

context: add walk method
author Matt Mackall <mpm@selenic.com>
date Fri, 27 Jun 2008 19:25:48 -0500
parents 403682f1c678
children f5d7cfcbb4d3
comparison
equal deleted inserted replaced
6763:403682f1c678 6764:8db64464d136
143 """ 143 """
144 return the ancestor context of self and c2 144 return the ancestor context of self and c2
145 """ 145 """
146 n = self._repo.changelog.ancestor(self._node, c2._node) 146 n = self._repo.changelog.ancestor(self._node, c2._node)
147 return changectx(self._repo, n) 147 return changectx(self._repo, n)
148
149 def walk(self, match):
150 fdict = dict.fromkeys(match.files())
151 # for dirstate.walk, files=['.'] means "walk the whole tree".
152 # follow that here, too
153 fdict.pop('.', None)
154 for fn in self:
155 for ffn in fdict:
156 # match if the file is the exact name or a directory
157 if ffn == fn or fn.startswith("%s/" % ffn):
158 del fdict[ffn]
159 break
160 if match(fn):
161 yield fn
162 for fn in util.sort(fdict):
163 if match.bad(fn, 'No such file in rev ' + str(self)) and match(fn):
164 yield fn
148 165
149 class filectx(object): 166 class filectx(object):
150 """A filecontext object makes access to data related to a particular 167 """A filecontext object makes access to data related to a particular
151 filerevision convenient.""" 168 filerevision convenient."""
152 def __init__(self, repo, path, changeid=None, fileid=None, 169 def __init__(self, repo, path, changeid=None, fileid=None,
574 591
575 def ancestor(self, c2): 592 def ancestor(self, c2):
576 """return the ancestor context of self and c2""" 593 """return the ancestor context of self and c2"""
577 return self._parents[0].ancestor(c2) # punt on two parents for now 594 return self._parents[0].ancestor(c2) # punt on two parents for now
578 595
596 def walk(self, match):
597 for src, fn, st in self._repo.dirstate.walk(match, True, False):
598 yield fn
599
579 class workingfilectx(filectx): 600 class workingfilectx(filectx):
580 """A workingfilectx object makes access to data related to a particular 601 """A workingfilectx object makes access to data related to a particular
581 file in the working directory convenient.""" 602 file in the working directory convenient."""
582 def __init__(self, repo, path, filelog=None, workingctx=None): 603 def __init__(self, repo, path, filelog=None, workingctx=None):
583 """changeid can be a changeset revision, node, or tag. 604 """changeid can be a changeset revision, node, or tag.