rust-changelog: don't panic on empty file lists stable
authorArun Kulshreshtha <akulshreshtha@janestreet.com>
Tue, 30 Jan 2024 22:14:02 +0000
branchstable
changeset 51363 d626e5e7bbbe
parent 51362 e7be2ddfb4c2
child 51364 c6560ee526d2
rust-changelog: don't panic on empty file lists
rust/hg-core/src/revlog/changelog.rs
--- a/rust/hg-core/src/revlog/changelog.rs	Wed Jan 24 13:49:29 2024 -0300
+++ b/rust/hg-core/src/revlog/changelog.rs	Tue Jan 30 22:14:02 2024 +0000
@@ -5,10 +5,11 @@
 use crate::utils::hg_path::HgPath;
 use crate::vfs::Vfs;
 use crate::{Graph, GraphError, UncheckedRevision};
-use itertools::Itertools;
+use itertools::{Either, Itertools};
 use std::ascii::escape_default;
 use std::borrow::Cow;
 use std::fmt::{Debug, Formatter};
+use std::iter;
 
 /// A specialized `Revlog` to work with changelog data format.
 pub struct Changelog {
@@ -228,9 +229,15 @@
 
     /// The files changed in this revision.
     pub fn files(&self) -> impl Iterator<Item = &HgPath> {
-        self.bytes[self.timestamp_end + 1..self.files_end]
-            .split(|b| b == &b'\n')
-            .map(HgPath::new)
+        if self.timestamp_end == self.files_end {
+            Either::Left(iter::empty())
+        } else {
+            Either::Right(
+                self.bytes[self.timestamp_end + 1..self.files_end]
+                    .split(|b| b == &b'\n')
+                    .map(HgPath::new),
+            )
+        }
     }
 
     /// The change description.
@@ -356,4 +363,12 @@
         );
         Ok(())
     }
+
+    #[test]
+    fn test_empty_files_list() {
+        assert!(ChangelogRevisionData::null()
+            .files()
+            .collect_vec()
+            .is_empty());
+    }
 }