Mercurial > hg-stable
changeset 14671:35c2cc322ba8
scmutil: switch match users to supplying contexts
The most appropriate context is not always clearly defined. The obvious cases:
For working directory commands, we use None
For commands (eg annotate) with single revs, we use that revision
The less obvious cases:
For commands (eg status, diff) with a pair of revs, we use the second revision
For commands that take a range (like log), we use None
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sat, 18 Jun 2011 16:52:51 -0500 |
parents | 19197fa4c41c |
children | 785bbc8634f8 |
files | contrib/perf.py hgext/churn.py hgext/extdiff.py hgext/hgk.py hgext/keyword.py hgext/mq.py hgext/purge.py mercurial/cmdutil.py mercurial/commands.py mercurial/scmutil.py tests/autodiff.py |
diffstat | 11 files changed, 38 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/perf.py Sat Jun 18 16:52:51 2011 -0500 +++ b/contrib/perf.py Sat Jun 18 16:52:51 2011 -0500 @@ -31,11 +31,11 @@ def perfwalk(ui, repo, *pats): try: - m = scmutil.match(repo, pats, {}) + m = scmutil.match(repo[None], pats, {}) timer(lambda: len(list(repo.dirstate.walk(m, [], True, False)))) except: try: - m = scmutil.match(repo, pats, {}) + m = scmutil.match(repo[None], pats, {}) timer(lambda: len([b for a, b, c in repo.dirstate.statwalk([], m)])) except: timer(lambda: len(list(cmdutil.walk(repo, pats, {}))))
--- a/hgext/churn.py Sat Jun 18 16:52:51 2011 -0500 +++ b/hgext/churn.py Sat Jun 18 16:52:51 2011 -0500 @@ -54,7 +54,7 @@ if opts.get('date'): df = util.matchdate(opts['date']) - m = scmutil.match(repo, pats, opts) + m = scmutil.match(repo[None], pats, opts) def prep(ctx, fns): rev = ctx.rev() if df and not df(ctx.date()[0]): # doesn't match date format
--- a/hgext/extdiff.py Sat Jun 18 16:52:51 2011 -0500 +++ b/hgext/extdiff.py Sat Jun 18 16:52:51 2011 -0500 @@ -137,7 +137,7 @@ if node1b == nullid: do3way = False - matcher = scmutil.match(repo, pats, opts) + matcher = scmutil.match(repo[node2], pats, opts) mod_a, add_a, rem_a = map(set, repo.status(node1a, node2, matcher)[:3]) if do3way: mod_b, add_b, rem_b = map(set, repo.status(node1b, node2, matcher)[:3])
--- a/hgext/hgk.py Sat Jun 18 16:52:51 2011 -0500 +++ b/hgext/hgk.py Sat Jun 18 16:52:51 2011 -0500 @@ -45,7 +45,7 @@ assert node2 is not None mmap = repo[node1].manifest() mmap2 = repo[node2].manifest() - m = scmutil.match(repo, files) + m = scmutil.match(repo[node1], files) modified, added, removed = repo.status(node1, node2, m)[:3] empty = short(nullid) @@ -81,7 +81,7 @@ if opts['patch']: if opts['pretty']: catcommit(ui, repo, node2, "") - m = scmutil.match(repo, files) + m = scmutil.match(repo[node1], files) chunks = patch.diff(repo, node1, node2, match=m, opts=patch.diffopts(ui, {'git': True})) for chunk in chunks:
--- a/hgext/keyword.py Sat Jun 18 16:52:51 2011 -0500 +++ b/hgext/keyword.py Sat Jun 18 16:52:51 2011 -0500 @@ -326,7 +326,7 @@ '''Bails out if [keyword] configuration is not active. Returns status of working directory.''' if kwt: - return repo.status(match=scmutil.match(repo, pats, opts), clean=True, + return repo.status(match=scmutil.match(repo[None], pats, opts), clean=True, unknown=opts.get('unknown') or opts.get('all')) if ui.configitems('keyword'): raise util.Abort(_('[keyword] patterns cannot match'))
--- a/hgext/mq.py Sat Jun 18 16:52:51 2011 -0500 +++ b/hgext/mq.py Sat Jun 18 16:52:51 2011 -0500 @@ -519,7 +519,7 @@ def printdiff(self, repo, diffopts, node1, node2=None, files=None, fp=None, changes=None, opts={}): stat = opts.get('stat') - m = scmutil.match(repo, files, opts) + m = scmutil.match(repo[node1], files, opts) cmdutil.diffordiffstat(self.ui, repo, diffopts, node1, node2, m, changes, stat, fp) @@ -899,7 +899,7 @@ if opts.get('include') or opts.get('exclude') or pats: if inclsubs: pats = list(pats or []) + inclsubs - match = scmutil.match(repo, pats, opts) + match = scmutil.match(repo[None], pats, opts) # detect missing files in pats def badfn(f, msg): if f != '.hgsubstate': # .hgsubstate is auto-created @@ -1380,7 +1380,7 @@ changes = repo.changelog.read(top) man = repo.manifest.read(changes[0]) aaa = aa[:] - matchfn = scmutil.match(repo, pats, opts) + matchfn = scmutil.match(repo[None], pats, opts) # in short mode, we only diff the files included in the # patch already plus specified files if opts.get('short'): @@ -1388,7 +1388,7 @@ # files plus specified files - unfiltered match = scmutil.matchfiles(repo, mm + aa + dd + matchfn.files()) # filter with inc/exl options - matchfn = scmutil.match(repo, opts=opts) + matchfn = scmutil.match(repo[None], opts=opts) else: match = scmutil.matchall(repo) m, a, r, d = repo.status(match=match)[:4]
--- a/hgext/purge.py Sat Jun 18 16:52:51 2011 -0500 +++ b/hgext/purge.py Sat Jun 18 16:52:51 2011 -0500 @@ -96,7 +96,7 @@ os.remove(path) directories = [] - match = scmutil.match(repo, dirs, opts) + match = scmutil.match(repo[None], dirs, opts) match.dir = directories.append status = repo.status(match=match, ignored=opts['all'], unknown=True)
--- a/mercurial/cmdutil.py Sat Jun 18 16:52:51 2011 -0500 +++ b/mercurial/cmdutil.py Sat Jun 18 16:52:51 2011 -0500 @@ -234,7 +234,7 @@ def walkpat(pat): srcs = [] badstates = after and '?' or '?r' - m = scmutil.match(repo, [pat], opts, globbed=True) + m = scmutil.match(repo[None], [pat], opts, globbed=True) for abs in repo.walk(m): state = repo.dirstate[abs] rel = m.rel(abs) @@ -1185,7 +1185,8 @@ if opts.get('addremove'): scmutil.addremove(repo, pats, opts) - return commitfunc(ui, repo, message, scmutil.match(repo, pats, opts), opts) + return commitfunc(ui, repo, message, + scmutil.match(repo[None], pats, opts), opts) def commiteditor(repo, ctx, subs): if ctx.description():
--- a/mercurial/commands.py Sat Jun 18 16:52:51 2011 -0500 +++ b/mercurial/commands.py Sat Jun 18 16:52:51 2011 -0500 @@ -162,7 +162,7 @@ Returns 0 if all files are successfully added. """ - m = scmutil.match(repo, pats, opts) + m = scmutil.match(repo[None], pats, opts) rejected = cmdutil.add(ui, repo, m, opts.get('dry_run'), opts.get('subrepos'), prefix="") return rejected and 1 or 0 @@ -262,7 +262,7 @@ raise util.Abort("%s: %s" % (x, y)) ctx = scmutil.revsingle(repo, opts.get('rev')) - m = scmutil.match(repo, pats, opts) + m = scmutil.match(ctx, pats, opts) m.bad = bad follow = not opts.get('no_follow') for abs in ctx.walk(m): @@ -342,7 +342,7 @@ prefix = os.path.basename(repo.root) + '-%h' prefix = cmdutil.makefilename(repo, prefix, node) - matchfn = scmutil.match(repo, [], opts) + matchfn = scmutil.match(ctx, [], opts) archival.archive(repo, dest, node, kind, not opts.get('no_decode'), matchfn, prefix, subrepos=opts.get('subrepos')) @@ -944,7 +944,7 @@ """ ctx = scmutil.revsingle(repo, opts.get('rev')) err = 1 - m = scmutil.match(repo, (file1,) + pats, opts) + m = scmutil.match(ctx, (file1,) + pats, opts) for abs in ctx.walk(m): fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(), pathname=abs) @@ -1091,7 +1091,7 @@ node = cmdutil.commit(ui, repo, commitfunc, pats, opts) if not node: - stat = repo.status(match=scmutil.match(repo, pats, opts)) + stat = repo.status(match=scmutil.match(repo[None], pats, opts)) if stat[3]: ui.status(_("nothing changed (%d missing files, see 'hg status')\n") % len(stat[3])) @@ -1610,7 +1610,7 @@ if ui.verbose: tree = fileset.parse(expr)[0] ui.note(tree, "\n") - matcher = lambda x: scmutil.match(repo, x, default='glob') + matcher = lambda x: scmutil.match(repo[None], x, default='glob') for f in fileset.getfileset(repo[None], matcher, expr): ui.write("%s\n" % f) @@ -1857,7 +1857,7 @@ """dump rename information""" ctx = scmutil.revsingle(repo, opts.get('rev')) - m = scmutil.match(repo, (file1,) + pats, opts) + m = scmutil.match(ctx, (file1,) + pats, opts) for abs in ctx.walk(m): fctx = ctx[abs] o = fctx.filelog().renamed(fctx.filenode()) @@ -2106,7 +2106,7 @@ @command('debugwalk', walkopts, _('[OPTION]... [FILE]...')) def debugwalk(ui, repo, *pats, **opts): """show how files match on given patterns""" - m = scmutil.match(repo, pats, opts) + m = scmutil.match(repo[None], pats, opts) items = list(repo.walk(m)) if not items: return @@ -2192,7 +2192,7 @@ node1, node2 = node2, node1 diffopts = patch.diffopts(ui, opts) - m = scmutil.match(repo, pats, opts) + m = scmutil.match(repo[node2], pats, opts) cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat, listsubrepos=opts.get('subrepos')) @@ -2272,7 +2272,7 @@ if not pats: raise util.Abort(_('no files specified')) - m = scmutil.match(repo, pats, opts) + m = scmutil.match(repo[None], pats, opts) s = repo.status(match=m, clean=True) forget = sorted(s[0] + s[1] + s[3] + s[6]) errs = 0 @@ -2438,7 +2438,7 @@ skip = {} revfiles = {} - matchfn = scmutil.match(repo, pats, opts) + matchfn = scmutil.match(repo[None], pats, opts) found = False follow = opts.get('follow') @@ -3313,7 +3313,7 @@ rev = scmutil.revsingle(repo, opts.get('rev'), None).node() ret = 1 - m = scmutil.match(repo, pats, opts, default='relglob') + m = scmutil.match(repo[rev], pats, opts, default='relglob') m.bad = lambda x, y: False for abs in repo[rev].walk(m): if not rev and abs not in repo.dirstate: @@ -3382,7 +3382,7 @@ Returns 0 on success. """ - matchfn = scmutil.match(repo, pats, opts) + matchfn = scmutil.match(repo[None], pats, opts) limit = cmdutil.loglimit(opts) count = 0 @@ -3437,7 +3437,7 @@ if opts.get('patch') or opts.get('stat'): if opts.get('follow') or opts.get('follow_first'): # note: this might be wrong when following through merges - revmatchfn = scmutil.match(repo, fns, default='path') + revmatchfn = scmutil.match(repo[None], fns, default='path') else: revmatchfn = matchfn @@ -3650,7 +3650,7 @@ ctx = scmutil.revsingle(repo, opts.get('rev'), None) if file_: - m = scmutil.match(repo, (file_,), opts) + m = scmutil.match(ctx, (file_,), opts) if m.anypats() or len(m.files()) != 1: raise util.Abort(_('can only specify an explicit filename')) file_ = m.files()[0] @@ -3968,7 +3968,7 @@ if not pats and not after: raise util.Abort(_('no files specified')) - m = scmutil.match(repo, pats, opts) + m = scmutil.match(repo[None], pats, opts) s = repo.status(match=m, clean=True) modified, added, deleted, clean = s[0], s[1], s[3], s[6] @@ -4102,7 +4102,7 @@ 'use --all to remerge all files')) ms = mergemod.mergestate(repo) - m = scmutil.match(repo, pats, opts) + m = scmutil.match(repo[None], pats, opts) ret = 0 for f in ms: @@ -4203,7 +4203,7 @@ try: # walk dirstate. - m = scmutil.match(repo, pats, opts) + m = scmutil.match(repo[None], pats, opts) m.bad = lambda x, y: False for abs in repo.walk(m): names[abs] = m.rel(abs), m.exact(abs) @@ -4219,7 +4219,7 @@ return ui.warn("%s: %s\n" % (m.rel(path), msg)) - m = scmutil.match(repo, pats, opts) + m = scmutil.match(repo[node], pats, opts) m.bad = badfn for abs in repo[node].walk(m): if abs not in names: @@ -4654,7 +4654,7 @@ if not show: show = ui.quiet and states[:4] or states[:5] - stat = repo.status(node1, node2, scmutil.match(repo, pats, opts), + stat = repo.status(node1, node2, scmutil.match(repo[node2], pats, opts), 'ignored' in show, 'clean' in show, 'unknown' in show, opts.get('subrepos')) changestates = zip(states, 'MAR!?IC', stat)
--- a/mercurial/scmutil.py Sat Jun 18 16:52:51 2011 -0500 +++ b/mercurial/scmutil.py Sat Jun 18 16:52:51 2011 -0500 @@ -573,7 +573,7 @@ m = ctx.match(pats, opts.get('include'), opts.get('exclude'), default) def badfn(f, msg): - repo.ui.warn("%s: %s\n" % (m.rel(f), msg)) + ctx._repo.ui.warn("%s: %s\n" % (m.rel(f), msg)) m.bad = badfn return m @@ -591,7 +591,7 @@ # we'd use status here, except handling of symlinks and ignore is tricky added, unknown, deleted, removed = [], [], [], [] audit_path = pathauditor(repo.root) - m = match(repo, pats, opts) + m = match(repo[None], pats, opts) for abs in repo.walk(m): target = repo.wjoin(abs) good = True
--- a/tests/autodiff.py Sat Jun 18 16:52:51 2011 -0500 +++ b/tests/autodiff.py Sat Jun 18 16:52:51 2011 -0500 @@ -29,7 +29,7 @@ raise util.Abort('--git must be yes, no or auto') node1, node2 = scmutil.revpair(repo, []) - m = scmutil.match(repo, pats, opts) + m = scmutil.match(repo[node2], pats, opts) it = patch.diff(repo, node1, node2, match=m, opts=diffopts, losedatafn=losedatafn) for chunk in it: