comparison mercurial/commands.py @ 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 2e9f379de0ac
children b0566467c492
comparison
equal deleted inserted replaced
14670:19197fa4c41c 14671:35c2cc322ba8
160 A foo.c 160 A foo.c
161 161
162 Returns 0 if all files are successfully added. 162 Returns 0 if all files are successfully added.
163 """ 163 """
164 164
165 m = scmutil.match(repo, pats, opts) 165 m = scmutil.match(repo[None], pats, opts)
166 rejected = cmdutil.add(ui, repo, m, opts.get('dry_run'), 166 rejected = cmdutil.add(ui, repo, m, opts.get('dry_run'),
167 opts.get('subrepos'), prefix="") 167 opts.get('subrepos'), prefix="")
168 return rejected and 1 or 0 168 return rejected and 1 or 0
169 169
170 @command('addremove', 170 @command('addremove',
260 260
261 def bad(x, y): 261 def bad(x, y):
262 raise util.Abort("%s: %s" % (x, y)) 262 raise util.Abort("%s: %s" % (x, y))
263 263
264 ctx = scmutil.revsingle(repo, opts.get('rev')) 264 ctx = scmutil.revsingle(repo, opts.get('rev'))
265 m = scmutil.match(repo, pats, opts) 265 m = scmutil.match(ctx, pats, opts)
266 m.bad = bad 266 m.bad = bad
267 follow = not opts.get('no_follow') 267 follow = not opts.get('no_follow')
268 for abs in ctx.walk(m): 268 for abs in ctx.walk(m):
269 fctx = ctx[abs] 269 fctx = ctx[abs]
270 if not opts.get('text') and util.binary(fctx.data()): 270 if not opts.get('text') and util.binary(fctx.data()):
340 dest = ui.fout 340 dest = ui.fout
341 if not prefix: 341 if not prefix:
342 prefix = os.path.basename(repo.root) + '-%h' 342 prefix = os.path.basename(repo.root) + '-%h'
343 343
344 prefix = cmdutil.makefilename(repo, prefix, node) 344 prefix = cmdutil.makefilename(repo, prefix, node)
345 matchfn = scmutil.match(repo, [], opts) 345 matchfn = scmutil.match(ctx, [], opts)
346 archival.archive(repo, dest, node, kind, not opts.get('no_decode'), 346 archival.archive(repo, dest, node, kind, not opts.get('no_decode'),
347 matchfn, prefix, subrepos=opts.get('subrepos')) 347 matchfn, prefix, subrepos=opts.get('subrepos'))
348 348
349 @command('backout', 349 @command('backout',
350 [('', 'merge', None, _('merge with old dirstate parent after backout')), 350 [('', 'merge', None, _('merge with old dirstate parent after backout')),
942 942
943 Returns 0 on success. 943 Returns 0 on success.
944 """ 944 """
945 ctx = scmutil.revsingle(repo, opts.get('rev')) 945 ctx = scmutil.revsingle(repo, opts.get('rev'))
946 err = 1 946 err = 1
947 m = scmutil.match(repo, (file1,) + pats, opts) 947 m = scmutil.match(ctx, (file1,) + pats, opts)
948 for abs in ctx.walk(m): 948 for abs in ctx.walk(m):
949 fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(), 949 fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(),
950 pathname=abs) 950 pathname=abs)
951 data = ctx[abs].data() 951 data = ctx[abs].data()
952 if opts.get('decode'): 952 if opts.get('decode'):
1089 branch = repo[None].branch() 1089 branch = repo[None].branch()
1090 bheads = repo.branchheads(branch) 1090 bheads = repo.branchheads(branch)
1091 1091
1092 node = cmdutil.commit(ui, repo, commitfunc, pats, opts) 1092 node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
1093 if not node: 1093 if not node:
1094 stat = repo.status(match=scmutil.match(repo, pats, opts)) 1094 stat = repo.status(match=scmutil.match(repo[None], pats, opts))
1095 if stat[3]: 1095 if stat[3]:
1096 ui.status(_("nothing changed (%d missing files, see 'hg status')\n") 1096 ui.status(_("nothing changed (%d missing files, see 'hg status')\n")
1097 % len(stat[3])) 1097 % len(stat[3]))
1098 else: 1098 else:
1099 ui.status(_("nothing changed\n")) 1099 ui.status(_("nothing changed\n"))
1608 def debugfileset(ui, repo, expr): 1608 def debugfileset(ui, repo, expr):
1609 '''parse and apply a fileset specification''' 1609 '''parse and apply a fileset specification'''
1610 if ui.verbose: 1610 if ui.verbose:
1611 tree = fileset.parse(expr)[0] 1611 tree = fileset.parse(expr)[0]
1612 ui.note(tree, "\n") 1612 ui.note(tree, "\n")
1613 matcher = lambda x: scmutil.match(repo, x, default='glob') 1613 matcher = lambda x: scmutil.match(repo[None], x, default='glob')
1614 1614
1615 for f in fileset.getfileset(repo[None], matcher, expr): 1615 for f in fileset.getfileset(repo[None], matcher, expr):
1616 ui.write("%s\n" % f) 1616 ui.write("%s\n" % f)
1617 1617
1618 @command('debugfsinfo', [], _('[PATH]')) 1618 @command('debugfsinfo', [], _('[PATH]'))
1855 _('[-r REV] FILE')) 1855 _('[-r REV] FILE'))
1856 def debugrename(ui, repo, file1, *pats, **opts): 1856 def debugrename(ui, repo, file1, *pats, **opts):
1857 """dump rename information""" 1857 """dump rename information"""
1858 1858
1859 ctx = scmutil.revsingle(repo, opts.get('rev')) 1859 ctx = scmutil.revsingle(repo, opts.get('rev'))
1860 m = scmutil.match(repo, (file1,) + pats, opts) 1860 m = scmutil.match(ctx, (file1,) + pats, opts)
1861 for abs in ctx.walk(m): 1861 for abs in ctx.walk(m):
1862 fctx = ctx[abs] 1862 fctx = ctx[abs]
1863 o = fctx.filelog().renamed(fctx.filenode()) 1863 o = fctx.filelog().renamed(fctx.filenode())
1864 rel = m.rel(abs) 1864 rel = m.rel(abs)
1865 if o: 1865 if o:
2104 ui.write(' revision %s\n' % v[1]) 2104 ui.write(' revision %s\n' % v[1])
2105 2105
2106 @command('debugwalk', walkopts, _('[OPTION]... [FILE]...')) 2106 @command('debugwalk', walkopts, _('[OPTION]... [FILE]...'))
2107 def debugwalk(ui, repo, *pats, **opts): 2107 def debugwalk(ui, repo, *pats, **opts):
2108 """show how files match on given patterns""" 2108 """show how files match on given patterns"""
2109 m = scmutil.match(repo, pats, opts) 2109 m = scmutil.match(repo[None], pats, opts)
2110 items = list(repo.walk(m)) 2110 items = list(repo.walk(m))
2111 if not items: 2111 if not items:
2112 return 2112 return
2113 fmt = 'f %%-%ds %%-%ds %%s' % ( 2113 fmt = 'f %%-%ds %%-%ds %%s' % (
2114 max([len(abs) for abs in items]), 2114 max([len(abs) for abs in items]),
2190 2190
2191 if reverse: 2191 if reverse:
2192 node1, node2 = node2, node1 2192 node1, node2 = node2, node1
2193 2193
2194 diffopts = patch.diffopts(ui, opts) 2194 diffopts = patch.diffopts(ui, opts)
2195 m = scmutil.match(repo, pats, opts) 2195 m = scmutil.match(repo[node2], pats, opts)
2196 cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat, 2196 cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat,
2197 listsubrepos=opts.get('subrepos')) 2197 listsubrepos=opts.get('subrepos'))
2198 2198
2199 @command('^export', 2199 @command('^export',
2200 [('o', 'output', '', 2200 [('o', 'output', '',
2270 """ 2270 """
2271 2271
2272 if not pats: 2272 if not pats:
2273 raise util.Abort(_('no files specified')) 2273 raise util.Abort(_('no files specified'))
2274 2274
2275 m = scmutil.match(repo, pats, opts) 2275 m = scmutil.match(repo[None], pats, opts)
2276 s = repo.status(match=m, clean=True) 2276 s = repo.status(match=m, clean=True)
2277 forget = sorted(s[0] + s[1] + s[3] + s[6]) 2277 forget = sorted(s[0] + s[1] + s[3] + s[6])
2278 errs = 0 2278 errs = 0
2279 2279
2280 for f in m.files(): 2280 for f in m.files():
2436 found = True 2436 found = True
2437 return found 2437 return found
2438 2438
2439 skip = {} 2439 skip = {}
2440 revfiles = {} 2440 revfiles = {}
2441 matchfn = scmutil.match(repo, pats, opts) 2441 matchfn = scmutil.match(repo[None], pats, opts)
2442 found = False 2442 found = False
2443 follow = opts.get('follow') 2443 follow = opts.get('follow')
2444 2444
2445 def prep(ctx, fns): 2445 def prep(ctx, fns):
2446 rev = ctx.rev() 2446 rev = ctx.rev()
3311 """ 3311 """
3312 end = opts.get('print0') and '\0' or '\n' 3312 end = opts.get('print0') and '\0' or '\n'
3313 rev = scmutil.revsingle(repo, opts.get('rev'), None).node() 3313 rev = scmutil.revsingle(repo, opts.get('rev'), None).node()
3314 3314
3315 ret = 1 3315 ret = 1
3316 m = scmutil.match(repo, pats, opts, default='relglob') 3316 m = scmutil.match(repo[rev], pats, opts, default='relglob')
3317 m.bad = lambda x, y: False 3317 m.bad = lambda x, y: False
3318 for abs in repo[rev].walk(m): 3318 for abs in repo[rev].walk(m):
3319 if not rev and abs not in repo.dirstate: 3319 if not rev and abs not in repo.dirstate:
3320 continue 3320 continue
3321 if opts.get('fullpath'): 3321 if opts.get('fullpath'):
3380 will appear in files:. 3380 will appear in files:.
3381 3381
3382 Returns 0 on success. 3382 Returns 0 on success.
3383 """ 3383 """
3384 3384
3385 matchfn = scmutil.match(repo, pats, opts) 3385 matchfn = scmutil.match(repo[None], pats, opts)
3386 limit = cmdutil.loglimit(opts) 3386 limit = cmdutil.loglimit(opts)
3387 count = 0 3387 count = 0
3388 3388
3389 endrev = None 3389 endrev = None
3390 if opts.get('copies') and opts.get('rev'): 3390 if opts.get('copies') and opts.get('rev'):
3435 3435
3436 revmatchfn = None 3436 revmatchfn = None
3437 if opts.get('patch') or opts.get('stat'): 3437 if opts.get('patch') or opts.get('stat'):
3438 if opts.get('follow') or opts.get('follow_first'): 3438 if opts.get('follow') or opts.get('follow_first'):
3439 # note: this might be wrong when following through merges 3439 # note: this might be wrong when following through merges
3440 revmatchfn = scmutil.match(repo, fns, default='path') 3440 revmatchfn = scmutil.match(repo[None], fns, default='path')
3441 else: 3441 else:
3442 revmatchfn = matchfn 3442 revmatchfn = matchfn
3443 3443
3444 displayer.show(ctx, copies=copies, matchfn=revmatchfn) 3444 displayer.show(ctx, copies=copies, matchfn=revmatchfn)
3445 3445
3648 """ 3648 """
3649 3649
3650 ctx = scmutil.revsingle(repo, opts.get('rev'), None) 3650 ctx = scmutil.revsingle(repo, opts.get('rev'), None)
3651 3651
3652 if file_: 3652 if file_:
3653 m = scmutil.match(repo, (file_,), opts) 3653 m = scmutil.match(ctx, (file_,), opts)
3654 if m.anypats() or len(m.files()) != 1: 3654 if m.anypats() or len(m.files()) != 1:
3655 raise util.Abort(_('can only specify an explicit filename')) 3655 raise util.Abort(_('can only specify an explicit filename'))
3656 file_ = m.files()[0] 3656 file_ = m.files()[0]
3657 filenodes = [] 3657 filenodes = []
3658 for cp in ctx.parents(): 3658 for cp in ctx.parents():
3966 ret = 0 3966 ret = 0
3967 after, force = opts.get('after'), opts.get('force') 3967 after, force = opts.get('after'), opts.get('force')
3968 if not pats and not after: 3968 if not pats and not after:
3969 raise util.Abort(_('no files specified')) 3969 raise util.Abort(_('no files specified'))
3970 3970
3971 m = scmutil.match(repo, pats, opts) 3971 m = scmutil.match(repo[None], pats, opts)
3972 s = repo.status(match=m, clean=True) 3972 s = repo.status(match=m, clean=True)
3973 modified, added, deleted, clean = s[0], s[1], s[3], s[6] 3973 modified, added, deleted, clean = s[0], s[1], s[3], s[6]
3974 3974
3975 for f in m.files(): 3975 for f in m.files():
3976 if f not in repo.dirstate and not os.path.isdir(m.rel(f)): 3976 if f not in repo.dirstate and not os.path.isdir(m.rel(f)):
4100 if not (all or pats or show or mark or unmark): 4100 if not (all or pats or show or mark or unmark):
4101 raise util.Abort(_('no files or directories specified; ' 4101 raise util.Abort(_('no files or directories specified; '
4102 'use --all to remerge all files')) 4102 'use --all to remerge all files'))
4103 4103
4104 ms = mergemod.mergestate(repo) 4104 ms = mergemod.mergestate(repo)
4105 m = scmutil.match(repo, pats, opts) 4105 m = scmutil.match(repo[None], pats, opts)
4106 ret = 0 4106 ret = 0
4107 4107
4108 for f in ms: 4108 for f in ms:
4109 if m(f): 4109 if m(f):
4110 if show: 4110 if show:
4201 4201
4202 wlock = repo.wlock() 4202 wlock = repo.wlock()
4203 try: 4203 try:
4204 # walk dirstate. 4204 # walk dirstate.
4205 4205
4206 m = scmutil.match(repo, pats, opts) 4206 m = scmutil.match(repo[None], pats, opts)
4207 m.bad = lambda x, y: False 4207 m.bad = lambda x, y: False
4208 for abs in repo.walk(m): 4208 for abs in repo.walk(m):
4209 names[abs] = m.rel(abs), m.exact(abs) 4209 names[abs] = m.rel(abs), m.exact(abs)
4210 4210
4211 # walk target manifest. 4211 # walk target manifest.
4217 for f in names: 4217 for f in names:
4218 if f.startswith(path_): 4218 if f.startswith(path_):
4219 return 4219 return
4220 ui.warn("%s: %s\n" % (m.rel(path), msg)) 4220 ui.warn("%s: %s\n" % (m.rel(path), msg))
4221 4221
4222 m = scmutil.match(repo, pats, opts) 4222 m = scmutil.match(repo[node], pats, opts)
4223 m.bad = badfn 4223 m.bad = badfn
4224 for abs in repo[node].walk(m): 4224 for abs in repo[node].walk(m):
4225 if abs not in names: 4225 if abs not in names:
4226 names[abs] = m.rel(abs), m.exact(abs) 4226 names[abs] = m.rel(abs), m.exact(abs)
4227 4227
4652 if opts.get('all'): 4652 if opts.get('all'):
4653 show += ui.quiet and (states[:4] + ['clean']) or states 4653 show += ui.quiet and (states[:4] + ['clean']) or states
4654 if not show: 4654 if not show:
4655 show = ui.quiet and states[:4] or states[:5] 4655 show = ui.quiet and states[:4] or states[:5]
4656 4656
4657 stat = repo.status(node1, node2, scmutil.match(repo, pats, opts), 4657 stat = repo.status(node1, node2, scmutil.match(repo[node2], pats, opts),
4658 'ignored' in show, 'clean' in show, 'unknown' in show, 4658 'ignored' in show, 'clean' in show, 'unknown' in show,
4659 opts.get('subrepos')) 4659 opts.get('subrepos'))
4660 changestates = zip(states, 'MAR!?IC', stat) 4660 changestates = zip(states, 'MAR!?IC', stat)
4661 4661
4662 if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'): 4662 if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'):