Commit Graph

64 Commits

Author SHA1 Message Date
Jun Wu
6d7c287ab2 ui: split config handling to a separate class
Summary:
A large portion of `ui` is config handling. Split it to a separate class so we
can pass that separate class to places that need pure configuration.

Some `develwarn`s are skipped since the new class does not have access to fout
or ferr.

Reviewed By: DurhamG

Differential Revision: D16683787

fbshipit-source-id: d823b9e5fc6f8ed08fff3401ab3502ad3c434f00
2019-08-15 12:47:35 -07:00
Jun Wu
6f0cd67661 logging: migrate profiling output to new blackbox format
Summary: The profiling result is now logged as a native Rust Event::Profile type.

Reviewed By: markbt

Differential Revision: D15710674

fbshipit-source-id: 699324937c07e7f639c93570a56b4f26ea0dddf1
2019-07-06 02:46:16 -07:00
Jun Wu
c754e0147b commands: provide in-core blackbox command
Summary:
The in-core blackbox command displays blackbox entries in the given time range.

The `blackbox` command provided by the blackbox extension was removed. They
can still be accessed via `.hg/blackbox.log`, though.

Tests are updated. Most `| grep` patterns were changed to use structured pattern
matching `--pattern` instead. Tests that are not interesting (ex. bundlebackup,
since we are moving away from bundle files slowly) are just removed.

Reviewed By: markbt

Differential Revision: D15640718

fbshipit-source-id: 7e5da60ca2b15ae9495d0242b340a066979d5a4f
2019-06-26 11:03:27 -07:00
Mark Thomas
57ed970fed blackbox: only log current commit if the changelog has been loaded
Summary:
When writing a blackbox log entry, only include the current commit if the repo
has already loaded the changelog.  Otherwise, finding out what the current
commit is will load the changelog, which is wasteful, and may cause a
re-entrant call back into blackbox logging.

Reviewed By: xavierd

Differential Revision: D15539413

fbshipit-source-id: 48c27b053b9db7ce5c2d4b1991020adaea720c21
2019-05-30 04:02:54 -07:00
Jun Wu
31c8ecbdf4 dispatch: print shorter crash header
Summary:
Change the crash header to just a single line without blaming extensions or
Python. This makes the crash log shorter, and easier to read when there are
crashes in run-tests.py diffs.

Remove `ui.supportcontact` since it's no longer used.

Reviewed By: sfilipco

Differential Revision: D14393982

fbshipit-source-id: 3ede8d3d3d8fd5d125944a9a750350d3ce356b14
2019-04-04 23:38:34 -07:00
Jun Wu
9dc21f8d0b codemod: import from the edenscm package
Summary:
D13853115 adds `edenscm/` to `sys.path` and code still uses `import mercurial`.
That has nasty problems if both `import mercurial` and
`import edenscm.mercurial` are used, because Python would think `mercurial.foo`
and `edenscm.mercurial.foo` are different modules so code like
`try: ... except mercurial.error.Foo: ...`, or `isinstance(x, mercurial.foo.Bar)`
would fail to handle the `edenscm.mercurial` version. There are also some
module-level states (ex. `extensions._extensions`) that would cause trouble if
they have multiple versions in a single process.

Change imports to use the `edenscm` so ideally the `mercurial` is no longer
imported at all. Add checks in extensions.py to catch unexpected extensions
importing modules from the old (wrong) locations when running tests.

Reviewed By: phillco

Differential Revision: D13868981

fbshipit-source-id: f4e2513766957fd81d85407994f7521a08e4de48
2019-01-29 17:25:32 -08:00
Mark Thomas
78e2b44b06 localrepo: devel-warn when accessing repo.vfs directly
Summary:
Callers should prefer repo.localvfs (or perhaps repo.sharedvfs) rather than
calling repo.vfs directly.  Warn when repo.vfs is accessed directly.

Reviewed By: quark-zju

Differential Revision: D9699167

fbshipit-source-id: 83b43fd347da6e68376eaab081b7f6e2d8c5d044
2018-09-28 07:23:02 -07:00
Kostia Balytskyi
a2307a1009 hg: make test-devel-warnings.t compatible with Rust binary
Reviewed By: quark-zju

Differential Revision: D9368559

fbshipit-source-id: 875fadbd4ba4cadb45af697af3f9ab4502d7c2b0
2018-08-17 10:51:47 -07:00
Kostia Balytskyi
ff36c006e6 hg: move hg entrypoint to the mercurial dir
Summary:
We want to have two possible Python entry points for Mercurial:
- pure-python one (`hg/hg` script, the one which is renamed into `hg.real` during FB installation)
- the one to be called from a Rust binary

The reason we can't reuse the `hg/hg` to be called form the Rust binary is because this script will eventually not exist. We also need something in the known location, so we chose to put `entrypoint.py` into `mercurial/`.

This means that both the `hg` script and the `hg.rust` binary need to be able to find the `mercurial/` directory on the system. Traditionally, `hg` contained a `LIBDIR@` string, which was replaced with the parent directory of a `mercurial/` dir at install time. Thus we could install Mercurial in non-standard locations if we needed to. We keep this functionality for the `hg` script.

`mercurial/entrypoint.py` however knows that it lives under `mercurial/` and that `hgext/` and `hgdemandimport/` live alongside `mercurial/`. Thus, the parent dir of `mercurial/` is added as a first item of `sys,path` in `entrypoint.py`.

In case `entrypoint.py` is called from a Rust binary, Python import logic also adds the entire `mercurial/` dir to `sys.path`. This is not desired, since we use `absolute_import` and want to only be able to import things as `from mercurial import smth`. A good example is `json`: even with `absolute_import` enabled `import json` loads `mercurial/json.py` if hg is called as a Rust binary. Therefore, we explicitly remove `mercurial/` from `sys.path`.

Reviewed By: quark-zju

Differential Revision: D9336157

fbshipit-source-id: 22f69e7782d549915c91ef9a0ad0ed29f62a9304
2018-08-17 10:51:47 -07:00
Jun Wu
97c36a4139 test-devel-warnings: work with fsmonitor
Summary:
fsmonitor would trigger buggylocking before the test extension. So let's update
the test to skip that part if fsmonitor is used.

Reviewed By: DurhamG

Differential Revision: D8869845

fbshipit-source-id: ef88e06be85de472a53d4b678e331a8374ccc9b1
2018-07-17 16:06:06 -07:00
Jun Wu
f5924da1d3 tests: improve test compatibility with different zlib
Summary:
When running with a Python runtime with a slightly different zlib module,
some `zlib.compress` outputs are different. Some tests are testing the
length, or the content of `zlib.compress` output, directly or indirectly.
That's causing issues.

This patch adds a `common-zlib` hghave test so it can be used to gate tests
checking zlib output. Some lengths are also changed to glob patterns to be
compatible.

Reviewed By: ryanmce

Differential Revision: D6937735

fbshipit-source-id: 2328a39d7f2022f16d51f61b6178568b26dfe2fb
2018-04-13 21:51:09 -07:00
Jun Wu
beb6c1d415 traceback: do not check actual traceback content
Summary:
Both chg and a packed python binary can add extra traceback
entries. So let's grep out the important lines.

Reviewed By: DurhamG

Differential Revision: D6879869

fbshipit-source-id: e97de7d2cfe512de2340ebb25e8ac93c360d5b9e
2018-04-13 21:51:02 -07:00
Phil Cohen
72085d2e96 testdir: fix test-extension.t for DEFAULT_EXTENSIONS
Differential Revision: https://phabricator.intern.facebook.com/D6718663
2018-01-14 14:53:52 -08:00
Durham Goode
43c7bbda26 tests: drop devel warn lines
The hotfix that drops devel warnings lost it's test fixes in the latest rebase.
This adds them back.
(grafted from c8005d3b0d065f148672e799b4a05821dacf76f5)
(grafted from a0134574e5429c6c8b493270fe2e050e707401fb)
(grafted from 5d7d4d7c382dbdfdbee29f756ed89d2923716f06)
(grafted from 17a1c05f7dd723447808f146c47e778486e34c72)
(grafted from 94d0e522d808f5126a48be614838ffa125e2b001)
(grafted from 75c5f73252a5bae8742b0323ea689ca858baa753)
(grafted from 5c48dc2dea6a08c511f0b535eb4647d5c675bd30)
(grafted from 7817f8cc763105df882b96304285c7bf0763b1c4)
(grafted from 67951163d1fcc3f69542deae05cd8a118e2cdc6b)
(grafted from 4652ab4536eaf1fa8280ea40dfa40e2f6f18dcf1)
2018-01-03 05:35:56 -08:00
Yuya Nishihara
21161a9bda configitems: relax warning about unwanted default value
The original condition was a bit harsh for extension authors since third-party
extensions need to preserve compatibility with older Mercurial versions, where
no defaults would be loaded from the configtable. So let's silence the warning
if the given default value matches, which should be harmless.
2017-10-31 22:37:30 +09:00
Boris Feld
38f9c73dbd configitems: adds a developer warning when accessing undeclared configuration
Now that all known options are declared, we setup a warning to make sure it will
stay this way.

We disable the warning in two tests checking other behavior with random options.
2017-10-16 17:41:27 +02:00
Saurabh Singh
93c6f3667f test-devel-warnings: make the test compatible with chg
The test fails when run with the "--chg" option. Therefore, this
commit makes it compatible with chg.

Test Plan:
Ran the test "test-devel-warnings.t' with and without the "--chg"
option

Differential Revision: https://phab.mercurial-scm.org/D915
2017-10-04 10:42:55 -07:00
Boris Feld
8744970b58 extensions: factor extra data loading out
Some of the extra data need to be registered earlier than they currently are
(eg: config items). We first factor out the logic to registered them in a small
function before reusing it in the next changeset.
2017-09-05 00:31:59 +02:00
Boris Feld
5e14d97b2b pypy: fix failing test-devel-warnings.t with Pypy5.6.0
In Pypy 5.6.0, traceback exception classes are not displayed with their full
qualified name.

Instead of displaying mercurial.error.ProgrammingError, Pypy displays
ProgrammingError.

Update the test to support both version.
2017-07-27 10:52:56 +02:00
Boris Feld
40b893532b configitems: handle case were the default value is not static
In some case, the default of one value is derived from other value. We add a
way to register them anyway and an associated devel-warning.

The registration is very naive for the moment. We might be able to have a
better way for registering each of these cases but it could be done later.
2017-07-12 23:36:10 +02:00
Boris Feld
ca27090453 reposvfs: add a ward to check if locks are properly taken
we wrap 'repo.svfs.audit' to check for the store lock when accessing file in
'.hg/store' for writing. This caught a couple of instance where the transaction
was released after the lock, we should probably have a dedicated checker for
that case.
2016-08-08 18:14:42 +02:00
Boris Feld
c9fe43d98b repovfs: add a ward to check if locks are properly taken
When the appropriate developer warnings are enabled, We wrap 'repo.vfs.audit' to
check for locks when accessing file in '.hg' for writing. Another changeset will
add a 'ward' for the store vfs (svfs).

This check system has caught a handful of locking issues that have been fixed
in previous series (mostly in 4.0). I expect another batch to be caught in third
party extensions.

We introduce two real exceptions from extensions 'blackbox.log' (because a lot of
read-only operations add entry to it), and 'last-email.txt' (because 'hg email'
is currently a read only operation and there is value to keep it this way).

In addition we are currently allowing bisect to operate outside of the lock
because the current code is a bit hard to get properly locked for now. Multiple
clean up have been made but there is still a couple of them to do and the freeze
is coming.
2017-07-11 12:38:17 +02:00
Pierre-Yves David
4488ccb959 test: glob a line number in test-devel-warnings.t
This make is simpler to edit the extensions file without side effect.
2017-07-02 01:38:08 +02:00
Pierre-Yves David
f22d338d2b test: add a small comment to explain a section of test-devel-warning
This makes each test boundaries clearer.
2017-07-02 01:37:03 +02:00
Pierre-Yves David
6b9d408177 configitems: add a devel warning for extensions items overiding core one
We do not want such case to pass silently. In the future we'll likely have
useful tool for an extension to alter the existing definition in core.
2017-06-18 19:52:54 +02:00
Pulkit Goyal
b4347ea80f py3: make sure commands name are bytes in tests 2017-06-25 08:20:05 +05:30
Pierre-Yves David
e2366ea12d configitems: register 'ui.interactive'
That item default value is a bit special (None) so this adds a second proof
that everything is still working fine.
2017-06-23 17:19:29 +02:00
Pierre-Yves David
4579a8de56 configitems: issue a devel warning when overriding default config
If the option is registered, there is already a default value available and
passing a new one is at best redundant. So we issue a deprecation warning in
this case.

(note: there will be case were the default value will not be as simple as what
is currently possible. We'll upgrade the configitems code to handle them in
time.)
2017-06-17 13:08:03 +02:00
Pulkit Goyal
ed094222db py3: make sure the commands name are bytes in test-devel-warnings.t 2017-06-20 23:50:50 +05:30
Martin von Zweigbergk
d8b160077a repair: move check for existing transaction earlier
Several benefits:

 * Gets close the comment describing it
 * Splits off unrelated comment about "backup" argument
 * Error checking is customarily done early
 * If we added an early return to the method, it would still
   consistently fail if there was an existing transaction (so
   we would find and fix that case quickly)

One test needs updating with for this change, because we no longer
create the backup bundle before we fail. I don't see much reason to
create that backup bundle. If some command was adding content and then
trying to strip it as well within the transaction, we would have a
backup for the user, but the risk of that not being discovered in
development seems very small.
2017-06-19 13:18:00 -07:00
Yuya Nishihara
1e7ba75af3 error: add hint to ProgrammingError
As the hint isn't shown by the default exception handler, we need to print
it manually. I've copied the "** " style from _exceptionwarning().
2017-05-14 15:41:27 +09:00
Yuya Nishihara
3e663dde68 registrar: move cmdutil.command to registrar module (API)
cmdutil.command wasn't a member of the registrar framework only for a
historical reason. Let's make that happen. This patch keeps cmdutil.command
as an alias for extension compatibility.
2016-01-09 23:07:20 +09:00
Yuya Nishihara
1ea92e7f19 dispatch: mark callcatch() as a private function 2017-04-15 12:58:06 +09:00
Pierre-Yves David
a185960897 util: add a way to issue deprecation warning without a UI object
Our current deprecation warning mechanism relies on ui object. They are case
where we cannot have access to the UI object. On a general basis we avoid using
the python mechanism for deprecation warning because up to Python 2.6 it is
exposing warning to unsuspecting user who cannot do anything to deal with them.

So we build a "safe" strategy to hide this warnings behind a flag in an
environment variable. The test runner set this flag so that tests show these
warning.  This will help us marker API as deprecated for extensions to update
their code.
2017-04-04 11:03:29 +02:00
Yuya Nishihara
c0606731ef revset: stop supporting predicate that returns plain list (API)
It's said to be removed after 3.9.
2017-04-02 22:01:32 +09:00
Matt Harbison
916bb7c1c1 test-blackbox: glob away quoting differences on Windows
Windows uses double quotes in these places.
2017-04-02 02:29:51 -04:00
Jun Wu
809dfffea4 repair: use ProgrammingError 2017-03-26 16:53:28 -07:00
Augie Fackler
f1710548b8 dispatch: replace mayberepr with shellquote
The quoting logic here was actually insufficient, and would have had
bogus b-prefixes on Python 3. shellquote seems more appropriate
anyway. Surprisingly, only two tests have output changes, and both of
them look reasonable to me (both are in blackbox logs).

Spotted by Yuya during review.
2017-03-19 14:23:30 -04:00
Jun Wu
f9c05a235e localrepo: use ProgrammingError
This is an example usage of ProgrammingError. Let's start migrating
RuntimeError to ProgrammingError.

The code only runs when devel.all-warnings or devel.check-locks is set, so
it does not affect the end-user experience.
2016-12-06 17:06:39 +00:00
Jun Wu
115ee04855 dispatch: move part of callcatch to scmutil
Per discussion at 7d927e65eaf2 [1], we need "callcatch" in worker.py. Move
it to scmutil.py to avoid cycles.

Note that dispatch's callcatch handles some additional high-level exceptions
related to config parsing, and commands. Moving them to scmutil will make
scmutil depend on "commands" or require "_formatparse" and "_getsimilar"
(and "difflib") to be moved as well. In the worker use-case, it is forked
when config and commands are fully loaded. So it should not care about those
exceptions.

[1]: https://www.mercurial-scm.org/pipermail/mercurial-devel/2016-August/087116.html
2016-11-24 00:48:40 +00:00
Gregory Szorc
9ac5776ef7 profiling: add a context manager that no-ops if profiling isn't enabled
And refactor dispatch.py to use it. As you can see, the resulting code
is much simpler.

I was tempted to inline _runcommand as part of writing this series.
However, a number of extensions wrap _runcommand. So keeping it around
is necessary (extensions can't easily wrap runcommand because it calls
hooks before and after command execution).
2016-08-14 17:51:12 -07:00
Jun Wu
5eaa546711 dispatch: split global error handling out so it can be reused
We may want a similar error handling at worker.py. This patch extracts the
error handling logic to "callcatch" so it can be reused.
2016-08-09 16:45:28 +01:00
Pierre-Yves David
3b0e4dbcf2 transaction: turn lack of locking into a hard failure (API)
We have been warning about transactions without locks for about a year (and
three releases), third party extensions had a fair grace period to fix their
code, we are moving lack of locking to a hard failure in order to protect users
against repository corruption.
2016-05-05 16:20:53 +02:00
Pierre-Yves David
85fe13b2bd test: extract develwarn transaction testing in its own command
The lack of locking for a transation is about to change from a warning to an
error. We first extract the test decidated to this warning to make the next
changeset clearer.
2016-05-05 16:13:22 +02:00
Pierre-Yves David
efaf172347 devel: fix a typo in a deprecation warning
Credit goes to Sean Farley for spotting it.
2016-05-11 09:34:59 +02:00
Pierre-Yves David
4bd2f39b1d devel: officially deprecate old style revset
When we introduce the develwarning, we did not had an official deprecation API
and infrastructure. We can now officially deprecate the old way with a version
deadline.
2016-05-11 09:31:47 +02:00
Pierre-Yves David
375f437d35 test: don't rely on __del__ in test-devel-warnings.t
Whatever the future of __del__ in Mercurial is, that devel-warning test is not
about testing the automatic transaction rollback and we should explicitly call
release.

This change make this tests pass with pypy, as pypy try less hard to call
__del__ at program exit.
2016-04-05 12:19:45 -07:00
timeless
7081e9f3c4 ui: log devel warnings 2016-01-29 14:37:16 +00:00
timeless
8e3dbae060 tests: relax test-devel-warnings to reduce false positives
This test is interested in warning output, so
glob away line numbers and hashes as they aren't relevant
to its core.
2016-02-03 18:59:35 +00:00
Pierre-Yves David
63cc76d3b4 ui: add a 'deprecwarn' helper to issue deprecation warnings
As discussed on the list, we are adding an official way to keep old API around
for a short time in order to help third party developer to catch up. The
deprecated API will issue developer warning (issued by default during test runs)
to warn extensions authors that they need to upgrade their code without
instantaneously breaking tool chains and normal users.

The version is passed as an explicit argument so that developer think about it
and a potential future script can automatically check for it.

This is not build as a decorator because accessing the 'ui' instance will likely
be different each time. The message is also free form because deprecated API are
replaced in a variety of ways. I'm not super happy about the final rendering of
that message, but this is a developer oriented warning and I would like to move
forward.
2015-12-05 23:05:49 -08:00