errors: format "abort: " text in a new Abort.format() method
This remove some duplication we had.
Differential Revision: https://phab.mercurial-scm.org/D9348
errors: make formatparse() an instance method on ParseError
It's just a little simpler this way.
Don't ask me what the "hg: " prefix signifies to the user, I just left
it as it was. I think we should consider changing the prefixes later
(maybe always use "abort: ", or maybe use more specific prefixes in
general).
Differential Revision: https://phab.mercurial-scm.org/D9347
errors: create "similarity hint" for UnknownIdentifier eagerly in constructor
No code wanted to do anything but to produce a hint from it anyway, so
we might as well just store the hint in the exception (which already
extended `Hint`). That way we can easily convert it to a
`ConfigException` when it's parsing of configuration that fails.
I was wondering if the purpose of lazily creating the string was so we
don't create it in cases where it won't get printed anyway. However, I
couldn't find any places where that could happen. If we do find such
places, we could instead revert to making it lazy but add a function
on `UnknownIdentifier` for creating the hint string.
I dropped the comment saying "make sure to check fileset first, as
revset can invoke fileset", which was added in
4e240d6ab898 (dispatch:
offer near-edit-distance suggestions for {file,rev}set functions,
2015-01-26). I couldn't figure out what it meant. The author of that
patch also did not remember the reason for it. Perhaps changes that
have happened since then made it so it no longer matters.
Differential Revision: https://phab.mercurial-scm.org/D9346
errors: move similarity_hint() to error module
I want to be able to reuse it from `UnknownIdentifier`'s constructor.
Moving it results in a new import of `difflib` in the `error`
module. There was a comment at the top of `error.py` saying "Do not
import anything but pycompat here, please", which was added (except
for the "pycompat" bit) in
08cabecfa8a8 (errors: move revlog errors,
2009-01-11). I don't know the reason for the comment. I'm guessing the
point was to not make the module depend on other Mercurial modules. If
that was it, then importing `difflib` should be fine.
Sorry about the churn (I moved this code from the `dispatch` module to
the `scmutil` module very recently).
Differential Revision: https://phab.mercurial-scm.org/D9345
errors: morph reportsimilar() into similarity_hint()
The next step is to eagerly create the hint in `UnknownIdentifier`'s
constructor.
Differential Revision: https://phab.mercurial-scm.org/D9344
errors: restructure formatparse() to clarify conditions a bit
The `similar` list will be calculated only for
`error.UnknownIdentifier`. It was then printed only if `inst.location
is None`, which is true for that exception type, but it's an indirect
condition to rely on.
Also, it looked from the code like it could both report similarities
and print a hint. That would be a little awkward because the
similarity report looks similar to the hint (both are printed within
parentheses). I also added a `elif` to clarify that. I plan to
refactor this more coming patches so the similarity report actually is
a hint.
Differential Revision: https://phab.mercurial-scm.org/D9343
pyoxidizer: run buildifier
Differential Revision: https://phab.mercurial-scm.org/D9342
errors: raise InputError in `hg absorb`
Differential Revision: https://phab.mercurial-scm.org/D9340