comparison hgext/fix.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 66ff8d3865b3
children f12a19d03d2c
comparison
equal deleted inserted replaced
48115:b067d22dc6ad 48116:5ced12cfa41b
142 from mercurial import ( 142 from mercurial import (
143 cmdutil, 143 cmdutil,
144 context, 144 context,
145 copies, 145 copies,
146 error, 146 error,
147 logcmdutil,
147 match as matchmod, 148 match as matchmod,
148 mdiff, 149 mdiff,
149 merge, 150 merge,
150 mergestate as mergestatemod, 151 mergestate as mergestatemod,
151 obsolete, 152 obsolete,
418 def getrevstofix(ui, repo, opts): 419 def getrevstofix(ui, repo, opts):
419 """Returns the set of revision numbers that should be fixed""" 420 """Returns the set of revision numbers that should be fixed"""
420 if opts[b'all']: 421 if opts[b'all']:
421 revs = repo.revs(b'(not public() and not obsolete()) or wdir()') 422 revs = repo.revs(b'(not public() and not obsolete()) or wdir()')
422 elif opts[b'source']: 423 elif opts[b'source']:
423 source_revs = scmutil.revrange(repo, opts[b'source']) 424 source_revs = logcmdutil.revrange(repo, opts[b'source'])
424 revs = set(repo.revs(b'(%ld::) - obsolete()', source_revs)) 425 revs = set(repo.revs(b'(%ld::) - obsolete()', source_revs))
425 if wdirrev in source_revs: 426 if wdirrev in source_revs:
426 # `wdir()::` is currently empty, so manually add wdir 427 # `wdir()::` is currently empty, so manually add wdir
427 revs.add(wdirrev) 428 revs.add(wdirrev)
428 if repo[b'.'].rev() in revs: 429 if repo[b'.'].rev() in revs:
429 revs.add(wdirrev) 430 revs.add(wdirrev)
430 else: 431 else:
431 revs = set(scmutil.revrange(repo, opts[b'rev'])) 432 revs = set(logcmdutil.revrange(repo, opts[b'rev']))
432 if opts.get(b'working_dir'): 433 if opts.get(b'working_dir'):
433 revs.add(wdirrev) 434 revs.add(wdirrev)
434 for rev in revs: 435 for rev in revs:
435 checkfixablectx(ui, repo, repo[rev]) 436 checkfixablectx(ui, repo, repo[rev])
436 # Allow fixing only wdir() even if there's an unfinished operation 437 # Allow fixing only wdir() even if there's an unfinished operation
616 --whole is used. 617 --whole is used.
617 """ 618 """
618 # The --base flag overrides the usual logic, and we give every revision 619 # The --base flag overrides the usual logic, and we give every revision
619 # exactly the set of baserevs that the user specified. 620 # exactly the set of baserevs that the user specified.
620 if opts.get(b'base'): 621 if opts.get(b'base'):
621 baserevs = set(scmutil.revrange(repo, opts.get(b'base'))) 622 baserevs = set(logcmdutil.revrange(repo, opts.get(b'base')))
622 if not baserevs: 623 if not baserevs:
623 baserevs = {nullrev} 624 baserevs = {nullrev}
624 basectxs = {repo[rev] for rev in baserevs} 625 basectxs = {repo[rev] for rev in baserevs}
625 return {rev: basectxs for rev in revstofix} 626 return {rev: basectxs for rev in revstofix}
626 627