##// END OF EJS Templates
walk: begin refactoring badmatch handling
Matt Mackall -
r6578:f242d368 default
parent child Browse files
Show More
@@ -228,12 +228,18 b' def matchpats(repo, pats=[], opts={}, gl'
228 228 pats = util.expand_glob(pats or [])
229 229 m = match.match(repo.root, repo.getcwd(), pats, opts.get('include'),
230 230 opts.get('exclude'), default)
231 def badfn(f, msg):
232 repo.ui.warn("%s: %s\n" % (m.rel(f), msg))
233 return False
234 m.bad = badfn
231 235 return m.files(), m, m.anypats()
232 236
233 237 def walk(repo, pats=[], opts={}, node=None, badmatch=None, globbed=False,
234 238 default='relpath'):
235 239 dummy, m, dummy = matchpats(repo, pats, opts, globbed, default)
236 for src, fn in repo.walk(node, m, badmatch):
240 if badmatch:
241 m.bad = badmatch
242 for src, fn in repo.walk(node, m):
237 243 yield src, fn, m.rel(fn), m.exact(fn)
238 244
239 245 def findrenames(repo, added=None, removed=None, threshold=0.5):
@@ -32,7 +32,7 b' def add(ui, repo, *pats, **opts):'
32 32 exacts = {}
33 33 names = []
34 34 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts,
35 badmatch=util.always):
35 badmatch=lambda x,y: True):
36 36 if exact:
37 37 if ui.verbose:
38 38 ui.status(_('adding %s\n') % rel)
@@ -1696,7 +1696,7 b' def locate(ui, repo, *pats, **opts):'
1696 1696
1697 1697 ret = 1
1698 1698 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node,
1699 badmatch=util.always,
1699 badmatch=lambda x,y: True,
1700 1700 default='relglob'):
1701 1701 if src == 'b':
1702 1702 continue
@@ -416,14 +416,13 b' class dirstate(object):'
416 416 return True
417 417 return False
418 418
419 def walk(self, match, badmatch):
419 def walk(self, match):
420 420 # filter out the stat
421 for src, f, st in self.statwalk(match.files(), match,
422 badmatch=badmatch):
421 for src, f, st in self.statwalk(match.files(), match, badfn=match.bad):
423 422 yield src, f
424 423
425 424 def statwalk(self, files, match, unknown=True,
426 ignored=False, badmatch=None, directories=False):
425 ignored=False, badfn=None, directories=False):
427 426 '''
428 427 walk recursively through the directory tree, finding all files
429 428 matched by the match function
@@ -433,11 +432,16 b' class dirstate(object):'
433 432 'f' the file was found in the directory tree
434 433 'd' the file is a directory of the tree
435 434 'm' the file was only in the dirstate and not in the tree
436 'b' file was not found and matched badmatch
435 'b' file was not found and did not match badfn
437 436
438 437 and st is the stat result if the file was found in the directory.
439 438 '''
440 439
440 def fwarn(f, msg):
441 self._ui.warn('%s: %s\n' % (self.pathto(ff), msg))
442 return False
443 badfn = badfn or fwarn
444
441 445 # walk all files by default
442 446 if not files:
443 447 files = ['.']
@@ -536,10 +540,9 b' class dirstate(object):'
536 540 found = True
537 541 break
538 542 if not found:
539 if inst.errno != errno.ENOENT or not badmatch:
540 self._ui.warn('%s: %s\n' %
541 (self.pathto(ff), inst.strerror))
542 elif badmatch and badmatch(ff) and imatch(nf):
543 if inst.errno != errno.ENOENT:
544 fwarn(ff, inst.strerror)
545 elif badfn(ff, inst.strerror) and imatch(nf):
543 546 yield 'b', ff, None
544 547 continue
545 548 if s_isdir(st.st_mode):
@@ -931,7 +931,7 b' class localrepository(repo.repository):'
931 931 self.dirstate.invalidate()
932 932 del tr, lock, wlock
933 933
934 def walk(self, node, match, badmatch):
934 def walk(self, node, match):
935 935 '''
936 936 walk recursively through the directory tree or a given
937 937 changeset, finding all files matched by the match
@@ -963,14 +963,11 b' class localrepository(repo.repository):'
963 963 ffiles = fdict.keys()
964 964 ffiles.sort()
965 965 for fn in ffiles:
966 if badmatch and badmatch(fn):
967 if match(fn):
968 yield 'b', fn
969 else:
970 self.ui.warn(_('%s: No such file in rev %s\n')
971 % (self.pathto(fn), short(node)))
966 if match.bad(fn, 'No such file in rev ' + short(node)) \
967 and match(fn):
968 yield 'b', fn
972 969 else:
973 for src, fn in self.dirstate.walk(match, badmatch):
970 for src, fn in self.dirstate.walk(match):
974 971 yield src, fn
975 972
976 973 def status(self, node1=None, node2=None, files=[], match=util.always,
@@ -7,9 +7,8 b' class match(object):'
7 7 self._cwd = cwd
8 8 self._include = include
9 9 self._exclude = exclude
10 f, mf, ap = util.matcher(self._root, self._cwd, self._patterns,
11 self._include, self._exclude, self.src(),
12 default)
10 f, mf, ap = util.matcher(root, cwd, patterns, include, exclude,
11 self.src(), default)
13 12 self._files = f
14 13 self._fmap = dict.fromkeys(f)
15 14 self._matchfn = mf
General Comments 0
You need to be logged in to leave comments. Login now