Skip to content

Commit

Permalink
Use CommitIteratorExt to replace .map(|c| c.id().clone())
Browse files Browse the repository at this point in the history
This replaces `.map(|c| c.id().clone())` with `.ids().cloned()` to use nicer
syntax for getting `CommitId`s from an iterator of commits using the
`CommitIteratorExt` trait.

In one case we can actually call `.parent_ids()` directly. I also pluralized a
variable to make it clearer that it's a vec of IDs and not a single ID.
  • Loading branch information
emesterhazy committed Apr 19, 2024
1 parent 18f94bb commit 44a18d4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
6 changes: 3 additions & 3 deletions cli/src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Please use `jj new 'all:x|y'` instead of `jj new --allow-large-revsets x y`.",
.resolve_some_revsets_default_single(&args.revisions)?
.into_iter()
.collect_vec();
let target_ids = target_commits.iter().map(|c| c.id().clone()).collect_vec();
let target_ids = target_commits.iter().ids().cloned().collect_vec();
let mut tx = workspace_command.start_transaction();
let mut num_rebased;
let new_commit;
Expand Down Expand Up @@ -128,10 +128,10 @@ Please use `jj new 'all:x|y'` instead of `jj new --allow-large-revsets x y`.",
.commits(tx.repo().store())
.try_collect()?;
let merged_tree = merge_commit_trees(tx.repo(), &new_parents_commits)?;
let new_parents_commit_id = new_parents_commits.iter().map(|c| c.id().clone()).collect();
let new_parents_commit_ids = new_parents_commits.iter().ids().cloned().collect();
new_commit = tx
.mut_repo()
.new_commit(command.settings(), new_parents_commit_id, merged_tree.id())
.new_commit(command.settings(), new_parents_commit_ids, merged_tree.id())
.set_description(join_message_paragraphs(&args.message_paragraphs))
.write()?;
num_rebased = target_ids.len();
Expand Down
6 changes: 1 addition & 5 deletions cli/src/commands/rebase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,7 @@ fn rebase_revision(
.iter()
.flat_map(|c| {
if c == &old_commit {
old_commit
.parents()
.iter()
.map(|c| c.id().clone())
.collect()
old_commit.parent_ids().to_vec()
} else {
[c.id().clone()].to_vec()
}
Expand Down
3 changes: 2 additions & 1 deletion cli/src/commands/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::sync::Arc;

use clap::Subcommand;
use itertools::Itertools;
use jj_lib::commit::CommitIteratorExt;
use jj_lib::file_util;
use jj_lib::object_id::ObjectId;
use jj_lib::op_store::{OpStoreError, WorkspaceId};
Expand Down Expand Up @@ -209,7 +210,7 @@ fn cmd_workspace_add(
};

let tree = merge_commit_trees(tx.repo(), &parents)?;
let parent_ids = parents.iter().map(|c| c.id().clone()).collect_vec();
let parent_ids = parents.iter().ids().cloned().collect_vec();
let new_wc_commit = tx
.mut_repo()
.new_commit(command.settings(), parent_ids, tree.id())
Expand Down

0 comments on commit 44a18d4

Please sign in to comment.