# HG changeset patch # User Antoine Cezar # Date 2020-09-15 14:46:57 # Node ID f2de24c2b1f6c17f80cac4fe0476f2982a9b94c2 # Parent aebc976fd7d5837a4faba39efc3b9b04a4f9f78d hg-core: add `files_with_nodes` to `Manifest` Differential Revision: https://phab.mercurial-scm.org/D9050 diff --git a/rust/hg-core/src/revlog/manifest.rs b/rust/hg-core/src/revlog/manifest.rs --- a/rust/hg-core/src/revlog/manifest.rs +++ b/rust/hg-core/src/revlog/manifest.rs @@ -57,4 +57,17 @@ impl ManifestEntry { HgPath::new(&line[..pos]) }) } + + /// Return an iterator over the files of the entry. + pub fn files_with_nodes(&self) -> impl Iterator { + self.lines().filter(|line| !line.is_empty()).map(|line| { + let pos = line + .iter() + .position(|x| x == &b'\0') + .expect("manifest line should contain \\0"); + let hash_start = pos + 1; + let hash_end = hash_start + 40; + (HgPath::new(&line[..pos]), &line[hash_start..hash_end]) + }) + } }