From d8997999f225d8b23bb19c52de7f0fe780d16c4e Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Mon, 13 Feb 2023 09:52:21 -0800 Subject: [PATCH] repo: replace RepoRef by Repo trait --- lib/src/repo.rs | 80 ----- lib/src/revset.rs | 28 +- lib/src/rewrite.rs | 18 +- lib/tests/test_operations.rs | 24 +- lib/tests/test_revset.rs | 386 ++++++++++-------------- lib/tests/test_revset_graph_iterator.rs | 17 +- src/cli_util.rs | 16 +- src/commands/branch.rs | 10 +- src/commands/git.rs | 16 +- src/commands/mod.rs | 27 +- src/diff_util.rs | 2 +- src/template_parser.rs | 6 +- src/templater.rs | 20 +- 13 files changed, 246 insertions(+), 404 deletions(-) diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 3a7b12bc1..b0cc68797 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -75,78 +75,6 @@ pub trait Repo { fn shortest_unique_change_id_prefix_len(&self, target_id_bytes: &ChangeId) -> usize; } -// TODO: Should we implement From<&ReadonlyRepo> and From<&MutableRepo> for -// RepoRef? -#[derive(Clone, Copy)] -pub enum RepoRef<'a> { - Readonly(&'a Arc), - Mutable(&'a MutableRepo), -} - -impl<'a> RepoRef<'a> { - pub fn base_repo(&self) -> &Arc { - match self { - RepoRef::Readonly(repo) => &repo, - RepoRef::Mutable(repo) => &repo.base_repo, - } - } - - pub fn store(&self) -> &Arc { - match self { - RepoRef::Readonly(repo) => repo.store(), - RepoRef::Mutable(repo) => repo.store(), - } - } - - pub fn op_store(&self) -> &Arc { - match self { - RepoRef::Readonly(repo) => repo.op_store(), - RepoRef::Mutable(repo) => repo.op_store(), - } - } - - pub fn index(&self) -> &'a dyn Index { - match self { - RepoRef::Readonly(repo) => repo.index(), - RepoRef::Mutable(repo) => repo.index(), - } - } - - pub fn view(&self) -> &View { - match self { - RepoRef::Readonly(repo) => repo.view(), - RepoRef::Mutable(repo) => repo.view(), - } - } - - pub fn resolve_change_id(&self, change_id: &ChangeId) -> Option>> { - // Replace this if we added more efficient lookup method. - let prefix = HexPrefix::from_bytes(change_id.as_bytes()); - match self.resolve_change_id_prefix(&prefix) { - PrefixResolution::NoMatch => None, - PrefixResolution::SingleMatch(entries) => Some(entries), - PrefixResolution::AmbiguousMatch => panic!("complete change_id should be unambiguous"), - } - } - - pub fn resolve_change_id_prefix( - &self, - prefix: &HexPrefix, - ) -> PrefixResolution>> { - match self { - RepoRef::Readonly(repo) => repo.resolve_change_id_prefix(prefix), - RepoRef::Mutable(repo) => repo.resolve_change_id_prefix(prefix), - } - } - - pub fn shortest_unique_change_id_prefix_len(&self, target_id: &ChangeId) -> usize { - match self { - RepoRef::Readonly(repo) => repo.shortest_unique_change_id_prefix_len(target_id), - RepoRef::Mutable(repo) => repo.shortest_unique_change_id_prefix_len(target_id), - } - } -} - pub struct ReadonlyRepo { repo_path: PathBuf, store: Arc, @@ -271,10 +199,6 @@ impl ReadonlyRepo { } } - pub fn as_repo_ref<'a>(self: &'a Arc) -> RepoRef<'a> { - RepoRef::Readonly(self) - } - pub fn repo_path(&self) -> &PathBuf { &self.repo_path } @@ -654,10 +578,6 @@ impl MutableRepo { } } - pub fn as_repo_ref(&self) -> RepoRef { - RepoRef::Mutable(self) - } - fn view_mut(&mut self) -> &mut View { self.view.get_mut() } diff --git a/lib/src/revset.rs b/lib/src/revset.rs index b4cf5a6d4..1961f3d43 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -36,7 +36,7 @@ use crate::hex_util::to_forward_hex; use crate::index::{HexPrefix, IndexEntry, PrefixResolution}; use crate::matchers::{EverythingMatcher, Matcher, PrefixMatcher}; use crate::op_store::WorkspaceId; -use crate::repo::RepoRef; +use crate::repo::Repo; use crate::repo_path::{FsPathParseError, RepoPath}; use crate::revset_graph_iterator::RevsetGraphIterator; use crate::rewrite; @@ -52,7 +52,7 @@ pub enum RevsetError { StoreError(#[source] BackendError), } -fn resolve_git_ref(repo: RepoRef, symbol: &str) -> Option> { +fn resolve_git_ref(repo: &dyn Repo, symbol: &str) -> Option> { let view = repo.view(); for git_ref_prefix in &["", "refs/", "refs/heads/", "refs/tags/", "refs/remotes/"] { if let Some(ref_target) = view.git_refs().get(&(git_ref_prefix.to_string() + symbol)) { @@ -62,7 +62,7 @@ fn resolve_git_ref(repo: RepoRef, symbol: &str) -> Option> { None } -fn resolve_branch(repo: RepoRef, symbol: &str) -> Option> { +fn resolve_branch(repo: &dyn Repo, symbol: &str) -> Option> { if let Some(branch_target) = repo.view().branches().get(symbol) { return Some( branch_target @@ -83,7 +83,7 @@ fn resolve_branch(repo: RepoRef, symbol: &str) -> Option> { } fn resolve_full_commit_id( - repo: RepoRef, + repo: &dyn Repo, symbol: &str, ) -> Result>, RevsetError> { if let Ok(binary_commit_id) = hex::decode(symbol) { @@ -103,7 +103,7 @@ fn resolve_full_commit_id( } fn resolve_short_commit_id( - repo: RepoRef, + repo: &dyn Repo, symbol: &str, ) -> Result>, RevsetError> { if let Some(prefix) = HexPrefix::new(symbol) { @@ -119,7 +119,7 @@ fn resolve_short_commit_id( } } -fn resolve_change_id(repo: RepoRef, symbol: &str) -> Result>, RevsetError> { +fn resolve_change_id(repo: &dyn Repo, symbol: &str) -> Result>, RevsetError> { if let Some(prefix) = to_forward_hex(symbol).as_deref().and_then(HexPrefix::new) { match repo.resolve_change_id_prefix(&prefix) { PrefixResolution::NoMatch => Ok(None), @@ -136,7 +136,7 @@ fn resolve_change_id(repo: RepoRef, symbol: &str) -> Result } pub fn resolve_symbol( - repo: RepoRef, + repo: &dyn Repo, symbol: &str, workspace_id: Option<&WorkspaceId>, ) -> Result, RevsetError> { @@ -538,7 +538,7 @@ impl RevsetExpression { pub fn evaluate<'repo>( &self, - repo: RepoRef<'repo>, + repo: &'repo dyn Repo, workspace_ctx: Option<&RevsetWorkspaceContext>, ) -> Result + 'repo>, RevsetError> { evaluate_expression(repo, self, workspace_ctx) @@ -1916,7 +1916,7 @@ pub struct RevsetWorkspaceContext<'a> { } pub fn evaluate_expression<'repo>( - repo: RepoRef<'repo>, + repo: &'repo dyn Repo, expression: &RevsetExpression, workspace_ctx: Option<&RevsetWorkspaceContext>, ) -> Result + 'repo>, RevsetError> { @@ -2127,7 +2127,7 @@ pub fn evaluate_expression<'repo>( } fn revset_for_commit_ids<'revset, 'repo: 'revset>( - repo: RepoRef<'repo>, + repo: &'repo dyn Repo, commit_ids: &[CommitId], ) -> Box + 'revset> { let index = repo.index(); @@ -2141,7 +2141,7 @@ fn revset_for_commit_ids<'revset, 'repo: 'revset>( } pub fn revset_for_commits<'revset, 'repo: 'revset>( - repo: RepoRef<'repo>, + repo: &'repo dyn Repo, commits: &[&Commit], ) -> Box + 'revset> { let index = repo.index(); @@ -2162,7 +2162,7 @@ impl<'repo> ToPredicateFn<'repo> for PurePredicateFn<'repo> { } fn build_predicate_fn<'repo>( - repo: RepoRef<'repo>, + repo: &'repo dyn Repo, predicate: &RevsetFilterPredicate, ) -> PurePredicateFn<'repo> { match predicate { @@ -2212,7 +2212,7 @@ fn build_predicate_fn<'repo>( } pub fn filter_by_diff<'revset, 'repo: 'revset>( - repo: RepoRef<'repo>, + repo: &'repo dyn Repo, matcher: impl Borrow + 'repo, candidates: Box + 'revset>, ) -> Box + 'revset> { @@ -2222,7 +2222,7 @@ pub fn filter_by_diff<'revset, 'repo: 'revset>( }) } -fn has_diff_from_parent(repo: RepoRef<'_>, entry: &IndexEntry<'_>, matcher: &dyn Matcher) -> bool { +fn has_diff_from_parent(repo: &dyn Repo, entry: &IndexEntry<'_>, matcher: &dyn Matcher) -> bool { let commit = repo.store().get_commit(&entry.commit_id()).unwrap(); let parents = commit.parents(); let from_tree = rewrite::merge_commit_trees(repo, &parents); diff --git a/lib/src/rewrite.rs b/lib/src/rewrite.rs index 7f645b916..7b56f8b8b 100644 --- a/lib/src/rewrite.rs +++ b/lib/src/rewrite.rs @@ -20,14 +20,14 @@ use crate::backend::{BackendError, BackendResult, CommitId, ObjectId}; use crate::commit::Commit; use crate::dag_walk; use crate::op_store::RefTarget; -use crate::repo::{MutableRepo, Repo, RepoRef}; +use crate::repo::{MutableRepo, Repo}; use crate::repo_path::RepoPath; use crate::revset::RevsetExpression; use crate::settings::UserSettings; use crate::tree::{merge_trees, Tree}; use crate::view::RefName; -pub fn merge_commit_trees(repo: RepoRef, commits: &[Commit]) -> Tree { +pub fn merge_commit_trees(repo: &dyn Repo, commits: &[Commit]) -> Tree { let store = repo.store(); if commits.is_empty() { store @@ -73,8 +73,8 @@ pub fn rebase_commit( // Optimization old_commit.tree_id().clone() } else { - let old_base_tree = merge_commit_trees(mut_repo.as_repo_ref(), &old_parents); - let new_base_tree = merge_commit_trees(mut_repo.as_repo_ref(), new_parents); + let old_base_tree = merge_commit_trees(mut_repo, &old_parents); + let new_base_tree = merge_commit_trees(mut_repo, new_parents); // TODO: pass in labels for the merge parts merge_trees(&new_base_tree, &old_base_tree, &old_commit.tree()).unwrap() }; @@ -95,8 +95,8 @@ pub fn back_out_commit( old_commit: &Commit, new_parents: &[Commit], ) -> BackendResult { - let old_base_tree = merge_commit_trees(mut_repo.as_repo_ref(), &old_commit.parents()); - let new_base_tree = merge_commit_trees(mut_repo.as_repo_ref(), new_parents); + let old_base_tree = merge_commit_trees(mut_repo, &old_commit.parents()); + let new_base_tree = merge_commit_trees(mut_repo, new_parents); // TODO: pass in labels for the merge parts let new_tree_id = merge_trees(&new_base_tree, &old_commit.tree(), &old_base_tree).unwrap(); let new_parent_ids = new_parents @@ -157,16 +157,14 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> { .parents() .minus(&old_commits_expression); let heads_to_add = heads_to_add_expression - .evaluate(mut_repo.as_repo_ref(), None) + .evaluate(mut_repo, None) .unwrap() .iter() .commit_ids() .collect(); let to_visit_expression = old_commits_expression.descendants(); - let to_visit_revset = to_visit_expression - .evaluate(mut_repo.as_repo_ref(), None) - .unwrap(); + let to_visit_revset = to_visit_expression.evaluate(mut_repo, None).unwrap(); let to_visit_entries = to_visit_revset.iter().collect_vec(); drop(to_visit_revset); let index = mut_repo.index(); diff --git a/lib/tests/test_operations.rs b/lib/tests/test_operations.rs index 50c5c95e6..07a7eccb2 100644 --- a/lib/tests/test_operations.rs +++ b/lib/tests/test_operations.rs @@ -15,7 +15,7 @@ use std::path::Path; use jujutsu_lib::backend::CommitId; -use jujutsu_lib::repo::{Repo, RepoRef}; +use jujutsu_lib::repo::Repo; use test_case::test_case; use testutils::{create_random_commit, write_random_commit, TestRepo}; @@ -122,7 +122,7 @@ fn test_concurrent_operations(use_git: bool) { assert_eq!(list_dir(&op_heads_dir), vec![merged_op_id.hex()]); } -fn assert_heads(repo: RepoRef, expected: Vec<&CommitId>) { +fn assert_heads(repo: &dyn Repo, expected: Vec<&CommitId>) { let expected = expected.iter().cloned().cloned().collect(); assert_eq!(*repo.view().heads(), expected); } @@ -147,9 +147,9 @@ fn test_isolation(use_git: bool) { let mut tx2 = repo.start_transaction(&settings, "transaction 2"); let mut_repo2 = tx2.mut_repo(); - assert_heads(repo.as_repo_ref(), vec![initial.id()]); - assert_heads(mut_repo1.as_repo_ref(), vec![initial.id()]); - assert_heads(mut_repo2.as_repo_ref(), vec![initial.id()]); + assert_heads(&repo, vec![initial.id()]); + assert_heads(mut_repo1, vec![initial.id()]); + assert_heads(mut_repo2, vec![initial.id()]); let rewrite1 = mut_repo1 .rewrite_commit(&settings, &initial) @@ -166,19 +166,19 @@ fn test_isolation(use_git: bool) { // Neither transaction has committed yet, so each transaction sees its own // commit. - assert_heads(repo.as_repo_ref(), vec![initial.id()]); - assert_heads(mut_repo1.as_repo_ref(), vec![rewrite1.id()]); - assert_heads(mut_repo2.as_repo_ref(), vec![rewrite2.id()]); + assert_heads(&repo, vec![initial.id()]); + assert_heads(mut_repo1, vec![rewrite1.id()]); + assert_heads(mut_repo2, vec![rewrite2.id()]); // The base repo and tx2 don't see the commits from tx1. tx1.commit(); - assert_heads(repo.as_repo_ref(), vec![initial.id()]); - assert_heads(mut_repo2.as_repo_ref(), vec![rewrite2.id()]); + assert_heads(&repo, vec![initial.id()]); + assert_heads(mut_repo2, vec![rewrite2.id()]); // The base repo still doesn't see the commits after both transactions commit. tx2.commit(); - assert_heads(repo.as_repo_ref(), vec![initial.id()]); + assert_heads(&repo, vec![initial.id()]); // After reload, the base repo sees both rewrites. let repo = repo.reload_at_head(&settings).unwrap(); - assert_heads(repo.as_repo_ref(), vec![rewrite1.id(), rewrite2.id()]); + assert_heads(&repo, vec![rewrite1.id(), rewrite2.id()]); } diff --git a/lib/tests/test_revset.rs b/lib/tests/test_revset.rs index c65c99f17..be3fdc7be 100644 --- a/lib/tests/test_revset.rs +++ b/lib/tests/test_revset.rs @@ -19,7 +19,7 @@ use jujutsu_lib::backend::{CommitId, MillisSinceEpoch, ObjectId, Signature, Time use jujutsu_lib::git; use jujutsu_lib::matchers::{FilesMatcher, Matcher}; use jujutsu_lib::op_store::{RefTarget, WorkspaceId}; -use jujutsu_lib::repo::{Repo, RepoRef}; +use jujutsu_lib::repo::Repo; use jujutsu_lib::repo_path::RepoPath; use jujutsu_lib::revset::{ self, optimize, parse, resolve_symbol, RevsetAliasesMap, RevsetError, RevsetExpression, @@ -39,7 +39,7 @@ fn test_resolve_symbol_root(use_git: bool) { let repo = &test_repo.repo; assert_matches!( - resolve_symbol(repo.as_repo_ref(), "root", None), + resolve_symbol(repo, "root", None), Ok(v) if v == vec![repo.store().root_commit_id().clone()] ); } @@ -99,60 +99,59 @@ fn test_resolve_symbol_commit_id() { insta::assert_snapshot!(commits[2].change_id().hex(), @"4399e4f3123763dfe7d68a2809ecc01b"); // Test lookup by full commit id - let repo_ref = repo.as_repo_ref(); assert_eq!( - resolve_symbol(repo_ref, "0454de3cae04c46cda37ba2e8873b4c17ff51dcb", None).unwrap(), + resolve_symbol(&repo, "0454de3cae04c46cda37ba2e8873b4c17ff51dcb", None).unwrap(), vec![commits[0].id().clone()] ); assert_eq!( - resolve_symbol(repo_ref, "045f56cd1b17e8abde86771e2705395dcde6a957", None).unwrap(), + resolve_symbol(&repo, "045f56cd1b17e8abde86771e2705395dcde6a957", None).unwrap(), vec![commits[1].id().clone()] ); assert_eq!( - resolve_symbol(repo_ref, "0468f7da8de2ce442f512aacf83411d26cd2e0cf", None).unwrap(), + resolve_symbol(&repo, "0468f7da8de2ce442f512aacf83411d26cd2e0cf", None).unwrap(), vec![commits[2].id().clone()] ); // Test empty commit id assert_matches!( - resolve_symbol(repo_ref, "", None), + resolve_symbol(&repo, "", None), Err(RevsetError::AmbiguousIdPrefix(s)) if s.is_empty() ); // Test commit id prefix assert_eq!( - resolve_symbol(repo_ref, "046", None).unwrap(), + resolve_symbol(&repo, "046", None).unwrap(), vec![commits[2].id().clone()] ); assert_matches!( - resolve_symbol(repo_ref, "04", None), + resolve_symbol(&repo, "04", None), Err(RevsetError::AmbiguousIdPrefix(s)) if s == "04" ); assert_matches!( - resolve_symbol(repo_ref, "", None), + resolve_symbol(&repo, "", None), Err(RevsetError::AmbiguousIdPrefix(s)) if s.is_empty() ); assert_matches!( - resolve_symbol(repo_ref, "040", None), + resolve_symbol(&repo, "040", None), Err(RevsetError::NoSuchRevision(s)) if s == "040" ); // Test non-hex string assert_matches!( - resolve_symbol(repo_ref, "foo", None), + resolve_symbol(&repo, "foo", None), Err(RevsetError::NoSuchRevision(s)) if s == "foo" ); // Test present() suppresses only NoSuchRevision error - assert_eq!(resolve_commit_ids(repo_ref, "present(foo)"), []); + assert_eq!(resolve_commit_ids(&repo, "present(foo)"), []); assert_matches!( optimize(parse("present(04)", &RevsetAliasesMap::new(), None).unwrap()) - .evaluate(repo_ref, None) + .evaluate(&repo, None) .map(|_| ()), Err(RevsetError::AmbiguousIdPrefix(s)) if s == "04" ); assert_eq!( - resolve_commit_ids(repo_ref, "present(046)"), + resolve_commit_ids(&repo, "present(046)"), vec![commits[2].id().clone()] ); } @@ -222,29 +221,29 @@ fn test_resolve_symbol_change_id(readonly: bool) { "040031cb4ad0cbc3287914f1d205dabf4a7eb889" ); - let repo; - let repo_ref = if readonly { - repo = tx.commit(); - repo.as_repo_ref() + let _readonly_repo; + let repo: &dyn Repo = if readonly { + _readonly_repo = tx.commit(); + &_readonly_repo } else { - tx.repo().as_repo_ref() + tx.mut_repo() }; // Test lookup by full change id assert_eq!( - resolve_symbol(repo_ref, "zvlyxpuvtsoopsqzlkorrpqrszrqvlnx", None).unwrap(), + resolve_symbol(repo, "zvlyxpuvtsoopsqzlkorrpqrszrqvlnx", None).unwrap(), vec![CommitId::from_hex( "8fd68d104372910e19511df709e5dde62a548720" )] ); assert_eq!( - resolve_symbol(repo_ref, "zvzowopwpuymrlmonvnuruunomzqmlsy", None).unwrap(), + resolve_symbol(repo, "zvzowopwpuymrlmonvnuruunomzqmlsy", None).unwrap(), vec![CommitId::from_hex( "5339432b8e7b90bd3aa1a323db71b8a5c5dcd020" )] ); assert_eq!( - resolve_symbol(repo_ref, "zvlynszrxlvlwvkwkwsymrpypvtsszor", None).unwrap(), + resolve_symbol(repo, "zvlynszrxlvlwvkwkwsymrpypvtsszor", None).unwrap(), vec![CommitId::from_hex( "e2ad9d861d0ee625851b8ecfcf2c727410e38720" )] @@ -252,40 +251,40 @@ fn test_resolve_symbol_change_id(readonly: bool) { // Test change id prefix assert_eq!( - resolve_symbol(repo_ref, "zvlyx", None).unwrap(), + resolve_symbol(repo, "zvlyx", None).unwrap(), vec![CommitId::from_hex( "8fd68d104372910e19511df709e5dde62a548720" )] ); assert_eq!( - resolve_symbol(repo_ref, "zvlyn", None).unwrap(), + resolve_symbol(repo, "zvlyn", None).unwrap(), vec![CommitId::from_hex( "e2ad9d861d0ee625851b8ecfcf2c727410e38720" )] ); assert_matches!( - resolve_symbol(repo_ref, "zvly", None), + resolve_symbol(repo, "zvly", None), Err(RevsetError::AmbiguousIdPrefix(s)) if s == "zvly" ); assert_matches!( - resolve_symbol(repo_ref, "", None), + resolve_symbol(repo, "", None), Err(RevsetError::AmbiguousIdPrefix(s)) if s.is_empty() ); assert_matches!( - resolve_symbol(repo_ref, "zvlyw", None), + resolve_symbol(repo, "zvlyw", None), Err(RevsetError::NoSuchRevision(s)) if s == "zvlyw" ); // Test that commit and changed id don't conflict ("040" and "zvz" are the // same). assert_eq!( - resolve_symbol(repo_ref, "040", None).unwrap(), + resolve_symbol(repo, "040", None).unwrap(), vec![CommitId::from_hex( "040031cb4ad0cbc3287914f1d205dabf4a7eb889" )] ); assert_eq!( - resolve_symbol(repo_ref, "zvz", None).unwrap(), + resolve_symbol(repo, "zvz", None).unwrap(), vec![CommitId::from_hex( "5339432b8e7b90bd3aa1a323db71b8a5c5dcd020" )] @@ -293,7 +292,7 @@ fn test_resolve_symbol_change_id(readonly: bool) { // Test non-hex string assert_matches!( - resolve_symbol(repo_ref, "foo", None), + resolve_symbol(repo, "foo", None), Err(RevsetError::NoSuchRevision(s)) if s == "foo" ); } @@ -316,15 +315,15 @@ fn test_resolve_symbol_checkout(use_git: bool) { // With no workspaces, no variation can be resolved assert_matches!( - resolve_symbol(mut_repo.as_repo_ref(), "@", None), + resolve_symbol(mut_repo, "@", None), Err(RevsetError::NoSuchRevision(s)) if s == "@" ); assert_matches!( - resolve_symbol(mut_repo.as_repo_ref(), "@", Some(&ws1)), + resolve_symbol(mut_repo, "@", Some(&ws1)), Err(RevsetError::NoSuchRevision(s)) if s == "@" ); assert_matches!( - resolve_symbol(mut_repo.as_repo_ref(), "ws1@", Some(&ws1)), + resolve_symbol(mut_repo, "ws1@", Some(&ws1)), Err(RevsetError::NoSuchRevision(s)) if s == "ws1@" ); @@ -335,17 +334,17 @@ fn test_resolve_symbol_checkout(use_git: bool) { mut_repo.set_wc_commit(ws2, commit2.id().clone()).unwrap(); // @ cannot be resolved without a default workspace ID assert_matches!( - resolve_symbol(mut_repo.as_repo_ref(), "@", None), + resolve_symbol(mut_repo, "@", None), Err(RevsetError::NoSuchRevision(s)) if s == "@" ); // Can resolve "@" shorthand with a default workspace ID assert_eq!( - resolve_symbol(mut_repo.as_repo_ref(), "@", Some(&ws1)).unwrap(), + resolve_symbol(mut_repo, "@", Some(&ws1)).unwrap(), vec![commit1.id().clone()] ); // Can resolve an explicit checkout assert_eq!( - resolve_symbol(mut_repo.as_repo_ref(), "ws2@", Some(&ws1)).unwrap(), + resolve_symbol(mut_repo, "ws2@", Some(&ws1)).unwrap(), vec![commit2.id().clone()] ); } @@ -391,7 +390,7 @@ fn test_resolve_symbol_git_refs() { // Nonexistent ref assert_matches!( - resolve_symbol(mut_repo.as_repo_ref(), "nonexistent", None), + resolve_symbol(mut_repo, "nonexistent", None), Err(RevsetError::NoSuchRevision(s)) if s == "nonexistent" ); @@ -401,7 +400,7 @@ fn test_resolve_symbol_git_refs() { RefTarget::Normal(commit4.id().clone()), ); assert_eq!( - resolve_symbol(mut_repo.as_repo_ref(), "refs/heads/branch", None).unwrap(), + resolve_symbol(mut_repo, "refs/heads/branch", None).unwrap(), vec![commit4.id().clone()] ); @@ -415,7 +414,7 @@ fn test_resolve_symbol_git_refs() { RefTarget::Normal(commit4.id().clone()), ); assert_eq!( - resolve_symbol(mut_repo.as_repo_ref(), "heads/branch", None).unwrap(), + resolve_symbol(mut_repo, "heads/branch", None).unwrap(), vec![commit5.id().clone()] ); @@ -429,7 +428,7 @@ fn test_resolve_symbol_git_refs() { RefTarget::Normal(commit4.id().clone()), ); assert_eq!( - resolve_symbol(mut_repo.as_repo_ref(), "branch", None).unwrap(), + resolve_symbol(mut_repo, "branch", None).unwrap(), vec![commit3.id().clone()] ); @@ -439,7 +438,7 @@ fn test_resolve_symbol_git_refs() { RefTarget::Normal(commit4.id().clone()), ); assert_eq!( - resolve_symbol(mut_repo.as_repo_ref(), "tag", None).unwrap(), + resolve_symbol(mut_repo, "tag", None).unwrap(), vec![commit4.id().clone()] ); @@ -449,7 +448,7 @@ fn test_resolve_symbol_git_refs() { RefTarget::Normal(commit2.id().clone()), ); assert_eq!( - resolve_symbol(mut_repo.as_repo_ref(), "origin/remote-branch", None).unwrap(), + resolve_symbol(mut_repo, "origin/remote-branch", None).unwrap(), vec![commit2.id().clone()] ); @@ -461,22 +460,22 @@ fn test_resolve_symbol_git_refs() { mut_repo.set_git_ref("@".to_string(), RefTarget::Normal(commit2.id().clone())); mut_repo.set_git_ref("root".to_string(), RefTarget::Normal(commit3.id().clone())); assert_eq!( - resolve_symbol(mut_repo.as_repo_ref(), "@", Some(&ws_id)).unwrap(), + resolve_symbol(mut_repo, "@", Some(&ws_id)).unwrap(), vec![mut_repo.view().get_wc_commit_id(&ws_id).unwrap().clone()] ); assert_eq!( - resolve_symbol(mut_repo.as_repo_ref(), "root", None).unwrap(), + resolve_symbol(mut_repo, "root", None).unwrap(), vec![mut_repo.store().root_commit().id().clone()] ); // Conflicted ref resolves to its "adds" assert_eq!( - resolve_symbol(mut_repo.as_repo_ref(), "refs/heads/conflicted", None).unwrap(), + resolve_symbol(mut_repo, "refs/heads/conflicted", None).unwrap(), vec![commit1.id().clone(), commit3.id().clone()] ); } -fn resolve_commit_ids(repo: RepoRef, revset_str: &str) -> Vec { +fn resolve_commit_ids(repo: &dyn Repo, revset_str: &str) -> Vec { let expression = optimize(parse(revset_str, &RevsetAliasesMap::new(), None).unwrap()); expression .evaluate(repo, None) @@ -487,7 +486,7 @@ fn resolve_commit_ids(repo: RepoRef, revset_str: &str) -> Vec { } fn resolve_commit_ids_in_workspace( - repo: RepoRef, + repo: &dyn Repo, revset_str: &str, workspace: &Workspace, cwd: Option<&Path>, @@ -522,7 +521,7 @@ fn test_evaluate_expression_root_and_checkout(use_git: bool) { // Can find the root commit assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "root"), + resolve_commit_ids(mut_repo, "root"), vec![root_commit.id().clone()] ); @@ -531,12 +530,7 @@ fn test_evaluate_expression_root_and_checkout(use_git: bool) { .set_wc_commit(WorkspaceId::default(), commit1.id().clone()) .unwrap(); assert_eq!( - resolve_commit_ids_in_workspace( - mut_repo.as_repo_ref(), - "@", - &test_workspace.workspace, - None, - ), + resolve_commit_ids_in_workspace(mut_repo, "@", &test_workspace.workspace, None), vec![commit1.id().clone()] ); } @@ -557,30 +551,24 @@ fn test_evaluate_expression_heads(use_git: bool) { let commit3 = graph_builder.commit_with_parents(&[&commit2]); // Heads of an empty set is an empty set - assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "heads(none())"), - vec![] - ); + assert_eq!(resolve_commit_ids(mut_repo, "heads(none())"), vec![]); // Heads of the root is the root assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "heads(root)"), + resolve_commit_ids(mut_repo, "heads(root)"), vec![root_commit.id().clone()] ); // Heads of a single commit is that commit assert_eq!( - resolve_commit_ids( - mut_repo.as_repo_ref(), - &format!("heads({})", commit2.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("heads({})", commit2.id().hex())), vec![commit2.id().clone()] ); // Heads of a parent and a child is the child assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("heads({} | {})", commit2.id().hex(), commit3.id().hex()) ), vec![commit3.id().clone()] @@ -590,7 +578,7 @@ fn test_evaluate_expression_heads(use_git: bool) { // heads() revset, which would include both) assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("heads({} | {})", commit1.id().hex(), commit3.id().hex()) ), vec![commit3.id().clone()] @@ -598,8 +586,8 @@ fn test_evaluate_expression_heads(use_git: bool) { // Heads of all commits is the set of heads in the repo assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "heads(all())"), - resolve_commit_ids(mut_repo.as_repo_ref(), "heads()") + resolve_commit_ids(mut_repo, "heads(all())"), + resolve_commit_ids(mut_repo, "heads()") ); } @@ -619,30 +607,24 @@ fn test_evaluate_expression_roots(use_git: bool) { let commit3 = graph_builder.commit_with_parents(&[&commit2]); // Roots of an empty set is an empty set - assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "roots(none())"), - vec![] - ); + assert_eq!(resolve_commit_ids(mut_repo, "roots(none())"), vec![]); // Roots of the root is the root assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "roots(root)"), + resolve_commit_ids(mut_repo, "roots(root)"), vec![root_commit.id().clone()] ); // Roots of a single commit is that commit assert_eq!( - resolve_commit_ids( - mut_repo.as_repo_ref(), - &format!("roots({})", commit2.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("roots({})", commit2.id().hex())), vec![commit2.id().clone()] ); // Roots of a parent and a child is the parent assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("roots({} | {})", commit2.id().hex(), commit3.id().hex()) ), vec![commit2.id().clone()] @@ -652,7 +634,7 @@ fn test_evaluate_expression_roots(use_git: bool) { // Mercurial's roots() revset, which would include both) assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("roots({} | {})", commit1.id().hex(), commit3.id().hex()) ), vec![commit1.id().clone()] @@ -660,7 +642,7 @@ fn test_evaluate_expression_roots(use_git: bool) { // Roots of all commits is the root commit assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "roots(all())"), + resolve_commit_ids(mut_repo, "roots(all())"), vec![root_commit.id().clone()] ); } @@ -683,32 +665,27 @@ fn test_evaluate_expression_parents(use_git: bool) { let commit5 = graph_builder.commit_with_parents(&[&commit2]); // The root commit has no parents - assert_eq!(resolve_commit_ids(mut_repo.as_repo_ref(), "root-"), vec![]); + assert_eq!(resolve_commit_ids(mut_repo, "root-"), vec![]); // Can find parents of the current working-copy commit mut_repo .set_wc_commit(WorkspaceId::default(), commit2.id().clone()) .unwrap(); assert_eq!( - resolve_commit_ids_in_workspace( - mut_repo.as_repo_ref(), - "@-", - &test_workspace.workspace, - None, - ), + resolve_commit_ids_in_workspace(mut_repo, "@-", &test_workspace.workspace, None,), vec![commit1.id().clone()] ); // Can find parents of a merge commit assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), &format!("{}-", commit4.id().hex())), + resolve_commit_ids(mut_repo, &format!("{}-", commit4.id().hex())), vec![commit3.id().clone(), commit2.id().clone()] ); // Parents of all commits in input are returned assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("({} | {})-", commit2.id().hex(), commit3.id().hex()) ), vec![commit1.id().clone(), root_commit.id().clone()] @@ -717,7 +694,7 @@ fn test_evaluate_expression_parents(use_git: bool) { // Parents already in input set are returned assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("({} | {})-", commit1.id().hex(), commit2.id().hex()) ), vec![commit1.id().clone(), root_commit.id().clone()] @@ -726,7 +703,7 @@ fn test_evaluate_expression_parents(use_git: bool) { // Parents shared among commits in input are not repeated assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("({} | {})-", commit4.id().hex(), commit5.id().hex()) ), vec![commit3.id().clone(), commit2.id().clone()] @@ -734,19 +711,19 @@ fn test_evaluate_expression_parents(use_git: bool) { // Can find parents of parents, which may be optimized to single query assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), &format!("{}--", commit4.id().hex())), + resolve_commit_ids(mut_repo, &format!("{}--", commit4.id().hex())), vec![commit1.id().clone(), root_commit.id().clone()] ); assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("({} | {})--", commit4.id().hex(), commit5.id().hex()) ), vec![commit1.id().clone(), root_commit.id().clone()] ); assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("({} | {})--", commit4.id().hex(), commit2.id().hex()) ), vec![commit1.id().clone(), root_commit.id().clone()] @@ -783,7 +760,7 @@ fn test_evaluate_expression_children(use_git: bool) { // Can find children of the root commit assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "root+"), + resolve_commit_ids(mut_repo, "root+"), vec![commit1.id().clone()] ); @@ -791,7 +768,7 @@ fn test_evaluate_expression_children(use_git: bool) { // input set assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("({} | {})+", commit1.id().hex(), commit2.id().hex()) ), vec![ @@ -804,7 +781,7 @@ fn test_evaluate_expression_children(use_git: bool) { // Children shared among commits in input are not repeated assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("({} | {})+", commit3.id().hex(), commit4.id().hex()) ), vec![commit5.id().clone()] @@ -829,14 +806,14 @@ fn test_evaluate_expression_ancestors(use_git: bool) { // The ancestors of the root commit is just the root commit itself assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), ":root"), + resolve_commit_ids(mut_repo, ":root"), vec![root_commit.id().clone()] ); // Can find ancestors of a specific commit. Commits reachable via multiple paths // are not repeated. assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), &format!(":{}", commit4.id().hex())), + resolve_commit_ids(mut_repo, &format!(":{}", commit4.id().hex())), vec![ commit4.id().clone(), commit3.id().clone(), @@ -849,10 +826,7 @@ fn test_evaluate_expression_ancestors(use_git: bool) { // Can find ancestors of parents or parents of ancestors, which may be optimized // to single query assert_eq!( - resolve_commit_ids( - mut_repo.as_repo_ref(), - &format!(":({}-)", commit4.id().hex()), - ), + resolve_commit_ids(mut_repo, &format!(":({}-)", commit4.id().hex()),), vec![ commit3.id().clone(), commit2.id().clone(), @@ -862,7 +836,7 @@ fn test_evaluate_expression_ancestors(use_git: bool) { ); assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("(:({}|{}))-", commit3.id().hex(), commit2.id().hex()), ), vec![ @@ -873,7 +847,7 @@ fn test_evaluate_expression_ancestors(use_git: bool) { ); assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!(":(({}|{})-)", commit3.id().hex(), commit2.id().hex()), ), vec![ @@ -901,15 +875,12 @@ fn test_evaluate_expression_range(use_git: bool) { // The range from the root to the root is empty (because the left side of the // range is exclusive) - assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "root..root"), - vec![] - ); + assert_eq!(resolve_commit_ids(mut_repo, "root..root"), vec![]); // Linear range assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("{}..{}", commit1.id().hex(), commit3.id().hex()) ), vec![commit3.id().clone(), commit2.id().clone()] @@ -918,7 +889,7 @@ fn test_evaluate_expression_range(use_git: bool) { // Empty range (descendant first) assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("{}..{}", commit3.id().hex(), commit1.id().hex()) ), vec![] @@ -927,7 +898,7 @@ fn test_evaluate_expression_range(use_git: bool) { // Range including a merge assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("{}..{}", commit1.id().hex(), commit4.id().hex()) ), vec![ @@ -940,7 +911,7 @@ fn test_evaluate_expression_range(use_git: bool) { // Sibling commits assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("{}..{}", commit2.id().hex(), commit3.id().hex()) ), vec![commit3.id().clone()] @@ -966,14 +937,14 @@ fn test_evaluate_expression_dag_range(use_git: bool) { // Can get DAG range of just the root commit assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "root:root"), + resolve_commit_ids(mut_repo, "root:root"), vec![root_commit_id.clone()] ); // Linear range assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("{}:{}", root_commit_id.hex(), commit2.id().hex()) ), vec![commit2.id().clone(), commit1.id().clone(), root_commit_id] @@ -982,7 +953,7 @@ fn test_evaluate_expression_dag_range(use_git: bool) { // Empty range assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("{}:{}", commit2.id().hex(), commit4.id().hex()) ), vec![] @@ -991,7 +962,7 @@ fn test_evaluate_expression_dag_range(use_git: bool) { // Including a merge assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("{}:{}", commit1.id().hex(), commit5.id().hex()) ), vec![ @@ -1006,7 +977,7 @@ fn test_evaluate_expression_dag_range(use_git: bool) { // Including a merge, but ancestors only from one side assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("{}:{}", commit2.id().hex(), commit5.id().hex()) ), vec![ @@ -1035,21 +1006,18 @@ fn test_evaluate_expression_connected(use_git: bool) { let commit5 = graph_builder.commit_with_parents(&[&commit3, &commit4]); // Connecting an empty set yields an empty set - assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "connected(none())"), - vec![] - ); + assert_eq!(resolve_commit_ids(mut_repo, "connected(none())"), vec![]); // Can connect just the root commit assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "connected(root)"), + resolve_commit_ids(mut_repo, "connected(root)"), vec![root_commit_id.clone()] ); // Can connect linearly assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!( "connected({} | {})", root_commit_id.hex(), @@ -1062,7 +1030,7 @@ fn test_evaluate_expression_connected(use_git: bool) { // Siblings don't get connected assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("connected({} | {})", commit2.id().hex(), commit4.id().hex()) ), vec![commit4.id().clone(), commit2.id().clone()] @@ -1071,7 +1039,7 @@ fn test_evaluate_expression_connected(use_git: bool) { // Including a merge assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("connected({} | {})", commit1.id().hex(), commit5.id().hex()) ), vec![ @@ -1086,7 +1054,7 @@ fn test_evaluate_expression_connected(use_git: bool) { // Including a merge, but ancestors only from one side assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("connected({} | {})", commit2.id().hex(), commit5.id().hex()) ), vec![ @@ -1128,7 +1096,7 @@ fn test_evaluate_expression_descendants(use_git: bool) { // The descendants of the root commit are all the commits in the repo assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "root:"), + resolve_commit_ids(mut_repo, "root:"), vec![ commit5.id().clone(), commit4.id().clone(), @@ -1141,7 +1109,7 @@ fn test_evaluate_expression_descendants(use_git: bool) { // Can find descendants of a specific commit assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), &format!("{}:", commit2.id().hex())), + resolve_commit_ids(mut_repo, &format!("{}:", commit2.id().hex())), vec![ commit5.id().clone(), commit3.id().clone(), @@ -1157,7 +1125,7 @@ fn test_evaluate_expression_none(use_git: bool) { let repo = &test_repo.repo; // none() is empty (doesn't include the checkout, for example) - assert_eq!(resolve_commit_ids(repo.as_repo_ref(), "none()"), vec![]); + assert_eq!(resolve_commit_ids(repo, "none()"), vec![]); } #[test_case(false ; "local backend")] @@ -1177,7 +1145,7 @@ fn test_evaluate_expression_all(use_git: bool) { let commit4 = graph_builder.commit_with_parents(&[&commit2, &commit3]); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "all()"), + resolve_commit_ids(mut_repo, "all()"), vec![ commit4.id().clone(), commit3.id().clone(), @@ -1203,7 +1171,7 @@ fn test_evaluate_expression_visible_heads(use_git: bool) { let commit3 = graph_builder.commit_with_parents(&[&commit1]); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "heads()"), + resolve_commit_ids(mut_repo, "heads()"), vec![commit3.id().clone(), commit2.id().clone()] ); } @@ -1224,19 +1192,19 @@ fn test_evaluate_expression_public_heads(use_git: bool) { // Can get public heads with root commit as only public head assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "public_heads()"), + resolve_commit_ids(mut_repo, "public_heads()"), vec![root_commit.id().clone()] ); // Can get public heads with a single public head mut_repo.add_public_head(&commit1); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "public_heads()"), + resolve_commit_ids(mut_repo, "public_heads()"), vec![commit1.id().clone()] ); // Can get public heads with multiple public head mut_repo.add_public_head(&commit2); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "public_heads()"), + resolve_commit_ids(mut_repo, "public_heads()"), vec![commit2.id().clone(), commit1.id().clone()] ); } @@ -1257,10 +1225,7 @@ fn test_evaluate_expression_git_refs(use_git: bool) { let commit4 = write_random_commit(mut_repo, &settings); // Can get git refs when there are none - assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "git_refs()"), - vec![] - ); + assert_eq!(resolve_commit_ids(mut_repo, "git_refs()"), vec![]); // Can get a mix of git refs mut_repo.set_git_ref( "refs/heads/branch1".to_string(), @@ -1271,7 +1236,7 @@ fn test_evaluate_expression_git_refs(use_git: bool) { RefTarget::Normal(commit2.id().clone()), ); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "git_refs()"), + resolve_commit_ids(mut_repo, "git_refs()"), vec![commit2.id().clone(), commit1.id().clone()] ); // Two refs pointing to the same commit does not result in a duplicate in the @@ -1281,7 +1246,7 @@ fn test_evaluate_expression_git_refs(use_git: bool) { RefTarget::Normal(commit2.id().clone()), ); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "git_refs()"), + resolve_commit_ids(mut_repo, "git_refs()"), vec![commit2.id().clone(), commit1.id().clone()] ); // Can get git refs when there are conflicted refs @@ -1301,7 +1266,7 @@ fn test_evaluate_expression_git_refs(use_git: bool) { ); mut_repo.remove_git_ref("refs/tags/tag2"); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "git_refs()"), + resolve_commit_ids(mut_repo, "git_refs()"), vec![ commit4.id().clone(), commit3.id().clone(), @@ -1323,13 +1288,10 @@ fn test_evaluate_expression_git_head(use_git: bool) { let commit1 = write_random_commit(mut_repo, &settings); // Can get git head when it's not set - assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "git_head()"), - vec![] - ); + assert_eq!(resolve_commit_ids(mut_repo, "git_head()"), vec![]); mut_repo.set_git_head(RefTarget::Normal(commit1.id().clone())); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "git_head()"), + resolve_commit_ids(mut_repo, "git_head()"), vec![commit1.id().clone()] ); } @@ -1350,10 +1312,7 @@ fn test_evaluate_expression_branches(use_git: bool) { let commit4 = write_random_commit(mut_repo, &settings); // Can get branches when there are none - assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "branches()"), - vec![] - ); + assert_eq!(resolve_commit_ids(mut_repo, "branches()"), vec![]); // Can get a few branches mut_repo.set_local_branch( "branch1".to_string(), @@ -1364,23 +1323,20 @@ fn test_evaluate_expression_branches(use_git: bool) { RefTarget::Normal(commit2.id().clone()), ); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "branches()"), + resolve_commit_ids(mut_repo, "branches()"), vec![commit2.id().clone(), commit1.id().clone()] ); // Can get branches with matching names assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "branches(branch1)"), + resolve_commit_ids(mut_repo, "branches(branch1)"), vec![commit1.id().clone()] ); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "branches(branch)"), + resolve_commit_ids(mut_repo, "branches(branch)"), vec![commit2.id().clone(), commit1.id().clone()] ); // Can silently resolve to an empty set if there's no matches - assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "branches(branch3)"), - vec![] - ); + assert_eq!(resolve_commit_ids(mut_repo, "branches(branch3)"), vec![]); // Two branches pointing to the same commit does not result in a duplicate in // the revset mut_repo.set_local_branch( @@ -1388,7 +1344,7 @@ fn test_evaluate_expression_branches(use_git: bool) { RefTarget::Normal(commit2.id().clone()), ); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "branches()"), + resolve_commit_ids(mut_repo, "branches()"), vec![commit2.id().clone(), commit1.id().clone()] ); // Can get branches when there are conflicted refs @@ -1408,7 +1364,7 @@ fn test_evaluate_expression_branches(use_git: bool) { ); mut_repo.remove_local_branch("branch3"); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "branches()"), + resolve_commit_ids(mut_repo, "branches()"), vec![ commit4.id().clone(), commit3.id().clone(), @@ -1433,10 +1389,7 @@ fn test_evaluate_expression_remote_branches(use_git: bool) { let commit4 = write_random_commit(mut_repo, &settings); // Can get branches when there are none - assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "remote_branches()"), - vec![] - ); + assert_eq!(resolve_commit_ids(mut_repo, "remote_branches()"), vec![]); // Can get a few branches mut_repo.set_remote_branch( "branch1".to_string(), @@ -1449,53 +1402,47 @@ fn test_evaluate_expression_remote_branches(use_git: bool) { RefTarget::Normal(commit2.id().clone()), ); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "remote_branches()"), + resolve_commit_ids(mut_repo, "remote_branches()"), vec![commit2.id().clone(), commit1.id().clone()] ); // Can get branches with matching names assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "remote_branches(branch1)"), + resolve_commit_ids(mut_repo, "remote_branches(branch1)"), vec![commit1.id().clone()] ); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "remote_branches(branch)"), + resolve_commit_ids(mut_repo, "remote_branches(branch)"), vec![commit2.id().clone(), commit1.id().clone()] ); // Can get branches from matching remotes assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), r#"remote_branches("", origin)"#), + resolve_commit_ids(mut_repo, r#"remote_branches("", origin)"#), vec![commit1.id().clone()] ); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), r#"remote_branches("", ri)"#), + resolve_commit_ids(mut_repo, r#"remote_branches("", ri)"#), vec![commit2.id().clone(), commit1.id().clone()] ); // Can get branches with matching names from matching remotes assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "remote_branches(branch1, ri)"), + resolve_commit_ids(mut_repo, "remote_branches(branch1, ri)"), vec![commit1.id().clone()] ); assert_eq!( - resolve_commit_ids( - mut_repo.as_repo_ref(), - r#"remote_branches(branch, private)"# - ), + resolve_commit_ids(mut_repo, r#"remote_branches(branch, private)"#), vec![commit2.id().clone()] ); // Can silently resolve to an empty set if there's no matches assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "remote_branches(branch3)"), + resolve_commit_ids(mut_repo, "remote_branches(branch3)"), vec![] ); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), r#"remote_branches("", upstream)"#), + resolve_commit_ids(mut_repo, r#"remote_branches("", upstream)"#), vec![] ); assert_eq!( - resolve_commit_ids( - mut_repo.as_repo_ref(), - r#"remote_branches(branch1, private)"# - ), + resolve_commit_ids(mut_repo, r#"remote_branches(branch1, private)"#), vec![] ); // Two branches pointing to the same commit does not result in a duplicate in @@ -1506,13 +1453,13 @@ fn test_evaluate_expression_remote_branches(use_git: bool) { RefTarget::Normal(commit2.id().clone()), ); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "remote_branches()"), + resolve_commit_ids(mut_repo, "remote_branches()"), vec![commit2.id().clone(), commit1.id().clone()] ); // The commits don't have to be in the current set of heads to be included. mut_repo.remove_head(commit2.id()); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "remote_branches()"), + resolve_commit_ids(mut_repo, "remote_branches()"), vec![commit2.id().clone(), commit1.id().clone()] ); // Can get branches when there are conflicted refs @@ -1534,7 +1481,7 @@ fn test_evaluate_expression_remote_branches(use_git: bool) { ); mut_repo.remove_remote_branch("branch3", "origin"); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "remote_branches()"), + resolve_commit_ids(mut_repo, "remote_branches()"), vec![ commit4.id().clone(), commit3.id().clone(), @@ -1561,15 +1508,12 @@ fn test_evaluate_expression_merges(use_git: bool) { // Finds all merges by default assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "merges()"), + resolve_commit_ids(mut_repo, "merges()"), vec![commit5.id().clone(), commit4.id().clone(),] ); // Searches only among candidates if specified assert_eq!( - resolve_commit_ids( - mut_repo.as_repo_ref(), - &format!(":{} & merges()", commit5.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!(":{} & merges()", commit5.id().hex())), vec![commit5.id().clone()] ); } @@ -1601,7 +1545,7 @@ fn test_evaluate_expression_description(use_git: bool) { // Can find multiple matches assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "description(commit)"), + resolve_commit_ids(mut_repo, "description(commit)"), vec![ commit3.id().clone(), commit2.id().clone(), @@ -1610,15 +1554,12 @@ fn test_evaluate_expression_description(use_git: bool) { ); // Can find a unique match assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "description(\"commit 2\")"), + resolve_commit_ids(mut_repo, "description(\"commit 2\")"), vec![commit2.id().clone()] ); // Searches only among candidates if specified assert_eq!( - resolve_commit_ids( - mut_repo.as_repo_ref(), - "heads() & description(\"commit 2\")" - ), + resolve_commit_ids(mut_repo, "heads() & description(\"commit 2\")"), vec![] ); } @@ -1666,7 +1607,7 @@ fn test_evaluate_expression_author(use_git: bool) { // Can find multiple matches assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "author(name)"), + resolve_commit_ids(mut_repo, "author(name)"), vec![ commit3.id().clone(), commit2.id().clone(), @@ -1675,22 +1616,22 @@ fn test_evaluate_expression_author(use_git: bool) { ); // Can find a unique match by either name or email assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "author(\"name2\")"), + resolve_commit_ids(mut_repo, "author(\"name2\")"), vec![commit2.id().clone()] ); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "author(\"name3\")"), + resolve_commit_ids(mut_repo, "author(\"name3\")"), vec![commit3.id().clone()] ); // Searches only among candidates if specified assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "heads() & author(\"name2\")"), + resolve_commit_ids(mut_repo, "heads() & author(\"name2\")"), vec![] ); // Filter by union of pure predicate and set assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("root.. & (author(name1) | {})", commit3.id().hex()) ), vec![commit3.id().clone(), commit1.id().clone()] @@ -1740,7 +1681,7 @@ fn test_evaluate_expression_committer(use_git: bool) { // Can find multiple matches assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "committer(name)"), + resolve_commit_ids(mut_repo, "committer(name)"), vec![ commit3.id().clone(), commit2.id().clone(), @@ -1749,16 +1690,16 @@ fn test_evaluate_expression_committer(use_git: bool) { ); // Can find a unique match by either name or email assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "committer(\"name2\")"), + resolve_commit_ids(mut_repo, "committer(\"name2\")"), vec![commit2.id().clone()] ); assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "committer(\"name3\")"), + resolve_commit_ids(mut_repo, "committer(\"name3\")"), vec![commit3.id().clone()] ); // Searches only among candidates if specified assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), "heads() & committer(\"name2\")"), + resolve_commit_ids(mut_repo, "heads() & committer(\"name2\")"), vec![] ); } @@ -1783,7 +1724,7 @@ fn test_evaluate_expression_union(use_git: bool) { // Union between ancestors assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!(":{} | :{}", commit4.id().hex(), commit5.id().hex()) ), vec![ @@ -1799,7 +1740,7 @@ fn test_evaluate_expression_union(use_git: bool) { // Unioning can add back commits removed by difference assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!( "(:{} ~ :{}) | :{}", commit4.id().hex(), @@ -1820,7 +1761,7 @@ fn test_evaluate_expression_union(use_git: bool) { // Unioning of disjoint sets assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!( "(:{} ~ :{}) | {}", commit4.id().hex(), @@ -1856,7 +1797,7 @@ fn test_evaluate_expression_intersection(use_git: bool) { // Intersection between ancestors assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!(":{} & :{}", commit4.id().hex(), commit5.id().hex()) ), vec![ @@ -1869,7 +1810,7 @@ fn test_evaluate_expression_intersection(use_git: bool) { // Intersection of disjoint sets assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("{} & {}", commit4.id().hex(), commit2.id().hex()) ), vec![] @@ -1895,35 +1836,35 @@ fn test_evaluate_expression_difference(use_git: bool) { // Difference from all assert_eq!( - resolve_commit_ids(mut_repo.as_repo_ref(), &format!("~:{}", commit5.id().hex())), + resolve_commit_ids(mut_repo, &format!("~:{}", commit5.id().hex())), vec![commit4.id().clone(), commit3.id().clone()] ); // Difference between ancestors assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!(":{} ~ :{}", commit4.id().hex(), commit5.id().hex()) ), vec![commit4.id().clone(), commit3.id().clone()] ); assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!(":{} ~ :{}", commit5.id().hex(), commit4.id().hex()) ), vec![commit5.id().clone()] ); assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!("~:{} & :{}", commit4.id().hex(), commit5.id().hex()) ), vec![commit5.id().clone()] ); assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!(":{} ~ :{}", commit4.id().hex(), commit2.id().hex()) ), vec![commit4.id().clone(), commit3.id().clone()] @@ -1932,7 +1873,7 @@ fn test_evaluate_expression_difference(use_git: bool) { // Associativity assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!( ":{} ~ {} ~ {}", commit4.id().hex(), @@ -1950,7 +1891,7 @@ fn test_evaluate_expression_difference(use_git: bool) { // Subtracting a difference does not add back any commits assert_eq!( resolve_commit_ids( - mut_repo.as_repo_ref(), + mut_repo, &format!( "(:{} ~ :{}) ~ (:{} ~ :{})", commit4.id().hex(), @@ -2023,10 +1964,10 @@ fn test_filter_by_diff(use_git: bool) { // matcher API: let resolve = |file_path: &RepoPath| -> Vec { - let repo_ref = mut_repo.as_repo_ref(); + let mut_repo = &*mut_repo; let matcher = FilesMatcher::new(&[file_path.clone()]); - let candidates = RevsetExpression::all().evaluate(repo_ref, None).unwrap(); - let commit_ids = revset::filter_by_diff(repo_ref, &matcher as &dyn Matcher, candidates) + let candidates = RevsetExpression::all().evaluate(mut_repo, None).unwrap(); + let commit_ids = revset::filter_by_diff(mut_repo, &matcher as &dyn Matcher, candidates) .iter() .commit_ids() .collect(); @@ -2050,7 +1991,7 @@ fn test_filter_by_diff(use_git: bool) { // file() revset: assert_eq!( resolve_commit_ids_in_workspace( - mut_repo.as_repo_ref(), + mut_repo, r#"file("repo/added_clean_clean")"#, &test_workspace.workspace, Some(test_workspace.workspace.workspace_root().parent().unwrap()), @@ -2059,7 +2000,7 @@ fn test_filter_by_diff(use_git: bool) { ); assert_eq!( resolve_commit_ids_in_workspace( - mut_repo.as_repo_ref(), + mut_repo, &format!(r#"{}: & file("added_modified_clean")"#, commit2.id().hex()), &test_workspace.workspace, Some(test_workspace.workspace.workspace_root()), @@ -2069,10 +2010,7 @@ fn test_filter_by_diff(use_git: bool) { // empty() revset, which is identical to ~file(".") assert_eq!( - resolve_commit_ids( - mut_repo.as_repo_ref(), - &format!("{}: & empty()", commit1.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("{}: & empty()", commit1.id().hex())), vec![commit4.id().clone()] ); } diff --git a/lib/tests/test_revset_graph_iterator.rs b/lib/tests/test_revset_graph_iterator.rs index 761317564..3cbe71fb5 100644 --- a/lib/tests/test_revset_graph_iterator.rs +++ b/lib/tests/test_revset_graph_iterator.rs @@ -48,7 +48,7 @@ fn test_graph_iterator_linearized(skip_transitive_edges: bool) { .unwrap(); let pos_a = repo.index().commit_id_to_pos(commit_a.id()).unwrap(); - let revset = revset_for_commits(repo.as_repo_ref(), &[&commit_a, &commit_d]); + let revset = revset_for_commits(&repo, &[&commit_a, &commit_d]); let commits = revset .iter() .graph() @@ -96,10 +96,7 @@ fn test_graph_iterator_virtual_octopus(skip_transitive_edges: bool) { let pos_b = repo.index().commit_id_to_pos(commit_b.id()).unwrap(); let pos_c = repo.index().commit_id_to_pos(commit_c.id()).unwrap(); - let revset = revset_for_commits( - repo.as_repo_ref(), - &[&commit_a, &commit_b, &commit_c, &commit_f], - ); + let revset = revset_for_commits(&repo, &[&commit_a, &commit_b, &commit_c, &commit_f]); let commits = revset .iter() .graph() @@ -156,7 +153,7 @@ fn test_graph_iterator_simple_fork(skip_transitive_edges: bool) { .unwrap(); let pos_a = repo.index().commit_id_to_pos(commit_a.id()).unwrap(); - let revset = revset_for_commits(repo.as_repo_ref(), &[&commit_a, &commit_c, &commit_e]); + let revset = revset_for_commits(&repo, &[&commit_a, &commit_c, &commit_e]); let commits = revset .iter() .graph() @@ -205,7 +202,7 @@ fn test_graph_iterator_multiple_missing(skip_transitive_edges: bool) { let pos_b = repo.index().commit_id_to_pos(commit_b.id()).unwrap(); let pos_c = repo.index().commit_id_to_pos(commit_c.id()).unwrap(); - let revset = revset_for_commits(repo.as_repo_ref(), &[&commit_b, &commit_f]); + let revset = revset_for_commits(&repo, &[&commit_b, &commit_f]); let commits = revset .iter() .graph() @@ -259,7 +256,7 @@ fn test_graph_iterator_edge_to_ancestor(skip_transitive_edges: bool) { let pos_c = repo.index().commit_id_to_pos(commit_c.id()).unwrap(); let pos_d = repo.index().commit_id_to_pos(commit_d.id()).unwrap(); - let revset = revset_for_commits(repo.as_repo_ref(), &[&commit_c, &commit_d, &commit_f]); + let revset = revset_for_commits(&repo, &[&commit_c, &commit_d, &commit_f]); let commits = revset .iter() .graph() @@ -337,7 +334,7 @@ fn test_graph_iterator_edge_escapes_from_(skip_transitive_edges: bool) { let pos_h = repo.index().commit_id_to_pos(commit_h.id()).unwrap(); let revset = revset_for_commits( - repo.as_repo_ref(), + &repo, &[&commit_a, &commit_d, &commit_g, &commit_h, &commit_j], ); let commits = revset @@ -420,7 +417,7 @@ fn test_reverse_graph_iterator() { let pos_f = repo.index().commit_id_to_pos(commit_f.id()).unwrap(); let revset = revset_for_commits( - repo.as_repo_ref(), + &repo, &[&commit_a, &commit_c, &commit_d, &commit_e, &commit_f], ); let commits = revset.iter().graph().reversed().collect_vec(); diff --git a/src/cli_util.rs b/src/cli_util.rs index 9e10b506a..b61900c0a 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -38,7 +38,7 @@ use jujutsu_lib::op_heads_store::{self, OpHeadResolutionError, OpHeadsStore}; use jujutsu_lib::op_store::{OpStore, OpStoreError, OperationId, RefTarget, WorkspaceId}; use jujutsu_lib::operation::Operation; use jujutsu_lib::repo::{ - CheckOutCommitError, EditCommitError, MutableRepo, ReadonlyRepo, Repo, RepoLoader, RepoRef, + CheckOutCommitError, EditCommitError, MutableRepo, ReadonlyRepo, Repo, RepoLoader, RewriteRootCommit, StoreFactories, }; use jujutsu_lib::repo_path::{FsPathParseError, RepoPath}; @@ -487,7 +487,7 @@ impl WorkspaceCommandHelper { // operation. // TODO: Parsed template can be cached if it doesn't capture repo parse_commit_summary_template( - repo.as_repo_ref(), + &repo, workspace.workspace_id(), &template_aliases_map, &settings, @@ -799,7 +799,7 @@ impl WorkspaceCommandHelper { &'repo self, revset_expression: &RevsetExpression, ) -> Result + 'repo>, RevsetError> { - revset_expression.evaluate(self.repo.as_repo_ref(), Some(&self.revset_context())) + revset_expression.evaluate(&self.repo, Some(&self.revset_context())) } fn revset_context(&self) -> RevsetWorkspaceContext { @@ -815,7 +815,7 @@ impl WorkspaceCommandHelper { template_text: &str, ) -> Result + '_>, TemplateParseError> { template_parser::parse_commit_template( - self.repo.as_repo_ref(), + &self.repo, self.workspace_id(), template_text, &self.template_aliases_map, @@ -837,7 +837,7 @@ impl WorkspaceCommandHelper { commit: &Commit, ) -> std::io::Result<()> { let template = parse_commit_summary_template( - self.repo.as_repo_ref(), + &self.repo, self.workspace_id(), &self.template_aliases_map, &self.settings, @@ -971,7 +971,7 @@ impl WorkspaceCommandHelper { if self.may_update_working_copy { let workspace_id = self.workspace_id().to_owned(); let summary_template = parse_commit_summary_template( - self.repo.as_repo_ref(), + &self.repo, &workspace_id, &self.template_aliases_map, &self.settings, @@ -1122,7 +1122,7 @@ impl WorkspaceCommandTransaction<'_> { commit: &Commit, ) -> std::io::Result<()> { let template = parse_commit_summary_template( - self.tx.repo().as_repo_ref(), + self.tx.repo(), self.helper.workspace_id(), &self.helper.template_aliases_map, &self.helper.settings, @@ -1557,7 +1557,7 @@ fn load_template_aliases( } fn parse_commit_summary_template<'a>( - repo: RepoRef<'a>, + repo: &'a dyn Repo, workspace_id: &WorkspaceId, aliases_map: &TemplateAliasesMap, settings: &UserSettings, diff --git a/src/commands/branch.rs b/src/commands/branch.rs index d6bb03376..d4b64ffd1 100644 --- a/src/commands/branch.rs +++ b/src/commands/branch.rs @@ -4,7 +4,7 @@ use clap::builder::NonEmptyStringValueParser; use itertools::Itertools; use jujutsu_lib::backend::{CommitId, ObjectId}; use jujutsu_lib::op_store::RefTarget; -use jujutsu_lib::repo::{Repo, RepoRef}; +use jujutsu_lib::repo::Repo; use jujutsu_lib::view::View; use crate::cli_util::{user_error, user_error_with_hint, CommandError, CommandHelper, RevisionArg}; @@ -170,11 +170,7 @@ fn cmd_branch_set( workspace_command.resolve_single_rev(args.revision.as_deref().unwrap_or("@"))?; if !args.allow_backwards && !branch_names.iter().all(|branch_name| { - is_fast_forward( - workspace_command.repo().as_repo_ref(), - branch_name, - target_commit.id(), - ) + is_fast_forward(workspace_command.repo(), branch_name, target_commit.id()) }) { return Err(user_error_with_hint( @@ -340,7 +336,7 @@ fn validate_branch_names_exist(view: &View, names: &[String]) -> Result<(), Comm Ok(()) } -fn is_fast_forward(repo: RepoRef, branch_name: &str, new_target_id: &CommitId) -> bool { +fn is_fast_forward(repo: &dyn Repo, branch_name: &str, new_target_id: &CommitId) -> bool { if let Some(current_target) = repo.view().get_local_branch(branch_name) { current_target .adds() diff --git a/src/commands/git.rs b/src/commands/git.rs index 0b65f09be..2f7419b41 100644 --- a/src/commands/git.rs +++ b/src/commands/git.rs @@ -12,7 +12,7 @@ use jujutsu_lib::backend::ObjectId; use jujutsu_lib::git::{self, GitFetchError, GitRefUpdate}; use jujutsu_lib::op_store::{BranchTarget, RefTarget}; use jujutsu_lib::refs::{classify_branch_push_action, BranchPushAction, BranchPushUpdate}; -use jujutsu_lib::repo::{Repo, RepoRef}; +use jujutsu_lib::repo::Repo; use jujutsu_lib::settings::UserSettings; use jujutsu_lib::store::Store; use jujutsu_lib::view::View; @@ -547,11 +547,9 @@ fn cmd_git_push( if !seen_branches.insert(branch_name.clone()) { continue; } - if let Some(update) = branch_updates_for_push( - workspace_command.repo().as_repo_ref(), - &remote, - branch_name, - )? { + if let Some(update) = + branch_updates_for_push(workspace_command.repo(), &remote, branch_name)? + { branch_updates.push((branch_name.clone(), update)); } else { writeln!( @@ -620,9 +618,7 @@ fn cmd_git_push( } tx.mut_repo() .set_local_branch(branch_name.clone(), RefTarget::Normal(commit.id().clone())); - if let Some(update) = - branch_updates_for_push(tx.mut_repo().as_repo_ref(), &remote, &branch_name)? - { + if let Some(update) = branch_updates_for_push(tx.mut_repo(), &remote, &branch_name)? { branch_updates.push((branch_name.clone(), update)); } else { writeln!( @@ -822,7 +818,7 @@ fn cmd_git_push( } fn branch_updates_for_push( - repo: RepoRef, + repo: &dyn Repo, remote_name: &str, branch_name: &str, ) -> Result, CommandError> { diff --git a/src/commands/mod.rs b/src/commands/mod.rs index b7dd85cd2..3b4ae90f4 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1260,7 +1260,7 @@ fn cmd_diff(ui: &mut Ui, command: &CommandHelper, args: &DiffArgs) -> Result<(), let commit = workspace_command.resolve_single_rev(args.revision.as_deref().unwrap_or("@"))?; let parents = commit.parents(); - from_tree = merge_commit_trees(workspace_command.repo().as_repo_ref(), &parents); + from_tree = merge_commit_trees(workspace_command.repo(), &parents); to_tree = commit.tree() } let matcher = workspace_command.matcher_from_values(&args.paths)?; @@ -1371,7 +1371,7 @@ fn cmd_status( } if let Some(wc_commit) = &maybe_wc_commit { - let parent_tree = merge_commit_trees(repo.as_repo_ref(), &wc_commit.parents()); + let parent_tree = merge_commit_trees(repo, &wc_commit.parents()); let tree = wc_commit.tree(); if tree.id() == parent_tree.id() { formatter.write_str("The working copy is clean\n")?; @@ -1409,7 +1409,7 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C let matcher = workspace_command.matcher_from_values(&args.paths)?; let revset = workspace_command.evaluate_revset(&revset_expression)?; let revset = if !args.paths.is_empty() { - revset::filter_by_diff(repo.as_repo_ref(), matcher.as_ref(), revset) + revset::filter_by_diff(repo, matcher.as_ref(), revset) } else { revset }; @@ -1667,12 +1667,9 @@ fn rebase_to_dest_parent( if source.parent_ids() == destination.parent_ids() { Ok(source.tree()) } else { - let destination_parent_tree = merge_commit_trees( - workspace_command.repo().as_repo_ref(), - &destination.parents(), - ); - let source_parent_tree = - merge_commit_trees(workspace_command.repo().as_repo_ref(), &source.parents()); + let destination_parent_tree = + merge_commit_trees(workspace_command.repo(), &destination.parents()); + let source_parent_tree = merge_commit_trees(workspace_command.repo(), &source.parents()); let rebased_tree_id = merge_trees( &destination_parent_tree, &source_parent_tree, @@ -2003,7 +2000,7 @@ fn cmd_new(ui: &mut Ui, command: &CommandHelper, args: &NewArgs) -> Result<(), C if new_parents_commits.len() > 1 { new_parents_commits.retain(|c| c != &root_commit); } - let merged_tree = merge_commit_trees(tx.base_repo().as_repo_ref(), &new_parents_commits); + let merged_tree = merge_commit_trees(tx.base_repo(), &new_parents_commits); let new_parents_commit_id = new_parents_commits.iter().map(|c| c.id().clone()).collect(); new_commit = tx .mut_repo() @@ -2024,7 +2021,7 @@ fn cmd_new(ui: &mut Ui, command: &CommandHelper, args: &NewArgs) -> Result<(), C )?; } } else { - let merged_tree = merge_commit_trees(tx.base_repo().as_repo_ref(), &target_commits); + let merged_tree = merge_commit_trees(tx.base_repo(), &target_commits); new_commit = tx .mut_repo() .new_commit( @@ -2118,7 +2115,7 @@ fn cmd_move(ui: &mut Ui, command: &CommandHelper, args: &MoveArgs) -> Result<(), source.id().hex(), destination.id().hex() )); - let parent_tree = merge_commit_trees(tx.base_repo().as_repo_ref(), &source.parents()); + let parent_tree = merge_commit_trees(tx.base_repo(), &source.parents()); let source_tree = source.tree(); let instructions = format!( "\ @@ -2280,7 +2277,7 @@ fn cmd_unsquash( workspace_command.check_rewritable(parent)?; let mut tx = workspace_command.start_transaction(&format!("unsquash commit {}", commit.id().hex())); - let parent_base_tree = merge_commit_trees(tx.base_repo().as_repo_ref(), &parent.parents()); + let parent_base_tree = merge_commit_trees(tx.base_repo(), &parent.parents()); let new_parent_tree_id; if args.interactive { let instructions = format!( @@ -2576,7 +2573,7 @@ Adjust the right side until it shows the contents you want. If you don't make any changes, then the operation will be aborted.", tx.format_commit_summary(&target_commit), ); - let base_tree = merge_commit_trees(tx.base_repo().as_repo_ref(), base_commits.as_slice()); + let base_tree = merge_commit_trees(tx.base_repo(), base_commits.as_slice()); let tree_id = tx.edit_diff(ui, &base_tree, &target_commit.tree(), &instructions)?; if &tree_id == target_commit.tree_id() { ui.write("Nothing changed.\n")?; @@ -2651,7 +2648,7 @@ fn cmd_split(ui: &mut Ui, command: &CommandHelper, args: &SplitArgs) -> Result<( let matcher = workspace_command.matcher_from_values(&args.paths)?; let mut tx = workspace_command.start_transaction(&format!("split commit {}", commit.id().hex())); - let base_tree = merge_commit_trees(tx.base_repo().as_repo_ref(), &commit.parents()); + let base_tree = merge_commit_trees(tx.base_repo(), &commit.parents()); let interactive = args.paths.is_empty(); let instructions = format!( "\ diff --git a/src/diff_util.rs b/src/diff_util.rs index ee8167886..ae94df395 100644 --- a/src/diff_util.rs +++ b/src/diff_util.rs @@ -137,7 +137,7 @@ pub fn show_patch( formats: &[DiffFormat], ) -> Result<(), CommandError> { let parents = commit.parents(); - let from_tree = rewrite::merge_commit_trees(workspace_command.repo().as_repo_ref(), &parents); + let from_tree = rewrite::merge_commit_trees(workspace_command.repo(), &parents); let to_tree = commit.tree(); show_diff( formatter, diff --git a/src/template_parser.rs b/src/template_parser.rs index 403440dba..235dcacae 100644 --- a/src/template_parser.rs +++ b/src/template_parser.rs @@ -21,7 +21,7 @@ use itertools::Itertools as _; use jujutsu_lib::backend::{Signature, Timestamp}; use jujutsu_lib::commit::Commit; use jujutsu_lib::op_store::WorkspaceId; -use jujutsu_lib::repo::RepoRef; +use jujutsu_lib::repo::Repo; use jujutsu_lib::rewrite; use pest::iterators::{Pair, Pairs}; use pest::Parser; @@ -1030,7 +1030,7 @@ fn build_global_function<'a, C: 'a>( } fn build_commit_keyword<'a>( - repo: RepoRef<'a>, + repo: &'a dyn Repo, workspace_id: &WorkspaceId, name: &str, span: pest::Span, @@ -1112,7 +1112,7 @@ fn build_expression<'a, C: 'a>( // TODO: We'll probably need a trait that abstracts the Property enum and // keyword/method parsing functions per the top-level context. pub fn parse_commit_template<'a>( - repo: RepoRef<'a>, + repo: &'a dyn Repo, workspace_id: &WorkspaceId, template_text: &str, aliases_map: &TemplateAliasesMap, diff --git a/src/templater.rs b/src/templater.rs index f2e9100df..ca44d3d6d 100644 --- a/src/templater.rs +++ b/src/templater.rs @@ -19,7 +19,7 @@ use itertools::Itertools; use jujutsu_lib::backend::{ChangeId, CommitId, ObjectId, Signature, Timestamp}; use jujutsu_lib::commit::Commit; use jujutsu_lib::hex_util::to_reverse_hex; -use jujutsu_lib::repo::RepoRef; +use jujutsu_lib::repo::Repo; use crate::formatter::{Formatter, PlainTextFormatter}; use crate::time_util; @@ -329,7 +329,7 @@ impl> TemplateProperty for PlainTextFormattedProperty { } pub struct WorkingCopiesProperty<'a> { - pub repo: RepoRef<'a>, + pub repo: &'a dyn Repo, } impl TemplateProperty for WorkingCopiesProperty<'_> { @@ -351,7 +351,7 @@ impl TemplateProperty for WorkingCopiesProperty<'_> { } pub struct BranchProperty<'a> { - pub repo: RepoRef<'a>, + pub repo: &'a dyn Repo, } impl TemplateProperty for BranchProperty<'_> { @@ -391,7 +391,7 @@ impl TemplateProperty for BranchProperty<'_> { } pub struct TagProperty<'a> { - pub repo: RepoRef<'a>, + pub repo: &'a dyn Repo, } impl TemplateProperty for TagProperty<'_> { @@ -413,7 +413,7 @@ impl TemplateProperty for TagProperty<'_> { } pub struct GitRefsProperty<'a> { - pub repo: RepoRef<'a>, + pub repo: &'a dyn Repo, } impl TemplateProperty for GitRefsProperty<'_> { @@ -437,11 +437,11 @@ impl TemplateProperty for GitRefsProperty<'_> { } pub struct GitHeadProperty<'a> { - repo: RepoRef<'a>, + repo: &'a dyn Repo, } impl<'a> GitHeadProperty<'a> { - pub fn new(repo: RepoRef<'a>) -> Self { + pub fn new(repo: &'a dyn Repo) -> Self { Self { repo } } } @@ -542,13 +542,13 @@ where /// Type-erased `CommitId`/`ChangeId`. #[derive(Clone)] pub struct CommitOrChangeId<'a> { - repo: RepoRef<'a>, + repo: &'a dyn Repo, id_bytes: Vec, is_commit_id: bool, } impl<'a> CommitOrChangeId<'a> { - pub fn commit_id(repo: RepoRef<'a>, id: &CommitId) -> Self { + pub fn commit_id(repo: &'a dyn Repo, id: &CommitId) -> Self { CommitOrChangeId { repo, id_bytes: id.to_bytes(), @@ -556,7 +556,7 @@ impl<'a> CommitOrChangeId<'a> { } } - pub fn change_id(repo: RepoRef<'a>, id: &ChangeId) -> Self { + pub fn change_id(repo: &'a dyn Repo, id: &ChangeId) -> Self { CommitOrChangeId { repo, id_bytes: id.to_bytes(),