Mercurial > hg-stable
changeset 45546:f2de24c2b1f6
hg-core: add `files_with_nodes` to `Manifest`
Differential Revision: https://phab.mercurial-scm.org/D9050
author | Antoine Cezar <antoine.cezar@octobus.net> |
---|---|
date | Tue, 15 Sep 2020 16:46:57 +0200 |
parents | aebc976fd7d5 |
children | 522ec3dc44b9 |
files | rust/hg-core/src/revlog/manifest.rs |
diffstat | 1 files changed, 13 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/manifest.rs Tue Sep 15 16:45:27 2020 +0200 +++ b/rust/hg-core/src/revlog/manifest.rs Tue Sep 15 16:46:57 2020 +0200 @@ -57,4 +57,17 @@ HgPath::new(&line[..pos]) }) } + + /// Return an iterator over the files of the entry. + pub fn files_with_nodes(&self) -> impl Iterator<Item = (&HgPath, &[u8])> { + 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]) + }) + } }