scmutil: add an optional parameter to matcher factories for a bad() override
Even though scmutil.matchandpats() is documented to warn about bad files,
several callers silence the warning.
--- a/hgext/largefiles/overrides.py Fri Jun 05 19:07:54 2015 -0400
+++ b/hgext/largefiles/overrides.py Fri Jun 05 19:24:32 2015 -0400
@@ -51,8 +51,8 @@
def installnormalfilesmatchfn(manifest):
'''installmatchfn with a matchfn that ignores all largefiles'''
def overridematch(ctx, pats=[], opts={}, globbed=False,
- default='relpath'):
- match = oldmatch(ctx, pats, opts, globbed, default)
+ default='relpath', badfn=None):
+ match = oldmatch(ctx, pats, opts, globbed, default, badfn=badfn)
return composenormalfilematcher(match, manifest)
oldmatch = installmatchfn(overridematch)
@@ -288,13 +288,14 @@
def overridelog(orig, ui, repo, *pats, **opts):
def overridematchandpats(ctx, pats=[], opts={}, globbed=False,
- default='relpath'):
+ default='relpath', badfn=None):
"""Matcher that merges root directory with .hglf, suitable for log.
It is still possible to match .hglf directly.
For any listed files run log on the standin too.
matchfn tries both the given filename and with .hglf stripped.
"""
- matchandpats = oldmatchandpats(ctx, pats, opts, globbed, default)
+ matchandpats = oldmatchandpats(ctx, pats, opts, globbed, default,
+ badfn=badfn)
m, p = copy.copy(matchandpats)
if m.always():
@@ -377,9 +378,9 @@
# (2) to determine what files to print out diffs for.
# The magic matchandpats override should be used for case (1) but not for
# case (2).
- def overridemakelogfilematcher(repo, pats, opts):
+ def overridemakelogfilematcher(repo, pats, opts, badfn=None):
wctx = repo[None]
- match, pats = oldmatchandpats(wctx, pats, opts)
+ match, pats = oldmatchandpats(wctx, pats, opts, badfn=badfn)
return lambda rev: match
oldmatchandpats = installmatchandpatsfn(overridematchandpats)
@@ -613,7 +614,7 @@
manifest = repo[None].manifest()
def overridematch(ctx, pats=[], opts={}, globbed=False,
- default='relpath'):
+ default='relpath', badfn=None):
newpats = []
# The patterns were previously mangled to add the standin
# directory; we need to remove that now
@@ -622,7 +623,7 @@
newpats.append(pat.replace(lfutil.shortname, ''))
else:
newpats.append(pat)
- match = oldmatch(ctx, newpats, opts, globbed, default)
+ match = oldmatch(ctx, newpats, opts, globbed, default, badfn=badfn)
m = copy.copy(match)
lfile = lambda f: lfutil.standin(f) in manifest
m._files = [lfutil.standin(f) for f in m._files if lfile(f)]
@@ -722,8 +723,8 @@
oldstandins = lfutil.getstandinsstate(repo)
def overridematch(mctx, pats=[], opts={}, globbed=False,
- default='relpath'):
- match = oldmatch(mctx, pats, opts, globbed, default)
+ default='relpath', badfn=None):
+ match = oldmatch(mctx, pats, opts, globbed, default, badfn=badfn)
m = copy.copy(match)
# revert supports recursing into subrepos, and though largefiles
--- a/mercurial/scmutil.py Fri Jun 05 19:07:54 2015 -0400
+++ b/mercurial/scmutil.py Fri Jun 05 19:24:32 2015 -0400
@@ -790,17 +790,22 @@
ret.append(kindpat)
return ret
-def matchandpats(ctx, pats=[], opts={}, globbed=False, default='relpath'):
+def matchandpats(ctx, pats=[], opts={}, globbed=False, default='relpath',
+ badfn=None):
'''Return a matcher and the patterns that were used.
- The matcher will warn about bad matches.'''
+ The matcher will warn about bad matches, unless an alternate badfn callback
+ is provided.'''
if pats == ("",):
pats = []
if not globbed and default == 'relpath':
pats = expandpats(pats or [])
- def badfn(f, msg):
+ def bad(f, msg):
ctx.repo().ui.warn("%s: %s\n" % (m.rel(f), msg))
+ if badfn is None:
+ badfn = bad
+
m = ctx.match(pats, opts.get('include'), opts.get('exclude'),
default, listsubrepos=opts.get('subrepos'), badfn=badfn)
@@ -808,17 +813,17 @@
pats = []
return m, pats
-def match(ctx, pats=[], opts={}, globbed=False, default='relpath'):
+def match(ctx, pats=[], opts={}, globbed=False, default='relpath', badfn=None):
'''Return a matcher that will warn about bad matches.'''
- return matchandpats(ctx, pats, opts, globbed, default)[0]
+ return matchandpats(ctx, pats, opts, globbed, default, badfn=badfn)[0]
def matchall(repo):
'''Return a matcher that will efficiently match everything.'''
return matchmod.always(repo.root, repo.getcwd())
-def matchfiles(repo, files):
+def matchfiles(repo, files, badfn=None):
'''Return a matcher that will efficiently match exactly these files.'''
- return matchmod.exact(repo.root, repo.getcwd(), files)
+ return matchmod.exact(repo.root, repo.getcwd(), files, badfn=badfn)
def addremove(repo, matcher, prefix, opts={}, dry_run=None, similarity=None):
m = matcher
@@ -885,9 +890,8 @@
def marktouched(repo, files, similarity=0.0):
'''Assert that files have somehow been operated upon. files are relative to
the repo root.'''
- m = matchfiles(repo, files)
+ m = matchfiles(repo, files, badfn=lambda x, y: rejected.append(x))
rejected = []
- m.bad = lambda x, y: rejected.append(x)
added, unknown, deleted, removed, forgotten = _interestingfiles(repo, m)