[Updated] D11615: rhg: faster hg cat when many files are requested
aalekseyev (Arseniy Alekseyev)
phabricator at mercurial-scm.org
Mon Oct 11 10:51:11 UTC 2021
aalekseyev updated this revision to Diff 30699.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D11615?vs=30677&id=30699
BRANCH
default
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D11615/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D11615
AFFECTED FILES
rust/hg-core/src/operations/cat.rs
rust/rhg/src/commands/cat.rs
CHANGE DETAILS
diff --git a/rust/rhg/src/commands/cat.rs b/rust/rhg/src/commands/cat.rs
--- a/rust/rhg/src/commands/cat.rs
+++ b/rust/rhg/src/commands/cat.rs
@@ -73,7 +73,7 @@
None => format!("{:x}", repo.dirstate_parents()?.p1),
};
- let output = cat(&repo, &rev, &files).map_err(|e| (e, rev.as_str()))?;
+ let output = cat(&repo, &rev, files).map_err(|e| (e, rev.as_str()))?;
invocation.ui.write_stdout(&output.concatenated)?;
if !output.missing.is_empty() {
let short = format!("{:x}", output.node.short()).into_bytes();
diff --git a/rust/hg-core/src/operations/cat.rs b/rust/hg-core/src/operations/cat.rs
--- a/rust/hg-core/src/operations/cat.rs
+++ b/rust/hg-core/src/operations/cat.rs
@@ -11,6 +11,9 @@
use crate::utils::hg_path::HgPathBuf;
+use itertools::EitherOrBoth::{Both, Left, Right};
+use itertools::Itertools;
+
pub struct CatOutput {
/// Whether any file in the manifest matched the paths given as CLI
/// arguments
@@ -31,7 +34,7 @@
pub fn cat<'a>(
repo: &Repo,
revset: &str,
- files: &'a [HgPathBuf],
+ mut files: Vec<HgPathBuf>,
) -> Result<CatOutput, RevlogError> {
let rev = crate::revset::resolve_single(revset, repo)?;
let manifest = repo.manifest_for_rev(rev)?;
@@ -40,13 +43,21 @@
.node_from_rev(rev)
.expect("should succeed when repo.manifest did");
let mut bytes = vec![];
- let mut matched = vec![false; files.len()];
let mut found_any = false;
+ files.sort_unstable();
+
+ let mut missing = vec![];
- for (manifest_file, node_bytes) in manifest.files_with_nodes() {
- for (cat_file, is_matched) in files.iter().zip(&mut matched) {
- if cat_file.as_bytes() == manifest_file.as_bytes() {
- *is_matched = true;
+ for entry in manifest
+ .files_with_nodes()
+ .merge_join_by(files.iter(), |(manifest_file, _), file| {
+ manifest_file.cmp(&file.as_ref())
+ })
+ {
+ match entry {
+ Left(_) => (),
+ Right(path) => missing.push(path),
+ Both((manifest_file, node_bytes), _) => {
found_any = true;
let file_log = repo.filelog(manifest_file)?;
let file_node = Node::from_hex_for_repo(node_bytes)?;
@@ -56,11 +67,9 @@
}
}
- let missing: Vec<_> = files
+ let missing: Vec<HgPathBuf> = missing
.iter()
- .zip(&matched)
- .filter(|pair| !*pair.1)
- .map(|pair| pair.0.clone())
+ .map(|file| (*(file.as_ref())).to_owned())
.collect();
Ok(CatOutput {
found_any,
To: aalekseyev, #hg-reviewers, martinvonz
Cc: martinvonz, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20211011/c40d0c2e/attachment-0002.html>
More information about the Mercurial-patches
mailing list