@@ -40,11 +40,32 @@ pub mod describe {
40
40
}
41
41
42
42
impl < ' repo > Resolution < ' repo > {
43
- /// Turn this instance into something displayable
43
+ /// Turn this instance into something displayable.
44
44
pub fn format ( self ) -> Result < gix_revision:: describe:: Format < ' static > , Error > {
45
45
let prefix = self . id . shorten ( ) ?;
46
46
Ok ( self . outcome . into_format ( prefix. hex_len ( ) ) )
47
47
}
48
+
49
+ /// Turn this instance into something displayable, possibly with dirty-suffix.
50
+ ///
51
+ /// If `dirty_suffix` is `Some(suffix)`, a possibly expensive [dirty check](crate::Repository::is_dirty()) will be
52
+ /// performed so that the `suffix` is appended to the output. If it is `None`, no check will be performed and
53
+ /// there will be no suffix.
54
+ /// Note that obtaining the dirty-state of the repository can be expensive.
55
+ #[ cfg( all( feature = "status" , feature = "parallel" ) ) ]
56
+ pub fn format_with_dirty_suffix (
57
+ self ,
58
+ dirty_suffix : impl Into < Option < String > > ,
59
+ ) -> Result < gix_revision:: describe:: Format < ' static > , Error > {
60
+ let prefix = self . id . shorten ( ) ?;
61
+ let mut dirty_suffix = dirty_suffix. into ( ) ;
62
+ if dirty_suffix. is_some ( ) && !self . id . repo . is_dirty ( ) ? {
63
+ dirty_suffix. take ( ) ;
64
+ }
65
+ let mut format = self . outcome . into_format ( prefix. hex_len ( ) ) ;
66
+ format. dirty_suffix = dirty_suffix;
67
+ Ok ( format)
68
+ }
48
69
}
49
70
50
71
/// The error returned by [`try_format()`][Platform::try_format()].
@@ -59,6 +80,9 @@ pub mod describe {
59
80
RefIter ( #[ from] crate :: reference:: iter:: Error ) ,
60
81
#[ error( transparent) ]
61
82
RefIterInit ( #[ from] crate :: reference:: iter:: init:: Error ) ,
83
+ #[ error( transparent) ]
84
+ #[ cfg( all( feature = "status" , feature = "parallel" ) ) ]
85
+ DetermineIsDirty ( #[ from] crate :: status:: is_dirty:: Error ) ,
62
86
}
63
87
64
88
/// A selector to choose what kind of references should contribute to names.
@@ -179,9 +203,7 @@ pub mod describe {
179
203
}
180
204
181
205
/// Try to find a name for the configured commit id using all prior configuration, returning `Some(describe::Format)`
182
- /// if one was found.
183
- ///
184
- /// Note that there will always be `Some(format)`
206
+ /// if one was found, or `None` if that wasn't the case.
185
207
pub fn try_format ( & self ) -> Result < Option < gix_revision:: describe:: Format < ' static > > , Error > {
186
208
self . try_resolve ( ) ?. map ( Resolution :: format) . transpose ( )
187
209
}
@@ -193,10 +215,9 @@ pub mod describe {
193
215
///
194
216
/// # Performance
195
217
///
196
- /// It is greatly recommended to [assure an object cache is set][ crate::Repository::object_cache_size_if_unset()]
218
+ /// It is greatly recommended to [assure an object cache is set]( crate::Repository::object_cache_size_if_unset())
197
219
/// to save ~40% of time.
198
220
pub fn try_resolve ( & self ) -> Result < Option < Resolution < ' repo > > , Error > {
199
- // TODO: dirty suffix with respective dirty-detection
200
221
let mut graph = gix_revwalk:: Graph :: new (
201
222
& self . repo . objects ,
202
223
gix_commitgraph:: Graph :: from_info_dir ( self . repo . objects . store_ref ( ) . path ( ) . join ( "info" ) . as_ref ( ) ) . ok ( ) ,
@@ -218,7 +239,7 @@ pub mod describe {
218
239
} ) )
219
240
}
220
241
221
- /// Like [`try_format()`][Platform ::try_format()] , but turns `id_as_fallback()` on to always produce a format.
242
+ /// Like [`try_format()`](Self ::try_format()) , but turns `id_as_fallback()` on to always produce a format.
222
243
pub fn format ( & mut self ) -> Result < gix_revision:: describe:: Format < ' static > , Error > {
223
244
self . id_as_fallback = true ;
224
245
Ok ( self . try_format ( ) ?. expect ( "BUG: fallback must always produce a format" ) )
0 commit comments