Skip to content

Commit

Permalink
rewrite: avoid abandoned commit parent lookup in `rebase_commit_with_…
Browse files Browse the repository at this point in the history
…options`

This is an optimization to avoid fetching the parent commit of an
abandoned commit after rebasing, given that it might not even be used.
  • Loading branch information
bnjmnt4n committed Nov 11, 2024
1 parent 9bd7e77 commit 0e67ef9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
8 changes: 4 additions & 4 deletions lib/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1305,11 +1305,11 @@ impl MutableRepo {
let old_commit_id = rewriter.old_commit().id().clone();
let rebased_commit: RebasedCommit =
rebase_commit_with_options(settings, rewriter, &options)?;
let new_commit = match rebased_commit {
RebasedCommit::Rewritten(new_commit) => new_commit,
RebasedCommit::Abandoned { parent } => parent,
let new_commit_id = match rebased_commit {
RebasedCommit::Rewritten(new_commit) => new_commit.id().clone(),
RebasedCommit::Abandoned { parent_id } => parent_id,
};
rebased.insert(old_commit_id, new_commit.id().clone());
rebased.insert(old_commit_id, new_commit_id);
}
Ok(())
})?;
Expand Down
9 changes: 3 additions & 6 deletions lib/src/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl<'repo> CommitRewriter<'repo> {

pub enum RebasedCommit {
Rewritten(Commit),
Abandoned { parent: Commit },
Abandoned { parent_id: CommitId },
}

pub fn rebase_commit_with_options(
Expand All @@ -318,11 +318,8 @@ pub fn rebase_commit_with_options(
rewriter.simplify_ancestor_merge();
}

// TODO: avoid this lookup by not returning the old parent for
// RebasedCommit::Abandoned
let store = rewriter.mut_repo().store().clone();
let single_parent = match &rewriter.new_parents[..] {
[parent] => Some(store.get_commit(parent)?),
[parent_id] => Some(parent_id.clone()),
_ => None,
};
let new_parents = rewriter.new_parents.clone();
Expand All @@ -332,7 +329,7 @@ pub fn rebase_commit_with_options(
} else {
assert_eq!(new_parents.len(), 1);
Ok(RebasedCommit::Abandoned {
parent: single_parent.unwrap(),
parent_id: single_parent.unwrap(),
})
}
}
Expand Down

0 comments on commit 0e67ef9

Please sign in to comment.