comparison mercurial/scmutil.py @ 25467:f64dbe06f3d0

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.
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 05 Jun 2015 19:24:32 -0400
parents 007a1d53f7c3
children 52e5f68d8363
comparison
equal deleted inserted replaced
25466:007a1d53f7c3 25467:f64dbe06f3d0
788 ret.extend(globbed) 788 ret.extend(globbed)
789 continue 789 continue
790 ret.append(kindpat) 790 ret.append(kindpat)
791 return ret 791 return ret
792 792
793 def matchandpats(ctx, pats=[], opts={}, globbed=False, default='relpath'): 793 def matchandpats(ctx, pats=[], opts={}, globbed=False, default='relpath',
794 badfn=None):
794 '''Return a matcher and the patterns that were used. 795 '''Return a matcher and the patterns that were used.
795 The matcher will warn about bad matches.''' 796 The matcher will warn about bad matches, unless an alternate badfn callback
797 is provided.'''
796 if pats == ("",): 798 if pats == ("",):
797 pats = [] 799 pats = []
798 if not globbed and default == 'relpath': 800 if not globbed and default == 'relpath':
799 pats = expandpats(pats or []) 801 pats = expandpats(pats or [])
800 802
801 def badfn(f, msg): 803 def bad(f, msg):
802 ctx.repo().ui.warn("%s: %s\n" % (m.rel(f), msg)) 804 ctx.repo().ui.warn("%s: %s\n" % (m.rel(f), msg))
805
806 if badfn is None:
807 badfn = bad
803 808
804 m = ctx.match(pats, opts.get('include'), opts.get('exclude'), 809 m = ctx.match(pats, opts.get('include'), opts.get('exclude'),
805 default, listsubrepos=opts.get('subrepos'), badfn=badfn) 810 default, listsubrepos=opts.get('subrepos'), badfn=badfn)
806 811
807 if m.always(): 812 if m.always():
808 pats = [] 813 pats = []
809 return m, pats 814 return m, pats
810 815
811 def match(ctx, pats=[], opts={}, globbed=False, default='relpath'): 816 def match(ctx, pats=[], opts={}, globbed=False, default='relpath', badfn=None):
812 '''Return a matcher that will warn about bad matches.''' 817 '''Return a matcher that will warn about bad matches.'''
813 return matchandpats(ctx, pats, opts, globbed, default)[0] 818 return matchandpats(ctx, pats, opts, globbed, default, badfn=badfn)[0]
814 819
815 def matchall(repo): 820 def matchall(repo):
816 '''Return a matcher that will efficiently match everything.''' 821 '''Return a matcher that will efficiently match everything.'''
817 return matchmod.always(repo.root, repo.getcwd()) 822 return matchmod.always(repo.root, repo.getcwd())
818 823
819 def matchfiles(repo, files): 824 def matchfiles(repo, files, badfn=None):
820 '''Return a matcher that will efficiently match exactly these files.''' 825 '''Return a matcher that will efficiently match exactly these files.'''
821 return matchmod.exact(repo.root, repo.getcwd(), files) 826 return matchmod.exact(repo.root, repo.getcwd(), files, badfn=badfn)
822 827
823 def addremove(repo, matcher, prefix, opts={}, dry_run=None, similarity=None): 828 def addremove(repo, matcher, prefix, opts={}, dry_run=None, similarity=None):
824 m = matcher 829 m = matcher
825 if dry_run is None: 830 if dry_run is None:
826 dry_run = opts.get('dry_run') 831 dry_run = opts.get('dry_run')
883 return ret 888 return ret
884 889
885 def marktouched(repo, files, similarity=0.0): 890 def marktouched(repo, files, similarity=0.0):
886 '''Assert that files have somehow been operated upon. files are relative to 891 '''Assert that files have somehow been operated upon. files are relative to
887 the repo root.''' 892 the repo root.'''
888 m = matchfiles(repo, files) 893 m = matchfiles(repo, files, badfn=lambda x, y: rejected.append(x))
889 rejected = [] 894 rejected = []
890 m.bad = lambda x, y: rejected.append(x)
891 895
892 added, unknown, deleted, removed, forgotten = _interestingfiles(repo, m) 896 added, unknown, deleted, removed, forgotten = _interestingfiles(repo, m)
893 897
894 if repo.ui.verbose: 898 if repo.ui.verbose:
895 unknownset = set(unknown + forgotten) 899 unknownset = set(unknown + forgotten)