changeset 49062:fb82b5cb8301

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
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 31 Mar 2022 22:06:26 -0700
parents 81d293eb5264
children cc132255261b
files rust/hg-core/src/revlog/changelog.rs
diffstat 1 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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)
         }
     }
 }