Skip to content

Commit

Permalink
rewrite: pass old parent ids in to mut_repo.new_parents() by slice
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Aug 28, 2024
1 parent 1fe9422 commit d99a850
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cli/src/commands/parallelize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub(crate) fn cmd_parallelize(
// Commits in the target set do not depend on each other but they still depend
// on other parents
if let Some(new_parents) = new_target_parents.get(rewriter.old_commit().id()) {
rewriter.set_new_rewritten_parents(new_parents.clone());
rewriter.set_new_rewritten_parents(new_parents);
} else if rewriter
.old_commit()
.parent_ids()
Expand All @@ -128,7 +128,7 @@ pub(crate) fn cmd_parallelize(
new_parents.push(parent.clone());
}
}
rewriter.set_new_rewritten_parents(new_parents);
rewriter.set_new_rewritten_parents(&new_parents);
}
if rewriter.parents_changed() {
let builder = rewriter.rebase(command.settings())?;
Expand Down
6 changes: 3 additions & 3 deletions lib/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ impl MutableRepo {
///
/// If `parent_mapping` contains cycles, this function may either panic or
/// drop parents that caused cycles.
pub fn new_parents(&self, old_ids: Vec<CommitId>) -> Vec<CommitId> {
pub fn new_parents(&self, old_ids: &[CommitId]) -> Vec<CommitId> {
assert!(!old_ids.is_empty());
let mut new_ids = Vec::with_capacity(old_ids.len());
let mut to_visit = old_ids.iter().rev().collect_vec();
Expand Down Expand Up @@ -1040,7 +1040,7 @@ impl MutableRepo {
// mappings, not transitive ones.
// TODO: keep parent_mapping updated with transitive mappings so we don't need
// to call `new_parents()` here.
let new_parent_ids = self.new_parents(rewrite.new_parent_ids().to_vec());
let new_parent_ids = self.new_parents(rewrite.new_parent_ids());
self.update_references(settings, old_parent_id, new_parent_ids)?;
}
Ok(())
Expand Down Expand Up @@ -1226,7 +1226,7 @@ impl MutableRepo {
) -> BackendResult<()> {
let mut to_visit = self.find_descendants_to_rebase(roots)?;
while let Some(old_commit) = to_visit.pop() {
let new_parent_ids = self.new_parents(old_commit.parent_ids().to_vec());
let new_parent_ids = self.new_parents(old_commit.parent_ids());
let rewriter = CommitRewriter::new(self, old_commit, new_parent_ids);
callback(rewriter)?;
}
Expand Down
9 changes: 3 additions & 6 deletions lib/src/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl<'repo> CommitRewriter<'repo> {

/// Set the old commit's intended new parents to be the rewritten versions
/// of the given parents.
pub fn set_new_rewritten_parents(&mut self, unrewritten_parents: Vec<CommitId>) {
pub fn set_new_rewritten_parents(&mut self, unrewritten_parents: &[CommitId]) {
self.new_parents = self.mut_repo.new_parents(unrewritten_parents);
}

Expand Down Expand Up @@ -426,7 +426,7 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> {
fn rebase_one(&mut self, old_commit: Commit) -> BackendResult<()> {
let old_commit_id = old_commit.id().clone();
let old_parent_ids = old_commit.parent_ids();
let new_parent_ids = self.mut_repo.new_parents(old_parent_ids.to_vec());
let new_parent_ids = self.mut_repo.new_parents(old_parent_ids);
let rewriter = CommitRewriter::new(self.mut_repo, old_commit, new_parent_ids);
if !rewriter.parents_changed() {
// The commit is already in place.
Expand Down Expand Up @@ -806,10 +806,7 @@ pub fn move_commits(
// tests.
while let Some(old_commit_id) = to_visit.pop() {
let old_commit = to_visit_commits.get(&old_commit_id).unwrap();
let parent_ids = to_visit_commits_new_parents
.get(&old_commit_id)
.cloned()
.unwrap();
let parent_ids = to_visit_commits_new_parents.get(&old_commit_id).unwrap();
let new_parent_ids = mut_repo.new_parents(parent_ids);
let rewriter = CommitRewriter::new(mut_repo, old_commit.clone(), new_parent_ids);
if rewriter.parents_changed() {
Expand Down

0 comments on commit d99a850

Please sign in to comment.