Commit da380383 authored by Matt Mackall's avatar Matt Mackall
Browse files

context: add walk method

parent 403682f1c678
......@@ -110,8 +110,8 @@ def annotate(ui, repo, *pats, **opts):
ctx = repo[opts['rev']]
m = cmdutil.match(repo, pats, opts)
for abs in repo.walk(m, ctx.node()):
fctx = ctx.filectx(abs)
for abs in ctx.walk(m):
fctx = ctx[abs]
if not opts['text'] and util.binary(fctx.data()):
ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs))
continue
......@@ -485,9 +485,9 @@ def cat(ui, repo, file1, *pats, **opts):
ctx = repo[opts['rev']]
err = 1
m = cmdutil.match(repo, (file1,) + pats, opts)
for abs in repo.walk(m, ctx.node()):
for abs in ctx.walk(m):
fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs)
data = ctx.filectx(abs).data()
data = ctx[abs].data()
if opts.get('decode'):
data = repo.wwritedata(abs, data)
fp.write(data)
......@@ -907,8 +907,8 @@ def debugrename(ui, repo, file1, *pats, **opts):
ctx = repo[opts.get('rev')]
m = cmdutil.match(repo, (file1,) + pats, opts)
for abs in repo.walk(m, ctx.node()):
fctx = ctx.filectx(abs)
for abs in ctx.walk(m):
fctx = ctx[abs]
o = fctx.filelog().renamed(fctx.filenode())
rel = m.rel(abs)
if o:
......@@ -1693,17 +1693,13 @@ def locate(ui, repo, *pats, **opts):
that contain white space as multiple filenames.
"""
end = opts['print0'] and '\0' or '\n'
rev = opts['rev']
if rev:
node = repo.lookup(rev)
else:
node = None
rev = opts.get('rev') or None
ret = 1
m = cmdutil.match(repo, pats, opts, default='relglob')
m.bad = lambda x,y: False
for abs in repo.walk(m, node):
if not node and abs not in repo.dirstate:
for abs in repo[rev].walk(m):
if not rev and abs not in repo.dirstate:
continue
if opts['fullpath']:
ui.write(os.path.join(repo.root, abs), end)
......@@ -2350,7 +2346,7 @@ def revert(ui, repo, *pats, **opts):
m = cmdutil.match(repo, pats, opts)
m.bad = badfn
for abs in repo.walk(m, node=node):
for abs in repo[node].walk(m):
if abs not in names:
names[abs] = m.rel(abs), m.exact(abs)
......
......@@ -146,6 +146,23 @@ class changectx(object):
n = self._repo.changelog.ancestor(self._node, c2._node)
return changectx(self._repo, n)
def walk(self, match):
fdict = dict.fromkeys(match.files())
# for dirstate.walk, files=['.'] means "walk the whole tree".
# follow that here, too
fdict.pop('.', None)
for fn in self:
for ffn in fdict:
# match if the file is the exact name or a directory
if ffn == fn or fn.startswith("%s/" % ffn):
del fdict[ffn]
break
if match(fn):
yield fn
for fn in util.sort(fdict):
if match.bad(fn, 'No such file in rev ' + str(self)) and match(fn):
yield fn
class filectx(object):
"""A filecontext object makes access to data related to a particular
filerevision convenient."""
......@@ -576,6 +593,10 @@ class workingctx(changectx):
"""return the ancestor context of self and c2"""
return self._parents[0].ancestor(c2) # punt on two parents for now
def walk(self, match):
for src, fn, st in self._repo.dirstate.walk(match, True, False):
yield fn
class workingfilectx(filectx):
"""A workingfilectx object makes access to data related to a particular
file in the working directory convenient."""
......
......@@ -941,27 +941,7 @@ class localrepository(repo.repository):
changeset, finding all files matched by the match
function
'''
if node:
fdict = dict.fromkeys(match.files())
# for dirstate.walk, files=['.'] means "walk the whole tree".
# follow that here, too
fdict.pop('.', None)
for fn in self[node]:
for ffn in fdict:
# match if the file is the exact name or a directory
if ffn == fn or fn.startswith("%s/" % ffn):
del fdict[ffn]
break
if match(fn):
yield fn
for fn in util.sort(fdict):
if match.bad(fn, 'No such file in rev ' + short(node)) \
and match(fn):
yield fn
else:
for src, fn, st in self.dirstate.walk(match, True, False):
yield fn
return self[node].walk(match)
def status(self, node1=None, node2=None, match=None,
ignored=False, clean=False, unknown=False):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment