Patchwork D9050: hg-core: add `files_with_nodes` to `Manifest`

login
register
mail settings
Submitter phabricator
Date Sept. 18, 2020, 4:01 p.m.
Message ID <differential-rev-PHID-DREV-6kna4jrgrpafrpccwrcj-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47224/
State Superseded
Headers show

Comments

phabricator - Sept. 18, 2020, 4:01 p.m.
acezar created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9050

AFFECTED FILES
  rust/hg-core/src/revlog/manifest.rs

CHANGE DETAILS




To: acezar, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

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 @@ 
             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])
+        })
+    }
 }