Skip to content

Commit

Permalink
cleanup: propagate errors from Commit::predecessors()
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvonz committed May 5, 2024
1 parent 3af4fae commit 2d7b633
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions cli/src/commands/obslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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![];
Expand Down Expand Up @@ -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(()),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ impl Commit {
&self.data.predecessors
}

pub fn predecessors(&self) -> Vec<Commit> {
pub fn predecessors(&self) -> BackendResult<Vec<Commit>> {
self.data
.predecessors
.iter()
.map(|id| self.store.get_commit(id).unwrap())
.map(|id| self.store.get_commit(id))
.collect()
}

Expand Down
4 changes: 2 additions & 2 deletions lib/tests/test_commit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/test_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 2d7b633

Please sign in to comment.