##// END OF EJS Templates
windows: degrade to py2 behavior when reading a non-symlink as a symlink...
windows: degrade to py2 behavior when reading a non-symlink as a symlink While waiting for the push to hg-committed in WSL to complete, I ran a `phabimport` from Windows and got this traceback: $ hg phabimport 11313 ** Unknown exception encountered with possibly-broken third-party extension "mercurial_keyring" (version N/A) ** which supports versions unknown of Mercurial. ** Please disable "mercurial_keyring" and try your action again. ** If that fixes the bug please report it to https://foss.heptapod.net/mercurial/mercurial_keyring/issues ** Python 3.9.5 (default, May 6 2021, 17:29:31) [MSC v.1928 64 bit (AMD64)] ** Mercurial Distributed SCM (version 5.9rc1+hg32.0e2f5733563d) ** Extensions loaded: absorb, blackbox, evolve 10.3.3, extdiff, fastannotate, fix, mercurial_keyring, mq, phabblocker 20210126, phabricator, rebase, show, strip, topic 0.22.3 Traceback (most recent call last): File "mercurial.lock", line 279, in _trylock File "mercurial.vfs", line 202, in makelock File "mercurial.util", line 2147, in makelock FileExistsError: [WinError 183] Cannot create a file when that file already exists: b'hp-omen:78348' -> b'C:\\Users\\Matt\\hg/.hg/store/lock' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<string>", line 24, in <module> File "mercurial.dispatch", line 144, in run File "mercurial.dispatch", line 250, in dispatch File "mercurial.dispatch", line 294, in _rundispatch File "mercurial.dispatch", line 470, in _runcatch File "mercurial.dispatch", line 480, in _callcatch File "mercurial.scmutil", line 153, in callcatch File "mercurial.dispatch", line 460, in _runcatchfunc File "mercurial.dispatch", line 1273, in _dispatch File "mercurial.dispatch", line 918, in runcommand File "mercurial.dispatch", line 1285, in _runcommand File "mercurial.dispatch", line 1271, in <lambda> File "mercurial.util", line 1886, in check File "mercurial.util", line 1886, in check File "hgext.mq", line 4239, in mqcommand File "mercurial.util", line 1886, in check File "mercurial.util", line 1886, in check File "hgext.phabricator", line 314, in inner File "hgext.phabricator", line 2222, in phabimport File "hgext.phabricator", line 2123, in readpatch File "hgext.phabricator", line 2199, in _write File "mercurial.localrepo", line 2956, in lock File "mercurial.localrepo", line 2918, in _lock File "mercurial.lock", line 152, in trylock File "mercurial.lock", line 283, in _trylock File "mercurial.lock", line 314, in _readlock File "mercurial.vfs", line 221, in readlock File "mercurial.util", line 2163, in readlock File "mercurial.windows", line 619, in readlink ValueError: not a symbolic link Both exceptions look accurate (the file exists, and the Windows side can't read WSL side symlinks). I didn't try to reproduce this entirely within the Windows side, but we can do better than a cryptic stacktrace. With this change, the same scenario results in this abort: abort: C:\Users\Matt\hg/.hg/store/lock: The file cannot be accessed by the system When both the `push` and `phabimport` are done on the Windows side, it prints a message about waiting for the lock, and successfully applies the patch after the push completes. I'm not sure if there's enough info to be able to convert the abort into the wait scenario. As it stands now, we don't support symlinks on Windows, which requires either a UAC Administrator level process or an opt-in in developer mode, and there are several places where the new symlink on Windows support in py3 was explicitly disabled in order to get tests to pass quicker. Differential Revision: https://phab.mercurial-scm.org/D11333
Matt Harbison -
r48680:4162f6b4 stable
Show More
Name Size Modified Last Commit Author
/ rust
.cargo
chg
hg-core
hg-cpython
hgcli
rhg
Cargo.lock Loading ...
Cargo.toml Loading ...
README.rst Loading ...

Mercurial Rust Code

This directory contains various Rust code for the Mercurial project. Rust is not required to use (or build) Mercurial, but using it improves performance in some areas.

There are currently three independent rust projects: - chg. An implementation of chg, in rust instead of C. - hgcli. A project that provide a (mostly) self-contained "hg" binary,

for ease of deployment and a bit of speed, using PyOxidizer. See hgcli/README.md.
  • hg-core (and hg-cpython): implementation of some functionality of mercurial in rust, e.g. ancestry computations in revision graphs, status or pull discovery. The top-level Cargo.toml file defines a workspace containing these crates.

Using Rust code

Local use (you need to clean previous build artifacts if you have built without rust previously):

$ make PURE=--rust local # to use ./hg
$ ./tests/run-tests.py --rust # to run all tests
$ ./hg debuginstall | grep -i rust # to validate rust is in use
checking Rust extensions (installed)
checking module policy (rust+c-allow)

If the environment variable HGWITHRUSTEXT=cpython is set, the Rust extension will be used by default unless --no-rust.

One day we may use this environment variable to switch to new experimental binding crates like a hypothetical HGWITHRUSTEXT=hpy.

Special features

You might want to check the features section in hg-cpython/Cargo.toml. It may contain features that might be interesting to try out.

To use features from the Makefile, use the HG_RUST_FEATURES environment variable: for instance HG_RUST_FEATURES="some-feature other-feature"

Profiling

Setting the environment variable RUST_LOG=trace will make hg print a few high level rust-related performance numbers. It can also indicate why the rust code cannot be used (say, using lookarounds in hgignore).

Creating a .cargo/config file with the following content enables debug information in optimized builds. This make profiles more informative with source file name and line number for Rust stack frames and (in some cases) stack frames for Rust functions that have been inlined.

[profile.release] debug = true

py-spy (https://github.com/benfred/py-spy) can be used to construct a single profile with rust functions and python functions (as opposed to hg --profile, which attributes time spent in rust to some unlucky python code running shortly after the rust code, and as opposed to tools for native code like perf, which attribute time to the python interpreter instead of python functions).

Example usage:

$ make PURE=--rust local # Don't forget to recompile after a code change $ py-spy record --native --output /tmp/profile.svg -- ./hg ...

Developing Rust

The current version of Rust in use is 1.41.1, because it's what Debian stable has. You can use rustup override set 1.41.1 at the root of the repo to make it easier on you.

Go to the hg-cpython folder:

$ cd rust/hg-cpython

Or, only the hg-core folder. Be careful not to break compatibility:

$ cd rust/hg-core

Simply run:

$ cargo build --release

It is possible to build without --release, but it is not recommended if performance is of any interest: there can be an order of magnitude of degradation when removing --release.

For faster builds, you may want to skip code generation:

$ cargo check

For even faster typing:

$ cargo c

You can run only the rust-specific tests (as opposed to tests of mercurial as a whole) with:

$ cargo test --all

Formatting the code

We use rustfmt to keep the code formatted at all times. For now, we are using the nightly version because it has been stable enough and provides comment folding.

To format the entire Rust workspace:

$ cargo +nightly fmt

This requires you to have the nightly toolchain installed.