##// END OF EJS Templates
rust: Align DirstateEntry internals with Python/C DirstateItem...
rust: Align DirstateEntry internals with Python/C DirstateItem This propagate to this Rust struct the similar change that was made recently to the Python classe and C struct. Namely, instead of storing a four-valued `state` field we now store seven (bit-packed) booleans that give lower-level information. Additionally, the marker values -1 and -2 for mtime and size should not be used internally anymore. They are replaced by some combinations of booleans For now, all uses of of `DirstateEntry` still use the compatibility APIs with `state` and marker values. Later the Rust API for DirstateMap will be increasingly updated to the new style. Also change the expected result of the test_non_normal_other_parent_entries unit test. Only a `DirstateEntry` with `size == -2 && mtime != -1` is affected, but this case never occurs outside of unit tests. `size == -2` was the marker value for "from other parent" entries, where no meaningful mtime is stored. Differential Revision: https://phab.mercurial-scm.org/D11484

File last commit:

r48783:87e3f878 default
r48856:008959fc default
Show More
cat.rs
71 lines | 2.1 KiB | application/rls-services+xml | RustLexer
// list_tracked_files.rs
//
// Copyright 2020 Antoine Cezar <antoine.cezar@octobus.net>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
use crate::repo::Repo;
use crate::revlog::revlog::RevlogError;
use crate::revlog::Node;
use crate::utils::hg_path::HgPathBuf;
pub struct CatOutput {
/// Whether any file in the manifest matched the paths given as CLI
/// arguments
pub found_any: bool,
/// The contents of matching files, in manifest order
pub concatenated: Vec<u8>,
/// Which of the CLI arguments did not match any manifest file
pub missing: Vec<HgPathBuf>,
/// The node ID that the given revset was resolved to
pub node: Node,
}
/// Output the given revision of files
///
/// * `root`: Repository root
/// * `rev`: The revision to cat the files from.
/// * `files`: The files to output.
pub fn cat<'a>(
repo: &Repo,
revset: &str,
files: &'a [HgPathBuf],
) -> Result<CatOutput, RevlogError> {
let rev = crate::revset::resolve_single(revset, repo)?;
let manifest = repo.manifest_for_rev(rev)?;
let node = *repo
.changelog()?
.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;
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;
found_any = true;
let file_log = repo.filelog(manifest_file)?;
let file_node = Node::from_hex_for_repo(node_bytes)?;
let entry = file_log.data_for_node(file_node)?;
bytes.extend(entry.data()?)
}
}
}
let missing: Vec<_> = files
.iter()
.zip(&matched)
.filter(|pair| !*pair.1)
.map(|pair| pair.0.clone())
.collect();
Ok(CatOutput {
found_any,
concatenated: bytes,
missing,
node,
})
}