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