##// END OF EJS Templates
context: add walk method
Matt Mackall -
r6764:8db64464 default
parent child Browse files
Show More
@@ -110,8 +110,8 b' def annotate(ui, repo, *pats, **opts):'
110 ctx = repo[opts['rev']]
110 ctx = repo[opts['rev']]
111
111
112 m = cmdutil.match(repo, pats, opts)
112 m = cmdutil.match(repo, pats, opts)
113 for abs in repo.walk(m, ctx.node()):
113 for abs in ctx.walk(m):
114 fctx = ctx.filectx(abs)
114 fctx = ctx[abs]
115 if not opts['text'] and util.binary(fctx.data()):
115 if not opts['text'] and util.binary(fctx.data()):
116 ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs))
116 ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs))
117 continue
117 continue
@@ -485,9 +485,9 b' def cat(ui, repo, file1, *pats, **opts):'
485 ctx = repo[opts['rev']]
485 ctx = repo[opts['rev']]
486 err = 1
486 err = 1
487 m = cmdutil.match(repo, (file1,) + pats, opts)
487 m = cmdutil.match(repo, (file1,) + pats, opts)
488 for abs in repo.walk(m, ctx.node()):
488 for abs in ctx.walk(m):
489 fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs)
489 fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs)
490 data = ctx.filectx(abs).data()
490 data = ctx[abs].data()
491 if opts.get('decode'):
491 if opts.get('decode'):
492 data = repo.wwritedata(abs, data)
492 data = repo.wwritedata(abs, data)
493 fp.write(data)
493 fp.write(data)
@@ -907,8 +907,8 b' def debugrename(ui, repo, file1, *pats, '
907
907
908 ctx = repo[opts.get('rev')]
908 ctx = repo[opts.get('rev')]
909 m = cmdutil.match(repo, (file1,) + pats, opts)
909 m = cmdutil.match(repo, (file1,) + pats, opts)
910 for abs in repo.walk(m, ctx.node()):
910 for abs in ctx.walk(m):
911 fctx = ctx.filectx(abs)
911 fctx = ctx[abs]
912 o = fctx.filelog().renamed(fctx.filenode())
912 o = fctx.filelog().renamed(fctx.filenode())
913 rel = m.rel(abs)
913 rel = m.rel(abs)
914 if o:
914 if o:
@@ -1693,17 +1693,13 b' def locate(ui, repo, *pats, **opts):'
1693 that contain white space as multiple filenames.
1693 that contain white space as multiple filenames.
1694 """
1694 """
1695 end = opts['print0'] and '\0' or '\n'
1695 end = opts['print0'] and '\0' or '\n'
1696 rev = opts['rev']
1696 rev = opts.get('rev') or None
1697 if rev:
1698 node = repo.lookup(rev)
1699 else:
1700 node = None
1701
1697
1702 ret = 1
1698 ret = 1
1703 m = cmdutil.match(repo, pats, opts, default='relglob')
1699 m = cmdutil.match(repo, pats, opts, default='relglob')
1704 m.bad = lambda x,y: False
1700 m.bad = lambda x,y: False
1705 for abs in repo.walk(m, node):
1701 for abs in repo[rev].walk(m):
1706 if not node and abs not in repo.dirstate:
1702 if not rev and abs not in repo.dirstate:
1707 continue
1703 continue
1708 if opts['fullpath']:
1704 if opts['fullpath']:
1709 ui.write(os.path.join(repo.root, abs), end)
1705 ui.write(os.path.join(repo.root, abs), end)
@@ -2350,7 +2346,7 b' def revert(ui, repo, *pats, **opts):'
2350
2346
2351 m = cmdutil.match(repo, pats, opts)
2347 m = cmdutil.match(repo, pats, opts)
2352 m.bad = badfn
2348 m.bad = badfn
2353 for abs in repo.walk(m, node=node):
2349 for abs in repo[node].walk(m):
2354 if abs not in names:
2350 if abs not in names:
2355 names[abs] = m.rel(abs), m.exact(abs)
2351 names[abs] = m.rel(abs), m.exact(abs)
2356
2352
@@ -146,6 +146,23 b' class changectx(object):'
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
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
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."""
@@ -576,6 +593,10 b' class workingctx(changectx):'
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."""
@@ -941,27 +941,7 b' class localrepository(repo.repository):'
941 changeset, finding all files matched by the match
941 changeset, finding all files matched by the match
942 function
942 function
943 '''
943 '''
944
944 return self[node].walk(match)
945 if node:
946 fdict = dict.fromkeys(match.files())
947 # for dirstate.walk, files=['.'] means "walk the whole tree".
948 # follow that here, too
949 fdict.pop('.', None)
950 for fn in self[node]:
951 for ffn in fdict:
952 # match if the file is the exact name or a directory
953 if ffn == fn or fn.startswith("%s/" % ffn):
954 del fdict[ffn]
955 break
956 if match(fn):
957 yield fn
958 for fn in util.sort(fdict):
959 if match.bad(fn, 'No such file in rev ' + short(node)) \
960 and match(fn):
961 yield fn
962 else:
963 for src, fn, st in self.dirstate.walk(match, True, False):
964 yield fn
965
945
966 def status(self, node1=None, node2=None, match=None,
946 def status(self, node1=None, node2=None, match=None,
967 ignored=False, clean=False, unknown=False):
947 ignored=False, clean=False, unknown=False):
General Comments 0
You need to be logged in to leave comments. Login now