@@ -71,22 +71,37 @@ pub mod describe {
71
71
repo : & Repository ,
72
72
) -> Result < git_revision:: hash_hasher:: HashedMap < ObjectId , Cow < ' static , BStr > > , Error > {
73
73
let platform = repo. references ( ) ?;
74
- let into_tuple =
75
- |r : crate :: Reference < ' _ > | ( r. inner . target . into_id ( ) , Cow :: from ( r. inner . name . shorten ( ) . to_owned ( ) ) ) ;
76
74
77
75
Ok ( match self {
78
- SelectRef :: AllTags => platform
79
- . tags ( ) ?
80
- . peeled ( )
76
+ SelectRef :: AllTags | SelectRef :: AllRefs => {
77
+ let mut refs: Vec < _ > = match self {
78
+ SelectRef :: AllRefs => platform. all ( ) ?,
79
+ SelectRef :: AllTags => platform. tags ( ) ?,
80
+ _ => unreachable ! ( ) ,
81
+ }
81
82
. filter_map ( Result :: ok)
82
- . map ( into_tuple)
83
- . collect ( ) ,
84
- SelectRef :: AllRefs => platform
85
- . all ( ) ?
86
- . peeled ( )
87
- . filter_map ( Result :: ok)
88
- . map ( into_tuple)
89
- . collect ( ) ,
83
+ . filter_map ( |mut r : crate :: Reference < ' _ > | {
84
+ let target_id = r. target ( ) . try_id ( ) . map ( ToOwned :: to_owned) ;
85
+ let peeled_id = r. peel_to_id_in_place ( ) . ok ( ) ?;
86
+ let ( prio, tag_time) = match target_id {
87
+ Some ( target_id) if peeled_id != * target_id => {
88
+ let tag = repo. find_object ( target_id) . ok ( ) ?. try_into_tag ( ) . ok ( ) ?;
89
+ ( 1 , tag. tagger ( ) . ok ( ) ??. time . seconds_since_unix_epoch )
90
+ }
91
+ _ => ( 0 , 0 ) ,
92
+ } ;
93
+ (
94
+ peeled_id. inner ,
95
+ prio,
96
+ tag_time,
97
+ Cow :: from ( r. inner . name . shorten ( ) . to_owned ( ) ) ,
98
+ )
99
+ . into ( )
100
+ } )
101
+ . collect ( ) ;
102
+ refs. sort_by ( |a, b| a. 2 . cmp ( & b. 2 ) . then_with ( || a. 1 . cmp ( & b. 1 ) ) ) ; // by time ascending, then by priority. Older entries overwrite newer ones.
103
+ refs. into_iter ( ) . map ( |( a, _, _, b) | ( a, b) ) . collect ( )
104
+ }
90
105
SelectRef :: AnnotatedTags => {
91
106
let mut peeled_commits_and_tag_date: Vec < _ > = platform
92
107
. tags ( ) ?
@@ -104,9 +119,7 @@ pub mod describe {
104
119
Some ( ( commit_id, tag_time, r. name ( ) . shorten ( ) . to_owned ( ) . into ( ) ) )
105
120
} )
106
121
. collect ( ) ;
107
- // TODO: this kind of sorting would also have to apply to the AllRefs/AlLTags cases, where annotated tags are preferred
108
- // and sorted accordingly.
109
- peeled_commits_and_tag_date. sort_by ( |a, b| a. 1 . cmp ( & b. 1 ) . reverse ( ) ) ; // by time, ascending, causing older names to overwrite newer ones.
122
+ peeled_commits_and_tag_date. sort_by ( |a, b| a. 1 . cmp ( & b. 1 ) ) ; // by time, ascending, causing older names to overwrite newer ones.
110
123
peeled_commits_and_tag_date
111
124
. into_iter ( )
112
125
. map ( |( a, _, c) | ( a, c) )
0 commit comments