##// END OF EJS Templates
narrow: fix commits of empty files...
narrow: fix commits of empty files The problem is that when committing a new file with empty contents (or in general empty file with filelog p1 = -1), hg commit with narrow doesn't create a filelog revision at all, which causes failures in further commands. The problem seems to be that: - hg thinks that instead of creating a new filelog revision, it can use the filelog's p1 (the nullrev) - because it thinks the file contents is the same in that revision and in p1 - because `narrowfilelog.cmp(nullrev, b'')` is True (unlike with `filelog.cmp`) It's not clear to me which `cmp` behaves better. But I think it makes sense to change the commit code to not to "reuse" the null rev when adding an empty file with filelog p1 == filelog p2 == -1. This is consistent with never writing the null rev in the manifest, which `hg verify` claims is an invariant: ``` inside/c@4: manifest refers to unknown revision 000000000000 ``` Differential Revision: https://phab.mercurial-scm.org/D11400

File last commit:

r48482:78f7f0d4 default
r48770:5b9de38a stable
Show More
list_tracked_files.rs
90 lines | 2.8 KiB | application/rls-services+xml | RustLexer
/ rust / hg-core / src / operations / list_tracked_files.rs
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 // 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.
Simon Sapin
rhg: Remove some intermediate Vecs in `rhg files`...
r48164 use crate::dirstate::parsers::parse_dirstate_entries;
Simon Sapin
dirstate-v2: Introduce a docket file...
r48474 use crate::dirstate_tree::on_disk::{for_each_tracked_path, read_docket};
Simon Sapin
rust: use HgError in RevlogError and Vfs...
r47172 use crate::errors::HgError;
Simon Sapin
rust: introduce Repo and Vfs types for filesystem abstraction...
r46782 use crate::repo::Repo;
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107 use crate::revlog::changelog::Changelog;
use crate::revlog::manifest::{Manifest, ManifestEntry};
Simon Sapin
rhg: centralize parsing of `--rev` CLI arguments...
r47162 use crate::revlog::node::Node;
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107 use crate::revlog::revlog::RevlogError;
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 use crate::utils::hg_path::HgPath;
Simon Sapin
rhg: Add support for dirstate-v2...
r48165 use crate::DirstateError;
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 use rayon::prelude::*;
/// List files under Mercurial control in the working directory
/// by reading the dirstate
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 pub struct Dirstate {
Antoine Cezar
hg-core: simplify `list_tracked_files` operation...
r46106 /// The `dirstate` content.
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 content: Vec<u8>,
Simon Sapin
dirstate-v2: Move fixed-size tree metadata into the docket file...
r48482 v2_metadata: Option<Vec<u8>>,
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 }
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 impl Dirstate {
Simon Sapin
rust: Remove DirstateParseError and ListDirstateTrackedFilesError...
r47169 pub fn new(repo: &Repo) -> Result<Self, HgError> {
Simon Sapin
dirstate-v2: Introduce a docket file...
r48474 let mut content = repo.hg_vfs().read("dirstate")?;
Simon Sapin
dirstate-v2: Move fixed-size tree metadata into the docket file...
r48482 let v2_metadata = if repo.has_dirstate_v2() {
Simon Sapin
dirstate-v2: Introduce a docket file...
r48474 let docket = read_docket(&content)?;
Simon Sapin
dirstate-v2: Move fixed-size tree metadata into the docket file...
r48482 let meta = docket.tree_metadata().to_vec();
Simon Sapin
dirstate-v2: Introduce a docket file...
r48474 content = repo.hg_vfs().read(docket.data_filename())?;
Simon Sapin
dirstate-v2: Move fixed-size tree metadata into the docket file...
r48482 Some(meta)
} else {
None
};
Simon Sapin
rhg: Add support for dirstate-v2...
r48165 Ok(Self {
Simon Sapin
dirstate-v2: Introduce a docket file...
r48474 content,
Simon Sapin
dirstate-v2: Move fixed-size tree metadata into the docket file...
r48482 v2_metadata,
Simon Sapin
rhg: Add support for dirstate-v2...
r48165 })
Antoine Cezar
hg-core: simplify `list_tracked_files` operation...
r46106 }
Simon Sapin
rhg: Add support for dirstate-v2...
r48165 pub fn tracked_files(&self) -> Result<Vec<&HgPath>, DirstateError> {
Simon Sapin
rhg: Remove some intermediate Vecs in `rhg files`...
r48164 let mut files = Vec::new();
Simon Sapin
rhg: Add support for dirstate-v2...
r48165 if !self.content.is_empty() {
Simon Sapin
dirstate-v2: Move fixed-size tree metadata into the docket file...
r48482 if let Some(meta) = &self.v2_metadata {
for_each_tracked_path(&self.content, meta, |path| {
files.push(path)
})?
Simon Sapin
rhg: Add support for dirstate-v2...
r48165 } else {
let _parents = parse_dirstate_entries(
&self.content,
|path, entry, _copy_source| {
if entry.state.is_tracked() {
files.push(path)
}
Ok(())
},
)?;
}
}
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 files.par_sort_unstable();
Ok(files)
}
}
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107
/// List files under Mercurial control at a given revision.
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 pub fn list_rev_tracked_files(
Simon Sapin
rust: introduce Repo and Vfs types for filesystem abstraction...
r46782 repo: &Repo,
Simon Sapin
rhg: centralize parsing of `--rev` CLI arguments...
r47162 revset: &str,
Simon Sapin
rust: remove three enums that were identical to `RevlogError`...
r47166 ) -> Result<FilesForRev, RevlogError> {
Simon Sapin
rhg: centralize parsing of `--rev` CLI arguments...
r47162 let rev = crate::revset::resolve_single(revset, repo)?;
Simon Sapin
rust: introduce Repo and Vfs types for filesystem abstraction...
r46782 let changelog = Changelog::open(repo)?;
let manifest = Manifest::open(repo)?;
Simon Sapin
rhg: centralize parsing of `--rev` CLI arguments...
r47162 let changelog_entry = changelog.get_rev(rev)?;
Simon Sapin
rust: use HgError in RevlogError and Vfs...
r47172 let manifest_node =
Node::from_hex_for_repo(&changelog_entry.manifest_node()?)?;
Simon Sapin
rust: Make NodePrefix allocation-free and Copy, remove NodePrefixRef...
r47160 let manifest_entry = manifest.get_node(manifest_node.into())?;
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 Ok(FilesForRev(manifest_entry))
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107 }
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 pub struct FilesForRev(ManifestEntry);
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 impl FilesForRev {
pub fn iter(&self) -> impl Iterator<Item = &HgPath> {
self.0.files()
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107 }
}