@@ -5,103 +5,108 @@ use crate::git::{Delta, FileMode, FileStatus, Status};
5
5
/// Builder for creating a new reference.
6
6
#[ derive( Debug ) ]
7
7
pub ( crate ) struct FileStatusBuilder {
8
- file_status : FileStatus ,
8
+ deltas : Vec < Delta > ,
9
+ destination_is_binary : bool ,
10
+ destination_mode : FileMode ,
11
+ destination_path : PathBuf ,
12
+ source_is_binary : bool ,
13
+ source_mode : FileMode ,
14
+ source_path : PathBuf ,
15
+ status : Status ,
9
16
}
10
17
11
18
impl FileStatusBuilder {
12
19
/// Create a new instance of the builder. The new instance will default to an empty file status.
13
20
#[ must_use]
14
21
pub ( crate ) fn new ( ) -> Self {
15
22
Self {
16
- file_status : FileStatus {
17
- deltas : vec ! [ ] ,
18
- destination_is_binary : false ,
19
- destination_mode : FileMode :: Normal ,
20
- destination_path : PathBuf :: default ( ) ,
21
- largest_new_line_number : 0 ,
22
- largest_old_line_number : 0 ,
23
- source_is_binary : false ,
24
- source_mode : FileMode :: Normal ,
25
- source_path : PathBuf :: default ( ) ,
26
- status : Status :: Added ,
27
- } ,
23
+ deltas : vec ! [ ] ,
24
+ destination_is_binary : false ,
25
+ destination_mode : FileMode :: Normal ,
26
+ destination_path : PathBuf :: default ( ) ,
27
+ source_is_binary : false ,
28
+ source_mode : FileMode :: Normal ,
29
+ source_path : PathBuf :: default ( ) ,
30
+ status : Status :: Added ,
28
31
}
29
32
}
30
33
31
34
/// Push a `Delta`.
32
35
#[ must_use]
33
36
pub ( crate ) fn push_delta ( mut self , delta : Delta ) -> Self {
34
- self . file_status . add_delta ( delta) ;
37
+ self . deltas . push ( delta) ;
35
38
self
36
39
}
37
40
38
41
/// Set if the destination is binary.
39
42
#[ must_use]
43
+ #[ allow( dead_code) ]
40
44
pub ( crate ) const fn destination_is_binary ( mut self , binary : bool ) -> Self {
41
- self . file_status . destination_is_binary = binary;
45
+ self . destination_is_binary = binary;
42
46
self
43
47
}
44
48
45
49
/// Set the destination file mode.
46
50
#[ must_use]
47
51
pub ( crate ) const fn destination_mode ( mut self , mode : FileMode ) -> Self {
48
- self . file_status . destination_mode = mode;
52
+ self . destination_mode = mode;
49
53
self
50
54
}
51
55
52
56
/// Set the destination file path.
53
57
#[ must_use]
54
58
pub ( crate ) fn destination_path < F : AsRef < Path > > ( mut self , path : F ) -> Self {
55
- self . file_status . destination_path = PathBuf :: from ( path. as_ref ( ) ) ;
56
- self
57
- }
58
-
59
- /// Set the largest new line number.
60
- #[ must_use]
61
- pub ( crate ) const fn largest_new_line_number ( mut self , largest_new_line_number : u32 ) -> Self {
62
- self . file_status . largest_new_line_number = largest_new_line_number;
63
- self
64
- }
65
-
66
- /// Set the largest old line number.
67
- #[ must_use]
68
- pub ( crate ) const fn largest_old_line_number ( mut self , largest_old_line_number : u32 ) -> Self {
69
- self . file_status . largest_old_line_number = largest_old_line_number;
59
+ self . destination_path = PathBuf :: from ( path. as_ref ( ) ) ;
70
60
self
71
61
}
72
62
73
63
/// Set if the source is binary.
74
64
#[ must_use]
65
+ #[ allow( dead_code) ]
75
66
pub ( crate ) const fn source_is_binary ( mut self , binary : bool ) -> Self {
76
- self . file_status . source_is_binary = binary;
67
+ self . source_is_binary = binary;
77
68
self
78
69
}
79
70
80
71
/// Set if the source file mode.
81
72
#[ must_use]
73
+ #[ allow( dead_code) ]
82
74
pub ( crate ) const fn source_mode ( mut self , mode : FileMode ) -> Self {
83
- self . file_status . source_mode = mode;
75
+ self . source_mode = mode;
84
76
self
85
77
}
86
78
87
79
/// Set the destination file path.
88
80
#[ must_use]
89
81
pub ( crate ) fn source_path < F : AsRef < Path > > ( mut self , path : F ) -> Self {
90
- self . file_status . source_path = PathBuf :: from ( path. as_ref ( ) ) ;
82
+ self . source_path = PathBuf :: from ( path. as_ref ( ) ) ;
91
83
self
92
84
}
93
85
94
86
/// Set the status.
95
87
#[ must_use]
96
88
pub ( crate ) const fn status ( mut self , status : Status ) -> Self {
97
- self . file_status . status = status;
89
+ self . status = status;
98
90
self
99
91
}
100
92
101
93
/// Build the `FileStatus`
102
94
#[ must_use]
103
95
#[ allow( clippy:: missing_const_for_fn) ]
104
96
pub ( crate ) fn build ( self ) -> FileStatus {
105
- self . file_status
97
+ let mut file_status = FileStatus :: new (
98
+ self . source_path ,
99
+ self . source_mode ,
100
+ self . source_is_binary ,
101
+ self . destination_path ,
102
+ self . destination_mode ,
103
+ self . destination_is_binary ,
104
+ self . status ,
105
+ ) ;
106
+ for delta in self . deltas {
107
+ file_status. add_delta ( delta) ;
108
+ }
109
+
110
+ file_status
106
111
}
107
112
}
0 commit comments