##// END OF EJS Templates
phases: large rewrite on retract boundary...
phases: large rewrite on retract boundary The new code is still pure Python, so we still have room to going significantly faster. However its complexity of the complex part is `O(|[min_new_draft, tip]|)` instead of `O(|[min_draft, tip]|` which should help tremendously one repository with old draft (like mercurial-devel or mozilla-try). This is especially useful as the most common "retract boundary" operation happens when we commit/rewrite new drafts or when we push new draft to a non-publishing server. In this case, the smallest new_revs is very close to the tip and there is very few work to do. A few smaller optimisation could be done for these cases and will be introduced in later changesets. We still have iterate over large sets of roots, but this is already a great improvement for a very small amount of work. We gather information on the affected changeset as we go as we can put it to use in the next changesets. This extra data collection might slowdown the `register_new` case a bit, however for register_new, it should not really matters. The set of new nodes is either small, so the impact is negligible, or the set of new nodes is large, and the amount of work to do to had them will dominate the overhead the collecting information in `changed_revs`. As this new code compute the changes on the fly, it unlock other interesting improvement to be done in later changeset.

File last commit:

r49875:b999edb1 default
r52302:2f39c7ae default
Show More
test-merge-lists.rs
204 lines | 3.2 KiB | application/rls-services+xml | RustLexer
use similar::DiffableStr;
use std::ffi::OsStr;
use tempdir::TempDir;
fn run_test(arg: &str, input: &str) -> String {
let mut cmd = assert_cmd::Command::cargo_bin("merge-lists").unwrap();
let temp_dir = TempDir::new("test").unwrap();
let base_path = temp_dir.path().join("base");
let local_path = temp_dir.path().join("local");
let other_path = temp_dir.path().join("other");
let rest = input.strip_prefix("\nbase:\n").unwrap();
let mut split = rest.split("\nlocal:\n");
std::fs::write(&base_path, split.next().unwrap()).unwrap();
let rest = split.next().unwrap();
let mut split = rest.split("\nother:\n");
std::fs::write(&local_path, split.next().unwrap()).unwrap();
std::fs::write(&other_path, split.next().unwrap()).unwrap();
cmd.args(&[
OsStr::new(arg),
local_path.as_os_str(),
base_path.as_os_str(),
other_path.as_os_str(),
])
.assert()
.success();
let new_base_bytes = std::fs::read(&base_path).unwrap();
let new_local_bytes = std::fs::read(&local_path).unwrap();
let new_other_bytes = std::fs::read(&other_path).unwrap();
// No newline before "base:" because of https://github.com/mitsuhiko/insta/issues/117
format!(
"base:\n{}\nlocal:\n{}\nother:\n{}",
new_base_bytes.as_str().unwrap(),
new_local_bytes.as_str().unwrap(),
new_other_bytes.as_str().unwrap()
)
}
#[test]
fn test_merge_lists_basic() {
let output = run_test(
"--python-imports",
r"
base:
import lib1
import lib2
local:
import lib2
import lib3
other:
import lib3
import lib4
",
);
insta::assert_snapshot!(output, @r###"
base:
import lib3
import lib4
local:
import lib3
import lib4
other:
import lib3
import lib4
"###);
}
#[test]
fn test_merge_lists_from() {
// Test some "from x import y" statements and some non-import conflicts
// (unresolvable)
let output = run_test(
"--python-imports",
r"
base:
from . import x
1+1
local:
from . import x
from a import b
2+2
other:
from a import c
3+3
",
);
insta::assert_snapshot!(output, @r###"
base:
from a import b
from a import c
1+1
local:
from a import b
from a import c
2+2
other:
from a import b
from a import c
3+3
"###);
}
#[test]
fn test_merge_lists_not_sorted() {
// Test that nothing is done if the elements in the conflicting hunks are
// not sorted
let output = run_test(
"--python-imports",
r"
base:
import x
1+1
local:
import a
import x
2+2
other:
import z
import y
3+3
",
);
insta::assert_snapshot!(output, @r###"
base:
import x
1+1
local:
import a
import x
2+2
other:
import z
import y
3+3
"###);
}
#[test]
fn test_custom_regex() {
// Test merging of all lines (by matching anything)
let output = run_test(
"--pattern=.*",
r"
base:
aardvark
baboon
camel
local:
aardvark
camel
eagle
other:
aardvark
camel
deer
",
);
insta::assert_snapshot!(output, @r###"
base:
aardvark
camel
deer
eagle
local:
aardvark
camel
deer
eagle
other:
aardvark
camel
deer
eagle
"###);
}