Mercurial > hg
view tests/test-merge-exec.t @ 46667:93e9f448273c
rhg: Add support for automatic fallback to Python
`rhg` is a command-line application that can do a small subset of what
`hg` can. It is written entirely in Rust, which avoids the cost of starting
a Python interpreter and importing many Python modules.
In a script that runs many `hg` commands, this cost can add up.
However making users decide when to use `rhg` instead of `hg` is
not practical as we want the subset of supported functionality
to grow over time.
Instead we introduce "fallback" behavior where, when `rhg` encounters
something (a sub-command, a repository format, …) that is not implemented
in Rust-only, it does nothing but silently start a subprocess of
Python-based `hg` running the same command.
That way `rhg` becomes a drop-in replacement for `hg` that sometimes
goes faster. Whether Python is used should be an implementation detail
not apparent to users (other than through speed).
A new `fallback` value is added to the previously introduced
`rhg.on-unsupported` configuration key. When in this mode, the new
`rhg.fallback-executable` config is determine what command to use
to run a Python-based `hg`.
The previous `rhg.on-unsupported = abort-silent` configuration was designed
to let a wrapper script call `rhg` and then fall back to `hg` based on the
exit code. This is still available, but having fallback behavior built-in
in rhg might be easier for users instead of leaving that script "as an
exercise for the reader".
Using a subprocess like this is not idea, especially when `rhg` is to be
installed in `$PATH` as `hg`, since the other `hg.py` executable needs
to still be available… somewhere. Eventually this could be replaced
by using PyOxidizer to a have a single executable that embeds a Python
interpreter, but only starts it when needed.
Differential Revision: https://phab.mercurial-scm.org/D10093
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Mon, 01 Mar 2021 20:36:06 +0100 |
parents | 6d968cd40961 |
children | b7fde9237c92 |
line wrap: on
line source
=============================================== Testing merge involving change to the exec flag =============================================== #require execbit Initial setup ============== $ hg init base-repo $ cd base-repo $ cat << EOF > a > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > EOF $ touch b $ hg add a b $ hg commit -m "initial commit" $ cd .. $ hg init base-exec $ cd base-exec $ cat << EOF > a > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > EOF $ chmod +x a $ touch b $ hg add a b $ hg commit -m "initial commit" $ cd .. Testing merging mode change =========================== Adding the flag --------------- setup Change on one side, executable bit on the other $ hg clone base-repo simple-merge-repo updating to branch default 2 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd simple-merge-repo $ chmod +x a $ hg ci -m "make a executable, no change" $ [ -x a ] || echo "executable bit not recorded" $ hg up ".^" 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cat << EOF > a > 1 > 2 > 3 > 4 > 5 > 6 > 7 > x > 9 > EOF $ hg commit -m "edit end of file" created new head merge them (from the update side) $ hg merge 'desc("make a executable, no change")' 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg st M a $ [ -x a ] || echo "executable bit lost" merge them (from the chmod side) $ hg up -C 'desc("make a executable, no change")' 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg merge 'desc("edit end of file")' 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg st M a $ [ -x a ] || echo "executable bit lost" $ cd .. Removing the flag ----------------- Change on one side, executable bit on the other $ hg clone base-exec simple-merge-repo-removal updating to branch default 2 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd simple-merge-repo-removal $ chmod -x a $ hg ci -m "make a non-executable, no change" $ [ -x a ] && echo "executable bit not removed" [1] $ hg up ".^" 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cat << EOF > a > 1 > 2 > 3 > 4 > 5 > 6 > 7 > x > 9 > EOF $ hg commit -m "edit end of file" created new head merge them (from the update side) $ hg merge 'desc("make a non-executable, no change")' 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg st M a $ [ -x a ] && echo "executable bit not removed" [1] merge them (from the chmod side) $ hg up -C 'desc("make a non-executable, no change")' 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg merge 'desc("edit end of file")' 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg st M a $ [ -x a ] && echo "executable bit not removed" [1] $ cd .. Testing merging mode change with rename ======================================= Adding the flag --------------- $ hg clone base-repo rename-merge-repo updating to branch default 2 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd rename-merge-repo make "a" executable on one side $ chmod +x a $ hg status M a $ hg ci -m "make a executable" $ [ -x a ] || echo "executable bit not recorded" $ hg up ".^" 1 files updated, 0 files merged, 0 files removed, 0 files unresolved make "a" renamed on the other side $ hg mv a z $ hg st --copies A z a R a $ hg ci -m "rename a to z" created new head merge them (from the rename side) $ hg merge 'desc("make a executable")' 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg st --copies M z a $ [ -x z ] || echo "executable bit lost" merge them (from the chmod side) $ hg up -C 'desc("make a executable")' 1 files updated, 0 files merged, 1 files removed, 0 files unresolved $ hg merge 'desc("rename a to z")' 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg st --copies M z a R a $ [ -x z ] || echo "executable bit lost" $ cd .. Removing the flag ----------------- $ hg clone base-exec rename-merge-repo-removal updating to branch default 2 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd rename-merge-repo-removal make "a" non-executable on one side $ chmod -x a $ hg status M a $ hg ci -m "make a non-executable" $ [ -x a ] && echo "executable bit not removed" [1] $ hg up ".^" 1 files updated, 0 files merged, 0 files removed, 0 files unresolved make "a" renamed on the other side $ hg mv a z $ hg st --copies A z a R a $ hg ci -m "rename a to z" created new head merge them (from the rename side) $ hg merge 'desc("make a non-executable")' 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg st --copies M z a $ [ -x z ] && echo "executable bit not removed" [1] merge them (from the chmod side) $ hg up -C 'desc("make a non-executable")' 1 files updated, 0 files merged, 1 files removed, 0 files unresolved $ hg merge 'desc("rename a to z")' 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg st --copies M z a R a $ [ -x z ] && echo "executable bit not removed" [1] $ cd .. Testing merging mode change with rename + modification on both side =================================================================== Adding the flag --------------- $ hg clone base-repo rename+mod-merge-repo updating to branch default 2 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd rename+mod-merge-repo make "a" executable on one side $ chmod +x a $ cat << EOF > a > 1 > x > 3 > 4 > 5 > 6 > 7 > 8 > 9 > EOF $ hg status M a $ hg ci -m "make a executable, and change start" $ [ -x a ] || echo "executable bit not recorded" $ hg up ".^" 1 files updated, 0 files merged, 0 files removed, 0 files unresolved make "a" renamed on the other side $ hg mv a z $ hg st --copies A z a R a $ cat << EOF > z > 1 > 2 > 3 > 4 > 5 > 6 > 7 > x > 9 > EOF $ hg ci -m "rename a to z, and change end" created new head merge them (from the rename side) $ hg merge 'desc("make a executable")' merging z and a to z 0 files updated, 1 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg st --copies M z a $ [ -x z ] || echo "executable bit lost" merge them (from the chmod side) $ hg up -C 'desc("make a executable")' 1 files updated, 0 files merged, 1 files removed, 0 files unresolved $ hg merge 'desc("rename a to z")' merging a and z to z 0 files updated, 1 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg st --copies M z a R a $ [ -x z ] || echo "executable bit lost" $ cd .. Removing the flag ----------------- $ hg clone base-exec rename+mod-merge-repo-removal updating to branch default 2 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd rename+mod-merge-repo-removal make "a" non-executable on one side $ chmod -x a $ cat << EOF > a > 1 > x > 3 > 4 > 5 > 6 > 7 > 8 > 9 > EOF $ hg status M a $ hg ci -m "make a non-executable, and change start" $ [ -x z ] && echo "executable bit not removed" [1] $ hg up ".^" 1 files updated, 0 files merged, 0 files removed, 0 files unresolved make "a" renamed on the other side $ hg mv a z $ hg st --copies A z a R a $ cat << EOF > z > 1 > 2 > 3 > 4 > 5 > 6 > 7 > x > 9 > EOF $ hg ci -m "rename a to z, and change end" created new head merge them (from the rename side) $ hg merge 'desc("make a non-executable")' merging z and a to z 0 files updated, 1 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg st --copies M z a $ [ -x z ] && echo "executable bit not removed" [1] merge them (from the chmod side) $ hg up -C 'desc("make a non-executable")' 1 files updated, 0 files merged, 1 files removed, 0 files unresolved $ hg merge 'desc("rename a to z")' merging a and z to z 0 files updated, 1 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg st --copies M z a R a $ [ -x z ] && echo "executable bit not removed" [1] $ cd ..