comparison mercurial/commands.py @ 14319:b33f3e35efb0

scmutil: move revsingle/pair/range from cmdutil This allows users at levels below the command layer to avoid import loops.
author Matt Mackall <mpm@selenic.com>
date Fri, 13 May 2011 14:06:28 -0500
parents 1f46be4689ed
children 003d63bb4fa5
comparison
equal deleted inserted replaced
14318:1f46be4689ed 14319:b33f3e35efb0
259 funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1]) 259 funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1])
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 = cmdutil.revsingle(repo, opts.get('rev')) 264 ctx = scmutil.revsingle(repo, opts.get('rev'))
265 m = cmdutil.match(repo, pats, opts) 265 m = cmdutil.match(repo, 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]
320 removed. 320 removed.
321 321
322 Returns 0 on success. 322 Returns 0 on success.
323 ''' 323 '''
324 324
325 ctx = cmdutil.revsingle(repo, opts.get('rev')) 325 ctx = scmutil.revsingle(repo, opts.get('rev'))
326 if not ctx: 326 if not ctx:
327 raise util.Abort(_('no working directory: please specify a revision')) 327 raise util.Abort(_('no working directory: please specify a revision'))
328 node = ctx.node() 328 node = ctx.node()
329 dest = cmdutil.makefilename(repo, dest, node) 329 dest = cmdutil.makefilename(repo, dest, node)
330 if os.path.realpath(dest) == repo.root: 330 if os.path.realpath(dest) == repo.root:
388 date = opts.get('date') 388 date = opts.get('date')
389 if date: 389 if date:
390 opts['date'] = util.parsedate(date) 390 opts['date'] = util.parsedate(date)
391 391
392 cmdutil.bailifchanged(repo) 392 cmdutil.bailifchanged(repo)
393 node = cmdutil.revsingle(repo, rev).node() 393 node = scmutil.revsingle(repo, rev).node()
394 394
395 op1, op2 = repo.dirstate.parents() 395 op1, op2 = repo.dirstate.parents()
396 a = repo.changelog.ancestor(op1, node) 396 a = repo.changelog.ancestor(op1, node)
397 if a != node: 397 if a != node:
398 raise util.Abort(_('cannot backout change on a different branch')) 398 raise util.Abort(_('cannot backout change on a different branch'))
571 raise util.Abort(_("failed to execute %s") % command) 571 raise util.Abort(_("failed to execute %s") % command)
572 elif status < 0: 572 elif status < 0:
573 raise util.Abort(_("%s killed") % command) 573 raise util.Abort(_("%s killed") % command)
574 else: 574 else:
575 transition = "bad" 575 transition = "bad"
576 ctx = cmdutil.revsingle(repo, rev) 576 ctx = scmutil.revsingle(repo, rev)
577 rev = None # clear for future iterations 577 rev = None # clear for future iterations
578 state[transition].append(ctx.node()) 578 state[transition].append(ctx.node())
579 ui.status(_('Changeset %d:%s: %s\n') % (ctx, ctx, transition)) 579 ui.status(_('Changeset %d:%s: %s\n') % (ctx, ctx, transition))
580 check_state(state, interactive=False) 580 check_state(state, interactive=False)
581 # bisect 581 # bisect
589 return 589 return
590 590
591 # update state 591 # update state
592 592
593 if rev: 593 if rev:
594 nodes = [repo.lookup(i) for i in cmdutil.revrange(repo, [rev])] 594 nodes = [repo.lookup(i) for i in scmutil.revrange(repo, [rev])]
595 else: 595 else:
596 nodes = [repo.lookup('.')] 596 nodes = [repo.lookup('.')]
597 597
598 if good or bad or skip: 598 if good or bad or skip:
599 if good: 599 if good:
874 874
875 Returns 0 on success, 1 if no changes found. 875 Returns 0 on success, 1 if no changes found.
876 """ 876 """
877 revs = None 877 revs = None
878 if 'rev' in opts: 878 if 'rev' in opts:
879 revs = cmdutil.revrange(repo, opts['rev']) 879 revs = scmutil.revrange(repo, opts['rev'])
880 880
881 if opts.get('all'): 881 if opts.get('all'):
882 base = ['null'] 882 base = ['null']
883 else: 883 else:
884 base = cmdutil.revrange(repo, opts.get('base')) 884 base = scmutil.revrange(repo, opts.get('base'))
885 if base: 885 if base:
886 if dest: 886 if dest:
887 raise util.Abort(_("--base is incompatible with specifying " 887 raise util.Abort(_("--base is incompatible with specifying "
888 "a destination")) 888 "a destination"))
889 common = [repo.lookup(rev) for rev in base] 889 common = [repo.lookup(rev) for rev in base]
933 :``%d``: dirname of file being printed, or '.' if in repository root 933 :``%d``: dirname of file being printed, or '.' if in repository root
934 :``%p``: root-relative path name of file being printed 934 :``%p``: root-relative path name of file being printed
935 935
936 Returns 0 on success. 936 Returns 0 on success.
937 """ 937 """
938 ctx = cmdutil.revsingle(repo, opts.get('rev')) 938 ctx = scmutil.revsingle(repo, opts.get('rev'))
939 err = 1 939 err = 1
940 m = cmdutil.match(repo, (file1,) + pats, opts) 940 m = cmdutil.match(repo, (file1,) + pats, opts)
941 for abs in ctx.walk(m): 941 for abs in ctx.walk(m):
942 fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(), 942 fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(),
943 pathname=abs) 943 pathname=abs)
1829 @command('debugrebuildstate', 1829 @command('debugrebuildstate',
1830 [('r', 'rev', '', _('revision to rebuild to'), _('REV'))], 1830 [('r', 'rev', '', _('revision to rebuild to'), _('REV'))],
1831 _('[-r REV] [REV]')) 1831 _('[-r REV] [REV]'))
1832 def debugrebuildstate(ui, repo, rev="tip"): 1832 def debugrebuildstate(ui, repo, rev="tip"):
1833 """rebuild the dirstate as it would look like for the given revision""" 1833 """rebuild the dirstate as it would look like for the given revision"""
1834 ctx = cmdutil.revsingle(repo, rev) 1834 ctx = scmutil.revsingle(repo, rev)
1835 wlock = repo.wlock() 1835 wlock = repo.wlock()
1836 try: 1836 try:
1837 repo.dirstate.rebuild(ctx.node(), ctx.manifest()) 1837 repo.dirstate.rebuild(ctx.node(), ctx.manifest())
1838 finally: 1838 finally:
1839 wlock.release() 1839 wlock.release()
1842 [('r', 'rev', '', _('revision to debug'), _('REV'))], 1842 [('r', 'rev', '', _('revision to debug'), _('REV'))],
1843 _('[-r REV] FILE')) 1843 _('[-r REV] FILE'))
1844 def debugrename(ui, repo, file1, *pats, **opts): 1844 def debugrename(ui, repo, file1, *pats, **opts):
1845 """dump rename information""" 1845 """dump rename information"""
1846 1846
1847 ctx = cmdutil.revsingle(repo, opts.get('rev')) 1847 ctx = scmutil.revsingle(repo, opts.get('rev'))
1848 m = cmdutil.match(repo, (file1,) + pats, opts) 1848 m = cmdutil.match(repo, (file1,) + pats, opts)
1849 for abs in ctx.walk(m): 1849 for abs in ctx.walk(m):
1850 fctx = ctx[abs] 1850 fctx = ctx[abs]
1851 o = fctx.filelog().renamed(fctx.filenode()) 1851 o = fctx.filelog().renamed(fctx.filenode())
1852 rel = m.rel(abs) 1852 rel = m.rel(abs)
2016 be used with care. 2016 be used with care.
2017 2017
2018 Returns 0 on success. 2018 Returns 0 on success.
2019 """ 2019 """
2020 2020
2021 r1 = cmdutil.revsingle(repo, rev1).node() 2021 r1 = scmutil.revsingle(repo, rev1).node()
2022 r2 = cmdutil.revsingle(repo, rev2, 'null').node() 2022 r2 = scmutil.revsingle(repo, rev2, 'null').node()
2023 2023
2024 wlock = repo.wlock() 2024 wlock = repo.wlock()
2025 try: 2025 try:
2026 repo.dirstate.setparents(r1, r2) 2026 repo.dirstate.setparents(r1, r2)
2027 finally: 2027 finally:
2062 @command('debugsub', 2062 @command('debugsub',
2063 [('r', 'rev', '', 2063 [('r', 'rev', '',
2064 _('revision to check'), _('REV'))], 2064 _('revision to check'), _('REV'))],
2065 _('[-r REV] [REV]')) 2065 _('[-r REV] [REV]'))
2066 def debugsub(ui, repo, rev=None): 2066 def debugsub(ui, repo, rev=None):
2067 ctx = cmdutil.revsingle(repo, rev, None) 2067 ctx = scmutil.revsingle(repo, rev, None)
2068 for k, v in sorted(ctx.substate.items()): 2068 for k, v in sorted(ctx.substate.items()):
2069 ui.write('path %s\n' % k) 2069 ui.write('path %s\n' % k)
2070 ui.write(' source %s\n' % v[0]) 2070 ui.write(' source %s\n' % v[0])
2071 ui.write(' revision %s\n' % v[1]) 2071 ui.write(' revision %s\n' % v[1])
2072 2072
2148 2148
2149 if revs and change: 2149 if revs and change:
2150 msg = _('cannot specify --rev and --change at the same time') 2150 msg = _('cannot specify --rev and --change at the same time')
2151 raise util.Abort(msg) 2151 raise util.Abort(msg)
2152 elif change: 2152 elif change:
2153 node2 = cmdutil.revsingle(repo, change, None).node() 2153 node2 = scmutil.revsingle(repo, change, None).node()
2154 node1 = repo[node2].p1().node() 2154 node1 = repo[node2].p1().node()
2155 else: 2155 else:
2156 node1, node2 = cmdutil.revpair(repo, revs) 2156 node1, node2 = scmutil.revpair(repo, revs)
2157 2157
2158 if reverse: 2158 if reverse:
2159 node1, node2 = node2, node1 2159 node1, node2 = node2, node1
2160 2160
2161 diffopts = patch.diffopts(ui, opts) 2161 diffopts = patch.diffopts(ui, opts)
2209 Returns 0 on success. 2209 Returns 0 on success.
2210 """ 2210 """
2211 changesets += tuple(opts.get('rev', [])) 2211 changesets += tuple(opts.get('rev', []))
2212 if not changesets: 2212 if not changesets:
2213 raise util.Abort(_("export requires at least one changeset")) 2213 raise util.Abort(_("export requires at least one changeset"))
2214 revs = cmdutil.revrange(repo, changesets) 2214 revs = scmutil.revrange(repo, changesets)
2215 if len(revs) > 1: 2215 if len(revs) > 1:
2216 ui.note(_('exporting patches:\n')) 2216 ui.note(_('exporting patches:\n'))
2217 else: 2217 else:
2218 ui.note(_('exporting patch:\n')) 2218 ui.note(_('exporting patch:\n'))
2219 cmdutil.export(repo, revs, template=opts.get('output'), 2219 cmdutil.export(repo, revs, template=opts.get('output'),
2499 Returns 0 if matching heads are found, 1 if not. 2499 Returns 0 if matching heads are found, 1 if not.
2500 """ 2500 """
2501 2501
2502 start = None 2502 start = None
2503 if 'rev' in opts: 2503 if 'rev' in opts:
2504 start = cmdutil.revsingle(repo, opts['rev'], None).node() 2504 start = scmutil.revsingle(repo, opts['rev'], None).node()
2505 2505
2506 if opts.get('topo'): 2506 if opts.get('topo'):
2507 heads = [repo[h] for h in repo.heads(start)] 2507 heads = [repo[h] for h in repo.heads(start)]
2508 else: 2508 else:
2509 heads = [] 2509 heads = []
2942 ('+'.join([hexfunc(p.node()) for p in parents]), changed)] 2942 ('+'.join([hexfunc(p.node()) for p in parents]), changed)]
2943 if num: 2943 if num:
2944 output.append("%s%s" % 2944 output.append("%s%s" %
2945 ('+'.join([str(p.rev()) for p in parents]), changed)) 2945 ('+'.join([str(p.rev()) for p in parents]), changed))
2946 else: 2946 else:
2947 ctx = cmdutil.revsingle(repo, rev) 2947 ctx = scmutil.revsingle(repo, rev)
2948 if default or id: 2948 if default or id:
2949 output = [hexfunc(ctx.node())] 2949 output = [hexfunc(ctx.node())]
2950 if num: 2950 if num:
2951 output.append(str(ctx.rev())) 2951 output.append(str(ctx.rev()))
2952 2952
3233 contain whitespace as multiple filenames. 3233 contain whitespace as multiple filenames.
3234 3234
3235 Returns 0 if a match is found, 1 otherwise. 3235 Returns 0 if a match is found, 1 otherwise.
3236 """ 3236 """
3237 end = opts.get('print0') and '\0' or '\n' 3237 end = opts.get('print0') and '\0' or '\n'
3238 rev = cmdutil.revsingle(repo, opts.get('rev'), None).node() 3238 rev = scmutil.revsingle(repo, opts.get('rev'), None).node()
3239 3239
3240 ret = 1 3240 ret = 1
3241 m = cmdutil.match(repo, pats, opts, default='relglob') 3241 m = cmdutil.match(repo, pats, opts, default='relglob')
3242 m.bad = lambda x, y: False 3242 m.bad = lambda x, y: False
3243 for abs in repo[rev].walk(m): 3243 for abs in repo[rev].walk(m):
3310 limit = cmdutil.loglimit(opts) 3310 limit = cmdutil.loglimit(opts)
3311 count = 0 3311 count = 0
3312 3312
3313 endrev = None 3313 endrev = None
3314 if opts.get('copies') and opts.get('rev'): 3314 if opts.get('copies') and opts.get('rev'):
3315 endrev = max(cmdutil.revrange(repo, opts.get('rev'))) + 1 3315 endrev = max(scmutil.revrange(repo, opts.get('rev'))) + 1
3316 3316
3317 df = False 3317 df = False
3318 if opts["date"]: 3318 if opts["date"]:
3319 df = util.matchdate(opts["date"]) 3319 df = util.matchdate(opts["date"])
3320 3320
3393 3393
3394 if not node: 3394 if not node:
3395 node = rev 3395 node = rev
3396 3396
3397 decor = {'l':'644 @ ', 'x':'755 * ', '':'644 '} 3397 decor = {'l':'644 @ ', 'x':'755 * ', '':'644 '}
3398 ctx = cmdutil.revsingle(repo, node) 3398 ctx = scmutil.revsingle(repo, node)
3399 for f in ctx: 3399 for f in ctx:
3400 if ui.debugflag: 3400 if ui.debugflag:
3401 ui.write("%40s " % hex(ctx.manifest()[f])) 3401 ui.write("%40s " % hex(ctx.manifest()[f]))
3402 if ui.verbose: 3402 if ui.verbose:
3403 ui.write(decor[ctx.flags(f)]) 3403 ui.write(decor[ctx.flags(f)])
3469 raise util.Abort(_('working directory not at a head revision'), 3469 raise util.Abort(_('working directory not at a head revision'),
3470 hint=_("use 'hg update' or merge with an " 3470 hint=_("use 'hg update' or merge with an "
3471 "explicit revision")) 3471 "explicit revision"))
3472 node = parent == bheads[0] and bheads[-1] or bheads[0] 3472 node = parent == bheads[0] and bheads[-1] or bheads[0]
3473 else: 3473 else:
3474 node = cmdutil.revsingle(repo, node).node() 3474 node = scmutil.revsingle(repo, node).node()
3475 3475
3476 if opts.get('preview'): 3476 if opts.get('preview'):
3477 # find nodes that are ancestors of p2 but not of p1 3477 # find nodes that are ancestors of p2 but not of p1
3478 p1 = repo.lookup('.') 3478 p1 = repo.lookup('.')
3479 p2 = repo.lookup(node) 3479 p2 = repo.lookup(node)
3541 argument to --rev if given) is printed. 3541 argument to --rev if given) is printed.
3542 3542
3543 Returns 0 on success. 3543 Returns 0 on success.
3544 """ 3544 """
3545 3545
3546 ctx = cmdutil.revsingle(repo, opts.get('rev'), None) 3546 ctx = scmutil.revsingle(repo, opts.get('rev'), None)
3547 3547
3548 if file_: 3548 if file_:
3549 m = cmdutil.match(repo, (file_,), opts) 3549 m = cmdutil.match(repo, (file_,), opts)
3550 if m.anypats() or len(m.files()) != 1: 3550 if m.anypats() or len(m.files()) != 1:
3551 raise util.Abort(_('can only specify an explicit filename')) 3551 raise util.Abort(_('can only specify an explicit filename'))
4072 4072
4073 if not pats and not opts.get('all'): 4073 if not pats and not opts.get('all'):
4074 raise util.Abort(_('no files or directories specified; ' 4074 raise util.Abort(_('no files or directories specified; '
4075 'use --all to revert the whole repo')) 4075 'use --all to revert the whole repo'))
4076 4076
4077 ctx = cmdutil.revsingle(repo, opts.get('rev')) 4077 ctx = scmutil.revsingle(repo, opts.get('rev'))
4078 node = ctx.node() 4078 node = ctx.node()
4079 mf = ctx.manifest() 4079 mf = ctx.manifest()
4080 if node == parent: 4080 if node == parent:
4081 pmf = mf 4081 pmf = mf
4082 else: 4082 else:
4517 raise util.Abort(msg) 4517 raise util.Abort(msg)
4518 elif change: 4518 elif change:
4519 node2 = repo.lookup(change) 4519 node2 = repo.lookup(change)
4520 node1 = repo[node2].p1().node() 4520 node1 = repo[node2].p1().node()
4521 else: 4521 else:
4522 node1, node2 = cmdutil.revpair(repo, revs) 4522 node1, node2 = scmutil.revpair(repo, revs)
4523 4523
4524 cwd = (pats and repo.getcwd()) or '' 4524 cwd = (pats and repo.getcwd()) or ''
4525 end = opts.get('print0') and '\0' or '\n' 4525 end = opts.get('print0') and '\0' or '\n'
4526 copy = {} 4526 copy = {}
4527 states = 'modified added removed deleted unknown ignored clean'.split() 4527 states = 'modified added removed deleted unknown ignored clean'.split()
4808 if p2 != nullid: 4808 if p2 != nullid:
4809 raise util.Abort(_('uncommitted merge')) 4809 raise util.Abort(_('uncommitted merge'))
4810 bheads = repo.branchheads() 4810 bheads = repo.branchheads()
4811 if not opts.get('force') and bheads and p1 not in bheads: 4811 if not opts.get('force') and bheads and p1 not in bheads:
4812 raise util.Abort(_('not at a branch head (use -f to force)')) 4812 raise util.Abort(_('not at a branch head (use -f to force)'))
4813 r = cmdutil.revsingle(repo, rev_).node() 4813 r = scmutil.revsingle(repo, rev_).node()
4814 4814
4815 if not message: 4815 if not message:
4816 # we don't translate commit messages 4816 # we don't translate commit messages
4817 message = ('Added tag %s for changeset %s' % 4817 message = ('Added tag %s for changeset %s' %
4818 (', '.join(names), short(r))) 4818 (', '.join(names), short(r)))
4959 if rev is None or rev == '': 4959 if rev is None or rev == '':
4960 rev = node 4960 rev = node
4961 4961
4962 # if we defined a bookmark, we have to remember the original bookmark name 4962 # if we defined a bookmark, we have to remember the original bookmark name
4963 brev = rev 4963 brev = rev
4964 rev = cmdutil.revsingle(repo, rev, rev).rev() 4964 rev = scmutil.revsingle(repo, rev, rev).rev()
4965 4965
4966 if check and clean: 4966 if check and clean:
4967 raise util.Abort(_("cannot specify both -c/--check and -C/--clean")) 4967 raise util.Abort(_("cannot specify both -c/--check and -C/--clean"))
4968 4968
4969 if check: 4969 if check: