Skip to content

Commit

Permalink
templater: cache list of all remote branches, filter them when requested
Browse files Browse the repository at this point in the history
New local/remote_branches keywords will be implemented on top.
  • Loading branch information
yuja committed Oct 28, 2023
1 parent 817ca7f commit 5486d72
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions cli/src/commit_templater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" => {
Expand Down Expand Up @@ -379,7 +384,8 @@ struct RefName {
remote: Option<String>,
/// 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,
}

Expand Down Expand Up @@ -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(),
Expand All @@ -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);
}
Expand Down

0 comments on commit 5486d72

Please sign in to comment.