From 5ed070a78a00faf34303ac835ec593e6449b37fa Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 13 Jul 2023 00:21:26 +0900 Subject: [PATCH] view: use get_git_ref(name) where extra .clone() wouldn't matter Perhaps, all view.get_(name) functions can return reference, but I'm not willing to change the interface at this point. I'll revisit this after migrating Option to new Conflict-based type. --- lib/src/view.rs | 2 +- lib/tests/test_git.rs | 37 +++++++++++++++++-------------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/lib/src/view.rs b/lib/src/view.rs index 9600ad830..d4b7d7c8b 100644 --- a/lib/src/view.rs +++ b/lib/src/view.rs @@ -131,7 +131,7 @@ impl View { RefName::LocalBranch(name) => self.get_local_branch(name), RefName::RemoteBranch { branch, remote } => self.get_remote_branch(branch, remote), RefName::Tag(name) => self.get_tag(name), - RefName::GitRef(name) => self.git_refs().get(name).cloned(), + RefName::GitRef(name) => self.get_git_ref(name), } } diff --git a/lib/tests/test_git.rs b/lib/tests/test_git.rs index ae98690a4..6aacc40d7 100644 --- a/lib/tests/test_git.rs +++ b/lib/tests/test_git.rs @@ -152,28 +152,28 @@ fn test_import_refs() { assert_eq!(view.git_refs().len(), 6); assert_eq!( - view.git_refs().get("refs/heads/main"), - Some(RefTarget::Normal(jj_id(&commit2))).as_ref() + view.get_git_ref("refs/heads/main"), + Some(RefTarget::Normal(jj_id(&commit2))) ); assert_eq!( - view.git_refs().get("refs/heads/feature1"), - Some(RefTarget::Normal(jj_id(&commit3))).as_ref() + view.get_git_ref("refs/heads/feature1"), + Some(RefTarget::Normal(jj_id(&commit3))) ); assert_eq!( - view.git_refs().get("refs/heads/feature2"), - Some(RefTarget::Normal(jj_id(&commit4))).as_ref() + view.get_git_ref("refs/heads/feature2"), + Some(RefTarget::Normal(jj_id(&commit4))) ); assert_eq!( - view.git_refs().get("refs/remotes/origin/main"), - Some(RefTarget::Normal(jj_id(&commit1))).as_ref() + view.get_git_ref("refs/remotes/origin/main"), + Some(RefTarget::Normal(jj_id(&commit1))) ); assert_eq!( - view.git_refs().get("refs/remotes/origin/feature3"), - Some(RefTarget::Normal(jj_id(&commit6))).as_ref() + view.get_git_ref("refs/remotes/origin/feature3"), + Some(RefTarget::Normal(jj_id(&commit6))) ); assert_eq!( - view.git_refs().get("refs/tags/v1.0"), - Some(RefTarget::Normal(jj_id(&commit5))).as_ref() + view.get_git_ref("refs/tags/v1.0"), + Some(RefTarget::Normal(jj_id(&commit5))) ); assert_eq!(view.git_head(), Some(&RefTarget::Normal(jj_id(&commit2)))); } @@ -263,18 +263,15 @@ fn test_import_refs_reimport() { assert!(view.tags().is_empty()); assert_eq!(view.git_refs().len(), 3); + assert_eq!(view.get_git_ref("refs/heads/main"), Some(commit2_target)); assert_eq!( - view.git_refs().get("refs/heads/main"), - Some(commit2_target).as_ref() - ); - assert_eq!( - view.git_refs().get("refs/remotes/origin/main"), - Some(commit1_target).as_ref() + view.get_git_ref("refs/remotes/origin/main"), + Some(commit1_target) ); let commit5_target = RefTarget::Normal(jj_id(&commit5)); assert_eq!( - view.git_refs().get("refs/heads/feature2"), - Some(commit5_target).as_ref() + view.get_git_ref("refs/heads/feature2"), + Some(commit5_target) ); }