From dc06bbc7d1c883fc05ab87ba01a9cf7b45061982 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sun, 27 Aug 2023 09:49:10 -0700 Subject: [PATCH] commit: migrate remaining uses of `Commit::tree_id()` and delete it --- cli/src/commands/mod.rs | 2 +- lib/src/commit.rs | 10 ++-------- lib/src/default_revset_engine.rs | 2 +- lib/tests/test_init.rs | 6 +++++- lib/tests/test_mut_repo.rs | 5 ++++- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/cli/src/commands/mod.rs b/cli/src/commands/mod.rs index 684b870ec..88cad96a1 100644 --- a/cli/src/commands/mod.rs +++ b/cli/src/commands/mod.rs @@ -3108,7 +3108,7 @@ don't make any changes, then the operation will be aborted. .mut_repo() .rewrite_commit(command.settings(), &commit) .set_parents(vec![first_commit.id().clone()]) - .set_tree(commit.tree_id().clone()) + .set_tree_id(commit.merged_tree_id().clone()) .generate_new_change_id() .set_description(second_description) .write()?; diff --git a/lib/src/commit.rs b/lib/src/commit.rs index 98d013741..fb49c8524 100644 --- a/lib/src/commit.rs +++ b/lib/src/commit.rs @@ -20,7 +20,7 @@ use std::hash::{Hash, Hasher}; use std::sync::Arc; use crate::backend; -use crate::backend::{BackendError, ChangeId, CommitId, MergedTreeId, Signature, TreeId}; +use crate::backend::{BackendError, ChangeId, CommitId, MergedTreeId, Signature}; use crate::merged_tree::MergedTree; use crate::repo_path::RepoPath; use crate::store::Store; @@ -113,12 +113,6 @@ impl Commit { self.store.get_root_tree(&self.data.root_tree) } - // TODO(#1624): delete when all callers have been updated to support tree-level - // conflicts - pub fn tree_id(&self) -> &TreeId { - self.data.root_tree.as_legacy_tree_id() - } - pub fn merged_tree_id(&self) -> &MergedTreeId { &self.data.root_tree } @@ -148,7 +142,7 @@ impl Commit { pub fn is_discardable(&self) -> bool { if self.description().is_empty() { if let [parent_commit] = &*self.parents() { - return self.tree_id() == parent_commit.tree_id(); + return self.merged_tree_id() == parent_commit.merged_tree_id(); } } false diff --git a/lib/src/default_revset_engine.rs b/lib/src/default_revset_engine.rs index 5f5b3c0ac..c5bc9e757 100644 --- a/lib/src/default_revset_engine.rs +++ b/lib/src/default_revset_engine.rs @@ -884,7 +884,7 @@ fn has_diff_from_parent( let parents = commit.parents(); if let [parent] = parents.as_slice() { // Fast path: no need to load the root tree - let unchanged = commit.tree_id() == parent.tree_id(); + let unchanged = commit.merged_tree_id() == parent.merged_tree_id(); if matcher.visit(&RepoPath::root()) == Visit::AllRecursively { return !unchanged; } else if unchanged { diff --git a/lib/tests/test_init.rs b/lib/tests/test_init.rs index 8acc4474d..547421c69 100644 --- a/lib/tests/test_init.rs +++ b/lib/tests/test_init.rs @@ -14,6 +14,7 @@ use std::path::{Path, PathBuf}; +use jj_lib::backend::MergedTreeId; use jj_lib::git_backend::GitBackend; use jj_lib::op_store::WorkspaceId; use jj_lib::repo::Repo; @@ -123,7 +124,10 @@ fn test_init_checkout(use_git: bool) { .get_wc_commit_id(&WorkspaceId::default()) .unwrap(); let wc_commit = repo.store().get_commit(wc_commit_id).unwrap(); - assert_eq!(wc_commit.tree_id(), repo.store().empty_tree_id()); + assert_eq!( + *wc_commit.merged_tree_id(), + MergedTreeId::Legacy(repo.store().empty_tree_id().clone()) + ); assert_eq!( wc_commit.store_commit().parents, vec![repo.store().root_commit_id().clone()] diff --git a/lib/tests/test_mut_repo.rs b/lib/tests/test_mut_repo.rs index bf22fbf0a..7105ba401 100644 --- a/lib/tests/test_mut_repo.rs +++ b/lib/tests/test_mut_repo.rs @@ -58,7 +58,10 @@ fn test_checkout(use_git: bool) { .mut_repo() .check_out(ws_id.clone(), &settings, &wc_commit_parent) .unwrap(); - assert_eq!(wc_commit.tree_id(), wc_commit_parent.tree_id()); + assert_eq!( + wc_commit.merged_tree_id(), + wc_commit_parent.merged_tree_id() + ); assert_eq!(wc_commit.parents().len(), 1); assert_eq!(wc_commit.parents()[0].id(), wc_commit_parent.id()); let repo = tx.commit();