From 2d7b6331d72cb5b3bb2d43021f30f00fc7b0aa43 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sun, 5 May 2024 10:03:30 -0700 Subject: [PATCH] cleanup: propagate errors from `Commit::predecessors()` --- cli/src/commands/obslog.rs | 6 +++--- lib/src/commit.rs | 4 ++-- lib/tests/test_commit_builder.rs | 4 ++-- lib/tests/test_init.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cli/src/commands/obslog.rs b/cli/src/commands/obslog.rs index 39f65b6aa8..7f165fd1a3 100644 --- a/cli/src/commands/obslog.rs +++ b/cli/src/commands/obslog.rs @@ -105,7 +105,7 @@ pub(crate) fn cmd_obslog( let mut commits = topo_order_reverse( vec![start_commit], |commit: &Commit| commit.id().clone(), - |commit: &Commit| commit.predecessors(), + |commit: &Commit| commit.predecessors().unwrap(), ); if let Some(n) = args.limit { commits.truncate(n); @@ -114,7 +114,7 @@ pub(crate) fn cmd_obslog( let mut graph = get_graphlog(command.settings(), formatter.raw()); for commit in commits { let mut edges = vec![]; - for predecessor in &commit.predecessors() { + for predecessor in commit.predecessors()? { edges.push(Edge::Direct(predecessor.id().clone())); } let mut buffer = vec![]; @@ -164,7 +164,7 @@ fn show_predecessor_patch( commit: &Commit, diff_formats: &[DiffFormat], ) -> Result<(), CommandError> { - let predecessors = commit.predecessors(); + let predecessors = commit.predecessors()?; let predecessor = match predecessors.first() { Some(predecessor) => predecessor, None => return Ok(()), diff --git a/lib/src/commit.rs b/lib/src/commit.rs index 64d9ae323a..48d1892d6e 100644 --- a/lib/src/commit.rs +++ b/lib/src/commit.rs @@ -92,11 +92,11 @@ impl Commit { &self.data.predecessors } - pub fn predecessors(&self) -> Vec { + pub fn predecessors(&self) -> BackendResult> { self.data .predecessors .iter() - .map(|id| self.store.get_commit(id).unwrap()) + .map(|id| self.store.get_commit(id)) .collect() } diff --git a/lib/tests/test_commit_builder.rs b/lib/tests/test_commit_builder.rs index 14d78eeaa3..c6c07eb429 100644 --- a/lib/tests/test_commit_builder.rs +++ b/lib/tests/test_commit_builder.rs @@ -78,7 +78,7 @@ fn test_initial(backend: TestRepoBackend) { tx.commit("test"); assert_eq!(commit.parents().unwrap(), vec![store.root_commit()]); - assert_eq!(commit.predecessors(), vec![]); + assert_eq!(commit.predecessors().unwrap(), vec![]); assert_eq!(commit.description(), "description"); assert_eq!(commit.author(), &author_signature); assert_eq!(commit.committer(), &committer_signature); @@ -157,7 +157,7 @@ fn test_rewrite(backend: TestRepoBackend) { vec![store.root_commit()] ); assert_eq!( - rewritten_commit.predecessors(), + rewritten_commit.predecessors().unwrap(), vec![initial_commit.clone()] ); assert_eq!(rewritten_commit.author().name, settings.user_name()); diff --git a/lib/tests/test_init.rs b/lib/tests/test_init.rs index b95bcb4f89..84812093f2 100644 --- a/lib/tests/test_init.rs +++ b/lib/tests/test_init.rs @@ -173,7 +173,7 @@ fn test_init_checkout(backend: TestRepoBackend) { wc_commit.store_commit().parents, vec![repo.store().root_commit_id().clone()] ); - assert_eq!(wc_commit.predecessors(), vec![]); + assert_eq!(wc_commit.predecessors().unwrap(), vec![]); assert_eq!(wc_commit.description(), ""); assert_eq!(wc_commit.author().name, settings.user_name()); assert_eq!(wc_commit.author().email, settings.user_email());