From cb0964b1d077571303a3aac79cb01edd12f1f6b7 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Tue, 30 Apr 2024 14:04:03 +0900 Subject: [PATCH] templater: extract remote-only RefName constructor as well I'm going to make these constructors return Rc, and it seems better to consolidate Rc wrapping functions. --- cli/src/commit_templater.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/cli/src/commit_templater.rs b/cli/src/commit_templater.rs index 80bb8baf4..e74b83a1d 100644 --- a/cli/src/commit_templater.rs +++ b/cli/src/commit_templater.rs @@ -775,6 +775,20 @@ impl RefName { } } + /// Creates remote ref representation which isn't tracked by a local ref. + pub fn remote_only( + name: impl Into, + remote_name: impl Into, + target: RefTarget, + ) -> Self { + RefName { + name: name.into(), + remote: Some(remote_name.into()), + target, + synced: false, // has no local counterpart + } + } + fn is_local(&self) -> bool { self.remote.is_none() } @@ -950,14 +964,10 @@ fn build_ref_names_index<'a>( fn extract_git_head(repo: &dyn Repo, commit: &Commit) -> Option { let target = repo.view().git_head(); - target.added_ids().contains(commit.id()).then(|| { - RefName { - name: "HEAD".to_owned(), - remote: Some(git::REMOTE_NAME_FOR_LOCAL_GIT_REPO.to_owned()), - target: target.clone(), - synced: false, // has no local counterpart - } - }) + target + .added_ids() + .contains(commit.id()) + .then(|| RefName::remote_only("HEAD", git::REMOTE_NAME_FOR_LOCAL_GIT_REPO, target.clone())) } #[derive(Clone, Debug, Eq, PartialEq)]