From 5486d72f99469347f5b0a865e2452b87f5b904b7 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Wed, 25 Oct 2023 17:30:49 +0900 Subject: [PATCH] templater: cache list of all remote branches, filter them when requested New local/remote_branches keywords will be implemented on top. --- cli/src/commit_templater.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cli/src/commit_templater.rs b/cli/src/commit_templater.rs index 1d4009d23c..de637d755f 100644 --- a/cli/src/commit_templater.rs +++ b/cli/src/commit_templater.rs @@ -312,7 +312,12 @@ fn build_commit_keyword_opt<'repo>( "branches" => { let index = cache.branches_index(repo).clone(); language.wrap_ref_name_list(wrap_fn(property, move |commit| { - index.get(commit.id()).to_vec() + index + .get(commit.id()) + .iter() + .filter(|ref_name| ref_name.is_local() || !ref_name.synced) + .cloned() + .collect() })) } "tags" => { @@ -379,7 +384,8 @@ struct RefName { remote: Option, /// Ref target has conflicts. conflict: bool, - /// Local ref is synchronized with all tracking remotes. + /// Local ref is synchronized with all tracking remotes, or tracking remote + /// ref is synchronized with the local. synced: bool, } @@ -466,9 +472,6 @@ fn build_branches_index(repo: &dyn Repo) -> RefNamesIndex { for (branch_name, branch_target) in repo.view().branches() { let local_target = branch_target.local_target; let remote_refs = branch_target.remote_refs; - let unsynced_remote_refs = remote_refs.iter().copied().filter(|&(_, remote_ref)| { - !remote_ref.is_tracking() || remote_ref.target != *local_target - }); if local_target.is_present() { let ref_name = RefName { name: branch_name.to_owned(), @@ -480,12 +483,12 @@ fn build_branches_index(repo: &dyn Repo) -> RefNamesIndex { }; index.insert(local_target.added_ids(), ref_name); } - for (remote_name, remote_ref) in unsynced_remote_refs { + for &(remote_name, remote_ref) in &remote_refs { let ref_name = RefName { name: branch_name.to_owned(), remote: Some(remote_name.to_owned()), conflict: remote_ref.target.has_conflict(), - synced: false, + synced: remote_ref.is_tracking() && remote_ref.target == *local_target, }; index.insert(remote_ref.target.added_ids(), ref_name); }