1
- use std :: path :: Path ;
2
-
1
+ use crate :: fs :: cache :: state :: IgnoreMatchGroup ;
2
+ use crate :: fs :: PathOidMapping ;
3
3
use bstr:: { BStr , BString , ByteSlice } ;
4
4
use gix_glob:: pattern:: Case ;
5
5
use gix_hash:: oid;
6
-
7
- use crate :: fs:: { cache:: State , PathOidMapping } ;
8
-
9
- type AttributeMatchGroup = gix_attributes:: Search ;
10
- type IgnoreMatchGroup = gix_ignore:: Search ;
11
-
12
- /// State related to attributes associated with files in the repository.
13
- #[ derive( Default , Clone ) ]
14
- #[ allow( unused) ]
15
- pub struct Attributes {
16
- /// Attribute patterns that match the currently set directory (in the stack).
17
- pub stack : AttributeMatchGroup ,
18
- /// Attribute patterns which aren't tied to the repository root, hence are global. They are consulted last.
19
- pub globals : AttributeMatchGroup ,
20
- }
6
+ use std:: path:: Path ;
21
7
22
8
/// State related to the exclusion of files.
23
9
#[ derive( Default , Clone ) ]
@@ -35,7 +21,7 @@ pub struct Ignore {
35
21
/// (index into match groups, index into list of pattern lists, index into pattern list)
36
22
matched_directory_patterns_stack : Vec < Option < ( usize , usize , usize ) > > ,
37
23
/// The name of the file to look for in directories.
38
- exclude_file_name_for_directories : BString ,
24
+ pub ( crate ) exclude_file_name_for_directories : BString ,
39
25
/// The case to use when matching directories as they are pushed onto the stack. We run them against the exclude engine
40
26
/// to know if an entire path can be ignored as a parent directory is ignored.
41
27
case : Case ,
@@ -183,12 +169,8 @@ impl Ignore {
183
169
let ignore_blob = find ( & attribute_files_in_index[ idx] . 1 , buf)
184
170
. map_err ( |err| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , err) ) ?;
185
171
let ignore_path = gix_path:: from_bstring ( ignore_path_relative. into_owned ( ) ) ;
186
- gix_glob:: search:: add_patterns_buffer (
187
- & mut self . stack . patterns ,
188
- ignore_blob. data ,
189
- ignore_path,
190
- Some ( root) ,
191
- ) ;
172
+ self . stack
173
+ . add_patterns_buffer ( ignore_blob. data , ignore_path, Some ( root) ) ;
192
174
}
193
175
Err ( _) => {
194
176
// Need one stack level per component so push and pop matches.
@@ -199,118 +181,3 @@ impl Ignore {
199
181
Ok ( ( ) )
200
182
}
201
183
}
202
-
203
- impl Attributes {
204
- /// Create a new instance from an attribute match group that represents `globals`.
205
- ///
206
- /// A stack of attributes will be applied on top of it later.
207
- pub fn new ( globals : AttributeMatchGroup ) -> Self {
208
- Attributes {
209
- globals,
210
- stack : Default :: default ( ) ,
211
- }
212
- }
213
- }
214
-
215
- impl From < AttributeMatchGroup > for Attributes {
216
- fn from ( group : AttributeMatchGroup ) -> Self {
217
- Attributes :: new ( group)
218
- }
219
- }
220
-
221
- impl State {
222
- /// Configure a state to be suitable for checking out files.
223
- pub fn for_checkout ( unlink_on_collision : bool , attributes : Attributes ) -> Self {
224
- State :: CreateDirectoryAndAttributesStack {
225
- unlink_on_collision,
226
- #[ cfg( debug_assertions) ]
227
- test_mkdir_calls : 0 ,
228
- attributes,
229
- }
230
- }
231
-
232
- /// Configure a state for adding files.
233
- pub fn for_add ( attributes : Attributes , ignore : Ignore ) -> Self {
234
- State :: AttributesAndIgnoreStack { attributes, ignore }
235
- }
236
-
237
- /// Configure a state for status retrieval.
238
- pub fn for_status ( ignore : Ignore ) -> Self {
239
- State :: IgnoreStack ( ignore)
240
- }
241
- }
242
-
243
- impl State {
244
- /// Returns a vec of tuples of relative index paths along with the best usable OID for either ignore, attribute files or both.
245
- ///
246
- /// - ignores entries which aren't blobs
247
- /// - ignores ignore entries which are not skip-worktree
248
- /// - within merges, picks 'our' stage both for ignore and attribute files.
249
- pub fn build_attribute_list (
250
- & self ,
251
- index : & gix_index:: State ,
252
- paths : & gix_index:: PathStorageRef ,
253
- case : Case ,
254
- ) -> Vec < PathOidMapping > {
255
- let a1_backing;
256
- let a2_backing;
257
- let names = match self {
258
- State :: IgnoreStack ( v) => {
259
- a1_backing = [ ( v. exclude_file_name_for_directories . as_bytes ( ) . as_bstr ( ) , true ) ] ;
260
- a1_backing. as_ref ( )
261
- }
262
- State :: AttributesAndIgnoreStack { ignore, .. } => {
263
- a2_backing = [
264
- ( ignore. exclude_file_name_for_directories . as_bytes ( ) . as_bstr ( ) , true ) ,
265
- ( ".gitattributes" . into ( ) , false ) ,
266
- ] ;
267
- a2_backing. as_ref ( )
268
- }
269
- State :: CreateDirectoryAndAttributesStack { .. } => {
270
- a1_backing = [ ( ".gitattributes" . into ( ) , true ) ] ;
271
- a1_backing. as_ref ( )
272
- }
273
- } ;
274
-
275
- index
276
- . entries ( )
277
- . iter ( )
278
- . filter_map ( move |entry| {
279
- let path = entry. path_in ( paths) ;
280
-
281
- // Stage 0 means there is no merge going on, stage 2 means it's 'our' side of the merge, but then
282
- // there won't be a stage 0.
283
- if entry. mode == gix_index:: entry:: Mode :: FILE && ( entry. stage ( ) == 0 || entry. stage ( ) == 2 ) {
284
- let basename = path
285
- . rfind_byte ( b'/' )
286
- . map ( |pos| path[ pos + 1 ..] . as_bstr ( ) )
287
- . unwrap_or ( path) ;
288
- let is_ignore = names. iter ( ) . find_map ( |t| {
289
- match case {
290
- Case :: Sensitive => basename == t. 0 ,
291
- Case :: Fold => basename. eq_ignore_ascii_case ( t. 0 ) ,
292
- }
293
- . then_some ( t. 1 )
294
- } ) ?;
295
- // See https://github.com/git/git/blob/master/dir.c#L912:L912
296
- if is_ignore && !entry. flags . contains ( gix_index:: entry:: Flags :: SKIP_WORKTREE ) {
297
- return None ;
298
- }
299
- Some ( ( path. to_owned ( ) , entry. id ) )
300
- } else {
301
- None
302
- }
303
- } )
304
- . collect ( )
305
- }
306
-
307
- pub ( crate ) fn ignore_or_panic ( & self ) -> & Ignore {
308
- match self {
309
- State :: IgnoreStack ( v) => v,
310
- State :: AttributesAndIgnoreStack { ignore, .. } => ignore,
311
- State :: CreateDirectoryAndAttributesStack { .. } => {
312
- unreachable ! ( "BUG: must not try to check excludes without it being setup" )
313
- }
314
- }
315
- }
316
- }
0 commit comments