rust-changelog: don't skip empty lines when iterating over changeset lines
authorMartin von Zweigbergk <martinvonz@google.com>
Thu, 31 Mar 2022 22:06:26 -0700
changeset 49062 fb82b5cb8301
parent 49061 81d293eb5264
child 49063 cc132255261b
rust-changelog: don't skip empty lines when iterating over changeset lines The first empty line in the changeset indicates the end of headers and beginning of description. Callers can't know figure out where that position is if empty lines are skipped. Differential Revision: https://phab.mercurial-scm.org/D12426
rust/hg-core/src/revlog/changelog.rs
--- a/rust/hg-core/src/revlog/changelog.rs	Thu Mar 31 22:02:46 2022 -0700
+++ b/rust/hg-core/src/revlog/changelog.rs	Thu Mar 31 22:06:26 2022 -0700
@@ -51,17 +51,18 @@
 impl ChangelogRevisionData {
     /// Return an iterator over the lines of the entry.
     pub fn lines(&self) -> impl Iterator<Item = &[u8]> {
-        self.bytes
-            .split(|b| b == &b'\n')
-            .filter(|line| !line.is_empty())
+        self.bytes.split(|b| b == &b'\n')
     }
 
     /// Return the node id of the `manifest` referenced by this `changelog`
     /// entry.
     pub fn manifest_node(&self) -> Result<Node, HgError> {
-        match self.lines().next() {
-            None => Ok(NULL_NODE),
-            Some(x) => Node::from_hex_for_repo(x),
+        let manifest_node_hex =
+            self.lines().next().expect("Empty iterator from split()?");
+        if manifest_node_hex.is_empty() {
+            Ok(NULL_NODE)
+        } else {
+            Node::from_hex_for_repo(manifest_node_hex)
         }
     }
 }