ok/jj
1
0
Fork 0
forked from mirrors/jj

Use CommitIteratorExt to replace .map(|c| c.id().clone())

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.
This commit is contained in:
Evan Mesterhazy 2024-04-19 00:03:19 -04:00 committed by Evan Mesterhazy
parent 449fc423b8
commit 3d267de53e
3 changed files with 6 additions and 9 deletions

View file

@ -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)? .resolve_some_revsets_default_single(&args.revisions)?
.into_iter() .into_iter()
.collect_vec(); .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 tx = workspace_command.start_transaction();
let mut num_rebased; let mut num_rebased;
let new_commit; let new_commit;
@ -128,10 +128,10 @@ Please use `jj new 'all:x|y'` instead of `jj new --allow-large-revsets x y`.",
.commits(tx.repo().store()) .commits(tx.repo().store())
.try_collect()?; .try_collect()?;
let merged_tree = merge_commit_trees(tx.repo(), &new_parents_commits)?; 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 new_commit = tx
.mut_repo() .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)) .set_description(join_message_paragraphs(&args.message_paragraphs))
.write()?; .write()?;
num_rebased = target_ids.len(); num_rebased = target_ids.len();

View file

@ -387,11 +387,7 @@ fn rebase_revision(
.iter() .iter()
.flat_map(|c| { .flat_map(|c| {
if c == &old_commit { if c == &old_commit {
old_commit old_commit.parent_ids().to_vec()
.parents()
.iter()
.map(|c| c.id().clone())
.collect()
} else { } else {
[c.id().clone()].to_vec() [c.id().clone()].to_vec()
} }

View file

@ -19,6 +19,7 @@ use std::sync::Arc;
use clap::Subcommand; use clap::Subcommand;
use itertools::Itertools; use itertools::Itertools;
use jj_lib::commit::CommitIteratorExt;
use jj_lib::file_util; use jj_lib::file_util;
use jj_lib::object_id::ObjectId; use jj_lib::object_id::ObjectId;
use jj_lib::op_store::{OpStoreError, WorkspaceId}; use jj_lib::op_store::{OpStoreError, WorkspaceId};
@ -209,7 +210,7 @@ fn cmd_workspace_add(
}; };
let tree = merge_commit_trees(tx.repo(), &parents)?; 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 let new_wc_commit = tx
.mut_repo() .mut_repo()
.new_commit(command.settings(), parent_ids, tree.id()) .new_commit(command.settings(), parent_ids, tree.id())