comparison mercurial/commands.py @ 48116:5ced12cfa41b

errors: raise InputError on bad revset to revrange() iff provided by the user Most callers of `scmutil.revrange()` pass in a revset provided by the user. If there are problems resolving that, it should result in an `InputError` and exit code 10 (when using detailed exit codes). However, there are also some callers that pass in revsets not provided by the user. `InputError` is not appropriate in those cases. This patch therefore introduces a wrapper around `scmutil.revrange()` that simply converts the exception type. I put it in `logcmdutil.py` since that seems to be the lowest-level module in the (poorly defined) UI layer. Differential Revision: https://phab.mercurial-scm.org/D11560
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 28 Sep 2021 08:47:11 -0700
parents b067d22dc6ad
children b74e128676d4
comparison
equal deleted inserted replaced
48115:b067d22dc6ad 48116:5ced12cfa41b
534 diffopts = patch.difffeatureopts( 534 diffopts = patch.difffeatureopts(
535 ui, opts, section=b'annotate', whitespace=True 535 ui, opts, section=b'annotate', whitespace=True
536 ) 536 )
537 skiprevs = opts.get(b'skip') 537 skiprevs = opts.get(b'skip')
538 if skiprevs: 538 if skiprevs:
539 skiprevs = scmutil.revrange(repo, skiprevs) 539 skiprevs = logcmdutil.revrange(repo, skiprevs)
540 540
541 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True) 541 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True)
542 for abs in ctx.walk(m): 542 for abs in ctx.walk(m):
543 fctx = ctx[abs] 543 fctx = ctx[abs]
544 rootfm.startitem() 544 rootfm.startitem()
1035 return 1035 return
1036 1036
1037 state = hbisect.load_state(repo) 1037 state = hbisect.load_state(repo)
1038 1038
1039 if rev: 1039 if rev:
1040 nodes = [repo[i].node() for i in scmutil.revrange(repo, rev)] 1040 nodes = [repo[i].node() for i in logcmdutil.revrange(repo, rev)]
1041 else: 1041 else:
1042 nodes = [repo.lookup(b'.')] 1042 nodes = [repo.lookup(b'.')]
1043 1043
1044 # update state 1044 # update state
1045 if good or bad or skip: 1045 if good or bad or skip:
1422 1422
1423 opts = pycompat.byteskwargs(opts) 1423 opts = pycompat.byteskwargs(opts)
1424 revs = opts.get(b'rev') 1424 revs = opts.get(b'rev')
1425 selectedbranches = None 1425 selectedbranches = None
1426 if revs: 1426 if revs:
1427 revs = scmutil.revrange(repo, revs) 1427 revs = logcmdutil.revrange(repo, revs)
1428 getbi = repo.revbranchcache().branchinfo 1428 getbi = repo.revbranchcache().branchinfo
1429 selectedbranches = {getbi(r)[0] for r in revs} 1429 selectedbranches = {getbi(r)[0] for r in revs}
1430 1430
1431 ui.pager(b'branches') 1431 ui.pager(b'branches')
1432 fm = ui.formatter(b'branches', opts) 1432 fm = ui.formatter(b'branches', opts)
1556 """ 1556 """
1557 opts = pycompat.byteskwargs(opts) 1557 opts = pycompat.byteskwargs(opts)
1558 revs = None 1558 revs = None
1559 if b'rev' in opts: 1559 if b'rev' in opts:
1560 revstrings = opts[b'rev'] 1560 revstrings = opts[b'rev']
1561 revs = scmutil.revrange(repo, revstrings) 1561 revs = logcmdutil.revrange(repo, revstrings)
1562 if revstrings and not revs: 1562 if revstrings and not revs:
1563 raise error.InputError(_(b'no commits to bundle')) 1563 raise error.InputError(_(b'no commits to bundle'))
1564 1564
1565 bundletype = opts.get(b'type', b'bzip2').lower() 1565 bundletype = opts.get(b'type', b'bzip2').lower()
1566 try: 1566 try:
1588 ) 1588 )
1589 if opts.get(b'base'): 1589 if opts.get(b'base'):
1590 ui.warn(_(b"ignoring --base because --all was specified\n")) 1590 ui.warn(_(b"ignoring --base because --all was specified\n"))
1591 base = [nullrev] 1591 base = [nullrev]
1592 else: 1592 else:
1593 base = scmutil.revrange(repo, opts.get(b'base')) 1593 base = logcmdutil.revrange(repo, opts.get(b'base'))
1594 if cgversion not in changegroup.supportedoutgoingversions(repo): 1594 if cgversion not in changegroup.supportedoutgoingversions(repo):
1595 raise error.Abort( 1595 raise error.Abort(
1596 _(b"repository does not support bundle version %s") % cgversion 1596 _(b"repository does not support bundle version %s") % cgversion
1597 ) 1597 )
1598 1598
2751 else: 2751 else:
2752 if not changesets: 2752 if not changesets:
2753 changesets = [b'.'] 2753 changesets = [b'.']
2754 2754
2755 repo = scmutil.unhidehashlikerevs(repo, changesets, b'nowarn') 2755 repo = scmutil.unhidehashlikerevs(repo, changesets, b'nowarn')
2756 revs = scmutil.revrange(repo, changesets) 2756 revs = logcmdutil.revrange(repo, changesets)
2757 2757
2758 if not revs: 2758 if not revs:
2759 raise error.InputError(_(b"export requires at least one changeset")) 2759 raise error.InputError(_(b"export requires at least one changeset"))
2760 if len(revs) > 1: 2760 if len(revs) > 1:
2761 ui.note(_(b'exporting patches:\n')) 2761 ui.note(_(b'exporting patches:\n'))
3168 else: 3168 else:
3169 if not revs: 3169 if not revs:
3170 raise error.InputError(_(b'no revisions specified')) 3170 raise error.InputError(_(b'no revisions specified'))
3171 cmdutil.checkunfinished(repo) 3171 cmdutil.checkunfinished(repo)
3172 cmdutil.bailifchanged(repo) 3172 cmdutil.bailifchanged(repo)
3173 revs = scmutil.revrange(repo, revs) 3173 revs = logcmdutil.revrange(repo, revs)
3174 3174
3175 skipped = set() 3175 skipped = set()
3176 basectx = None 3176 basectx = None
3177 if opts.get('base'): 3177 if opts.get('base'):
3178 basectx = scmutil.revsingle(repo, opts['base'], None) 3178 basectx = scmutil.revsingle(repo, opts['base'], None)
3706 heads += repo.branchheads(branch, start, opts.get(b'closed')) 3706 heads += repo.branchheads(branch, start, opts.get(b'closed'))
3707 heads = [repo[h] for h in heads] 3707 heads = [repo[h] for h in heads]
3708 3708
3709 if branchrevs: 3709 if branchrevs:
3710 branches = { 3710 branches = {
3711 repo[r].branch() for r in scmutil.revrange(repo, branchrevs) 3711 repo[r].branch() for r in logcmdutil.revrange(repo, branchrevs)
3712 } 3712 }
3713 heads = [h for h in heads if h.branch() in branches] 3713 heads = [h for h in heads if h.branch() in branches]
3714 3714
3715 if opts.get(b'active') and branchrevs: 3715 if opts.get(b'active') and branchrevs:
3716 dagheads = repo.heads(start) 3716 dagheads = repo.heads(start)
5218 5218
5219 # look for specified revision 5219 # look for specified revision
5220 revs = list(revs) 5220 revs = list(revs)
5221 revs.extend(opts[b'rev']) 5221 revs.extend(opts[b'rev'])
5222 if revs: 5222 if revs:
5223 revs = scmutil.revrange(repo, revs) 5223 revs = logcmdutil.revrange(repo, revs)
5224 else: 5224 else:
5225 # display both parents as the second parent phase can influence 5225 # display both parents as the second parent phase can influence
5226 # the phase of a merge commit 5226 # the phase of a merge commit
5227 revs = [c.rev() for c in repo[None].parents()] 5227 revs = [c.rev() for c in repo[None].parents()]
5228 5228
5733 ) 5733 )
5734 other = hg.peer(repo, opts, dest) 5734 other = hg.peer(repo, opts, dest)
5735 5735
5736 try: 5736 try:
5737 if revs: 5737 if revs:
5738 revs = [repo[r].node() for r in scmutil.revrange(repo, revs)] 5738 revs = [repo[r].node() for r in logcmdutil.revrange(repo, revs)]
5739 if not revs: 5739 if not revs:
5740 raise error.InputError( 5740 raise error.InputError(
5741 _(b"specified revisions evaluate to an empty set"), 5741 _(b"specified revisions evaluate to an empty set"),
5742 hint=_(b"use different revision arguments"), 5742 hint=_(b"use different revision arguments"),
5743 ) 5743 )