MutableRepo: accept just CommitId instead of whole Commit where possible

This commit is contained in:
Martin von Zweigbergk 2021-09-25 09:25:42 -07:00
parent e1fd69cfa8
commit ff71af1e11
7 changed files with 18 additions and 16 deletions

View file

@ -725,8 +725,8 @@ impl MutableRepo {
}
}
pub fn remove_head(&mut self, head: &Commit) {
self.view.remove_head(head.id());
pub fn remove_head(&mut self, head: &CommitId) {
self.view.remove_head(head);
self.enforce_view_invariants();
self.invalidate_evolution();
}
@ -739,8 +739,8 @@ impl MutableRepo {
}
}
pub fn remove_public_head(&mut self, head: &Commit) {
self.view.remove_public_head(head.id());
pub fn remove_public_head(&mut self, head: &CommitId) {
self.view.remove_public_head(head);
self.invalidate_evolution();
}

View file

@ -73,7 +73,7 @@ fn test_obsolete_and_orphan(use_git: bool) {
assert!(!mut_repo.evolution().is_orphan(rewritten.id()));
// It should no longer be obsolete if we remove the successor.
mut_repo.remove_head(&rewritten);
mut_repo.remove_head(rewritten.id());
assert!(!mut_repo.evolution().is_obsolete(original.id()));
assert!(!mut_repo.evolution().is_orphan(child.id()));
assert!(!mut_repo.evolution().is_orphan(grandchild.id()));

View file

@ -255,7 +255,7 @@ fn test_index_commits_previous_operations(use_git: bool) {
let repo = tx.commit();
let mut tx = repo.start_transaction("test");
tx.mut_repo().remove_head(&commit_c);
tx.mut_repo().remove_head(commit_c.id());
let repo = tx.commit();
// Delete index from disk

View file

@ -52,7 +52,7 @@ fn test_load_at_operation(use_git: bool) {
let repo = tx.commit();
let mut tx = repo.start_transaction("remove commit");
tx.mut_repo().remove_head(&commit);
tx.mut_repo().remove_head(commit.id());
tx.commit();
// If we load the repo at head, we should not see the commit since it was

View file

@ -428,7 +428,7 @@ fn test_remove_head(use_git: bool) {
let mut tx = repo.start_transaction("test");
let mut_repo = tx.mut_repo();
assert!(mut_repo.view().heads().contains(commit3.id()));
mut_repo.remove_head(&commit3);
mut_repo.remove_head(commit3.id());
let heads = mut_repo.view().heads().clone();
assert!(!heads.contains(commit3.id()));
assert!(!heads.contains(commit2.id()));
@ -474,7 +474,7 @@ fn test_remove_head_ancestor_git_ref(use_git: bool) {
let mut_repo = tx.mut_repo();
let heads = mut_repo.view().heads().clone();
assert!(heads.contains(commit5.id()));
mut_repo.remove_head(&commit5);
mut_repo.remove_head(commit5.id());
let heads = mut_repo.view().heads().clone();
assert!(!heads.contains(commit5.id()));
assert!(heads.contains(commit4.id()));
@ -552,7 +552,7 @@ fn test_remove_public_head(use_git: bool) {
let mut tx = repo.start_transaction("test");
let mut_repo = tx.mut_repo();
assert!(mut_repo.view().public_heads().contains(commit1.id()));
mut_repo.remove_public_head(&commit1);
mut_repo.remove_public_head(commit1.id());
assert!(!mut_repo.view().public_heads().contains(commit1.id()));
let repo = tx.commit();
assert!(!repo.view().public_heads().contains(commit1.id()));

View file

@ -100,8 +100,9 @@ fn test_merge_views_heads() {
let repo = tx.commit();
let mut tx1 = repo.start_transaction("test");
tx1.mut_repo().remove_head(&head_remove_tx1);
tx1.mut_repo().remove_public_head(&public_head_remove_tx1);
tx1.mut_repo().remove_head(head_remove_tx1.id());
tx1.mut_repo()
.remove_public_head(public_head_remove_tx1.id());
let head_add_tx1 =
testutils::create_random_commit(&settings, &repo).write_to_repo(tx1.mut_repo());
let public_head_add_tx1 =
@ -110,8 +111,9 @@ fn test_merge_views_heads() {
tx1.commit();
let mut tx2 = repo.start_transaction("test");
tx2.mut_repo().remove_head(&head_remove_tx2);
tx2.mut_repo().remove_public_head(&public_head_remove_tx2);
tx2.mut_repo().remove_head(head_remove_tx2.id());
tx2.mut_repo()
.remove_public_head(public_head_remove_tx2.id());
let head_add_tx2 =
testutils::create_random_commit(&settings, &repo).write_to_repo(tx2.mut_repo());
let public_head_add_tx2 =

View file

@ -2370,9 +2370,9 @@ fn cmd_discard(
let mut tx = repo_command.start_transaction(&format!("discard commit {}", commit.id().hex()));
let mut_repo = tx.mut_repo();
if sub_matches.is_present("public") {
mut_repo.remove_public_head(&commit);
mut_repo.remove_public_head(commit.id());
} else {
mut_repo.remove_head(&commit);
mut_repo.remove_head(commit.id());
}
for parent in commit.parents() {
mut_repo.add_head(&parent);