@@ -51,9 +51,11 @@ use jj_lib::merge::Diff;
5151use jj_lib:: merge:: MergedTreeValue ;
5252use jj_lib:: merged_tree:: MergedTree ;
5353use jj_lib:: object_id:: ObjectId as _;
54+ use jj_lib:: op_store:: LocalRemoteRefTarget ;
5455use jj_lib:: op_store:: OperationId ;
5556use jj_lib:: op_store:: RefTarget ;
5657use jj_lib:: op_store:: RemoteRef ;
58+ use jj_lib:: ref_name:: RefName ;
5759use jj_lib:: ref_name:: WorkspaceName ;
5860use jj_lib:: ref_name:: WorkspaceNameBuf ;
5961use jj_lib:: repo:: Repo ;
@@ -920,12 +922,12 @@ pub struct CommitKeywordCache<'repo> {
920922impl < ' repo > CommitKeywordCache < ' repo > {
921923 pub fn bookmarks_index ( & self , repo : & dyn Repo ) -> & Rc < CommitRefsIndex > {
922924 self . bookmarks_index
923- . get_or_init ( || Rc :: new ( build_bookmarks_index ( repo) ) )
925+ . get_or_init ( || Rc :: new ( build_local_remote_refs_index ( repo. view ( ) . bookmarks ( ) ) ) )
924926 }
925927
926928 pub fn tags_index ( & self , repo : & dyn Repo ) -> & Rc < CommitRefsIndex > {
927929 self . tags_index
928- . get_or_init ( || Rc :: new ( build_commit_refs_index ( repo. view ( ) . local_tags ( ) ) ) )
930+ . get_or_init ( || Rc :: new ( build_local_remote_refs_index ( repo. view ( ) . tags ( ) ) ) )
929931 }
930932
931933 pub fn git_refs_index ( & self , repo : & dyn Repo ) -> & Rc < CommitRefsIndex > {
@@ -1058,14 +1060,8 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm
10581060 . keyword_cache
10591061 . bookmarks_index ( language. repo )
10601062 . clone ( ) ;
1061- let out_property = self_property. map ( move |commit| {
1062- index
1063- . get ( commit. id ( ) )
1064- . iter ( )
1065- . filter ( |commit_ref| commit_ref. is_local ( ) || !commit_ref. synced )
1066- . cloned ( )
1067- . collect_vec ( )
1068- } ) ;
1063+ let out_property =
1064+ self_property. map ( move |commit| collect_distinct_refs ( index. get ( commit. id ( ) ) ) ) ;
10691065 Ok ( out_property. into_dyn_wrapped ( ) )
10701066 } ,
10711067 ) ;
@@ -1112,7 +1108,8 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm
11121108 |language, _diagnostics, _build_ctx, self_property, function| {
11131109 function. expect_no_arguments ( ) ?;
11141110 let index = language. keyword_cache . tags_index ( language. repo ) . clone ( ) ;
1115- let out_property = self_property. map ( move |commit| index. get ( commit. id ( ) ) . to_vec ( ) ) ;
1111+ let out_property =
1112+ self_property. map ( move |commit| collect_distinct_refs ( index. get ( commit. id ( ) ) ) ) ;
11161113 Ok ( out_property. into_dyn_wrapped ( ) )
11171114 } ,
11181115 ) ;
@@ -1784,22 +1781,23 @@ impl CommitRefsIndex {
17841781 }
17851782}
17861783
1787- fn build_bookmarks_index ( repo : & dyn Repo ) -> CommitRefsIndex {
1784+ fn build_local_remote_refs_index < ' a > (
1785+ local_remote_refs : impl IntoIterator < Item = ( & ' a RefName , LocalRemoteRefTarget < ' a > ) > ,
1786+ ) -> CommitRefsIndex {
17881787 let mut index = CommitRefsIndex :: default ( ) ;
1789- for ( bookmark_name , bookmark_target ) in repo . view ( ) . bookmarks ( ) {
1790- let local_target = bookmark_target . local_target ;
1791- let remote_refs = bookmark_target . remote_refs ;
1788+ for ( name , target ) in local_remote_refs {
1789+ let local_target = target . local_target ;
1790+ let remote_refs = target . remote_refs ;
17921791 if local_target. is_present ( ) {
17931792 let commit_ref = CommitRef :: local (
1794- bookmark_name ,
1793+ name ,
17951794 local_target. clone ( ) ,
17961795 remote_refs. iter ( ) . map ( |& ( _, remote_ref) | remote_ref) ,
17971796 ) ;
17981797 index. insert ( local_target. added_ids ( ) , commit_ref) ;
17991798 }
18001799 for & ( remote_name, remote_ref) in & remote_refs {
1801- let commit_ref =
1802- CommitRef :: remote ( bookmark_name, remote_name, remote_ref. clone ( ) , local_target) ;
1800+ let commit_ref = CommitRef :: remote ( name, remote_name, remote_ref. clone ( ) , local_target) ;
18031801 index. insert ( remote_ref. target . added_ids ( ) , commit_ref) ;
18041802 }
18051803 }
@@ -1817,6 +1815,14 @@ fn build_commit_refs_index<'a, K: Into<String>>(
18171815 index
18181816}
18191817
1818+ fn collect_distinct_refs ( commit_refs : & [ Rc < CommitRef > ] ) -> Vec < Rc < CommitRef > > {
1819+ commit_refs
1820+ . iter ( )
1821+ . filter ( |commit_ref| commit_ref. is_local ( ) || !commit_ref. synced )
1822+ . cloned ( )
1823+ . collect ( )
1824+ }
1825+
18201826/// Wrapper to render ref/remote name in revset syntax.
18211827#[ derive( Clone , Debug , Eq , PartialEq , serde:: Serialize ) ]
18221828#[ serde( transparent) ]
0 commit comments