Patchwork D12426: rhg: don't skip empty lines when iterating over changeset lines

login
register
mail settings
Submitter phabricator
Date April 1, 2022, 6:09 a.m.
Message ID <differential-rev-PHID-DREV-2veen4zrmq4sls6ite2d-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50772/
State New
Headers show

Comments

phabricator - April 1, 2022, 6:09 a.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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

CHANGE DETAILS




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

Patch

diff --git a/rust/hg-core/src/revlog/changelog.rs b/rust/hg-core/src/revlog/changelog.rs
--- a/rust/hg-core/src/revlog/changelog.rs
+++ b/rust/hg-core/src/revlog/changelog.rs
@@ -51,17 +51,17 @@ 
 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().unwrap();
+        if manifest_node_hex.is_empty() {
+            Ok(NULL_NODE)
+        } else {
+            Node::from_hex_for_repo(manifest_node_hex)
         }
     }
 }