@@ -15,9 +15,9 @@ fn main() {
15
15
let args: Vec < String > = env:: args ( ) . collect ( ) ;
16
16
let mut patterns_filters: Vec < PatternFilter > = Vec :: new ( ) ;
17
17
18
- for arg in args. iter ( ) {
18
+ for arg in & args {
19
19
if arg. starts_with ( "--patterns=" ) {
20
- patterns_filters = create_patterns_filters ( & arg) ;
20
+ patterns_filters = create_patterns_filters ( arg) ;
21
21
}
22
22
}
23
23
@@ -26,34 +26,34 @@ fn main() {
26
26
return ;
27
27
}
28
28
29
- let ( include_patterns_filters, exclude_patterns_filters) = categorize_filters ( patterns_filters) ;
29
+ let ( include_patterns_filters, exclude_patterns_filters) = categorize_filters ( & patterns_filters) ;
30
30
31
31
let start = Instant :: now ( ) ;
32
32
let changed_files = get_changed_files ( ) ;
33
33
let duration = start. elapsed ( ) ;
34
- println ! ( "Getting changed files done in: {:?}" , duration ) ;
34
+ println ! ( "Getting changed files done in: {duration :?}" ) ;
35
35
36
- println ! ( "Changed files: {:?}" , changed_files ) ;
36
+ println ! ( "Changed files: {changed_files :?}" ) ;
37
37
38
38
let start = Instant :: now ( ) ;
39
- let filtered_files = filter_files ( changed_files, include_patterns_filters, exclude_patterns_filters) ;
39
+ let filtered_files = filter_files ( & changed_files, & include_patterns_filters, & exclude_patterns_filters) ;
40
40
let duration = start. elapsed ( ) ;
41
- println ! ( "Filtering files done in: {:?}" , duration ) ;
41
+ println ! ( "Filtering files done in: {duration :?}" ) ;
42
42
43
- let count = get_count ( filtered_files. clone ( ) ) ;
43
+ let count = get_count ( & filtered_files) ;
44
44
45
- println ! ( "Filtered files: {:?}" , filtered_files ) ;
46
- println ! ( "Count: {}" , count ) ;
45
+ println ! ( "Filtered files: {filtered_files :?}" ) ;
46
+ println ! ( "Count: {count}" ) ;
47
47
48
48
Command :: new ( "sh" )
49
49
. arg ( "-c" )
50
- . arg ( format ! ( "echo \" DIFF_FILES={:?}\" >> $GITHUB_OUTPUT" , filtered_files ) )
50
+ . arg ( format ! ( "echo \" DIFF_FILES={filtered_files :?}\" >> $GITHUB_OUTPUT" ) )
51
51
. output ( )
52
52
. expect ( "Failed to execute DIFF_FILES command" ) ;
53
53
54
54
Command :: new ( "sh" )
55
55
. arg ( "-c" )
56
- . arg ( format ! ( "echo \" DIFF_COUNT={}\" >> $GITHUB_OUTPUT" , count ) )
56
+ . arg ( format ! ( "echo \" DIFF_COUNT={count }\" >> $GITHUB_OUTPUT" ) )
57
57
. output ( )
58
58
. expect ( "Failed to execute DIFF_COUNT command" ) ;
59
59
}
@@ -63,9 +63,9 @@ fn create_patterns_filters(arg: &str) -> Vec<PatternFilter> {
63
63
. split ( '=' )
64
64
. last ( )
65
65
. expect ( "Failed to get patterns" )
66
- . replace ( " " , "" )
67
- . replace ( " \n " , "," )
68
- . replace ( " \r " , "" )
66
+ . replace ( ' ' , "" )
67
+ . replace ( '\n' , "," )
68
+ . replace ( '\r' , "" )
69
69
. replace ( ",," , "," )
70
70
. trim_end_matches ( ',' )
71
71
. to_string ( ) ;
@@ -76,12 +76,12 @@ fn create_patterns_filters(arg: &str) -> Vec<PatternFilter> {
76
76
77
77
let mut patterns_filters: Vec < PatternFilter > = Vec :: new ( ) ;
78
78
79
- for pattern in patterns. iter ( ) {
79
+ for pattern in & patterns {
80
80
let exclude = pattern. starts_with ( '!' ) ;
81
81
let pattern = if exclude {
82
82
pattern[ 1 ..] . to_string ( )
83
83
} else {
84
- pattern. to_string ( )
84
+ ( * pattern) . to_string ( )
85
85
} ;
86
86
87
87
patterns_filters. push ( PatternFilter {
@@ -104,11 +104,11 @@ fn get_changed_files() -> Vec<String> {
104
104
105
105
Command :: new ( "sh" )
106
106
. arg ( "-c" )
107
- . arg ( format ! ( "git fetch origin {}" , base_ref_env ) )
107
+ . arg ( format ! ( "git fetch origin {base_ref_env}" ) )
108
108
. output ( )
109
109
. expect ( "Failed to execute fetch branch command" ) ;
110
110
111
- let base_ref_string = format ! ( "refs/remotes/origin/{}" , base_ref_env ) ;
111
+ let base_ref_string = format ! ( "refs/remotes/origin/{base_ref_env}" ) ;
112
112
let base_ref = repository. find_reference ( & base_ref_string) . expect ( "Failed to find default branch" ) ;
113
113
let base_commit = base_ref. peel_to_commit ( ) . expect ( "Failed to peel default branch to commit" ) ;
114
114
@@ -134,41 +134,41 @@ fn get_changed_files() -> Vec<String> {
134
134
changed_files
135
135
}
136
136
137
- fn filter_files ( changed_files : Vec < String > , include_patterns_filters : HashSet < String > , exclude_patterns_filters : HashSet < String > ) -> HashSet < String > {
137
+ fn filter_files ( changed_files : & Vec < String > , include_patterns_filters : & HashSet < String > , exclude_patterns_filters : & HashSet < String > ) -> HashSet < String > {
138
138
let mut hash_set_filtered_files = HashSet :: new ( ) ;
139
139
140
- for changed_file in changed_files. iter ( ) {
141
- include_patterns_filters . iter ( ) . for_each ( | pattern| {
140
+ for changed_file in changed_files {
141
+ for pattern in include_patterns_filters {
142
142
if Pattern :: new ( pattern) . expect ( "Failed to create pattern" ) . matches ( changed_file) {
143
143
hash_set_filtered_files. insert ( changed_file. to_string ( ) ) ;
144
144
}
145
145
146
- exclude_patterns_filters . iter ( ) . for_each ( | pattern| {
146
+ for pattern in exclude_patterns_filters {
147
147
if Pattern :: new ( pattern) . expect ( "Failed to create pattern" ) . matches ( changed_file) {
148
148
hash_set_filtered_files. remove ( changed_file) ;
149
149
}
150
- } ) ;
151
- } ) ;
150
+ }
151
+ }
152
152
}
153
153
154
154
hash_set_filtered_files
155
155
}
156
156
157
- fn get_count ( filtered_files : HashSet < String > ) -> usize {
157
+ fn get_count ( filtered_files : & HashSet < String > ) -> usize {
158
158
filtered_files. len ( )
159
159
}
160
160
161
- fn categorize_filters ( filters : Vec < PatternFilter > ) -> ( HashSet < String > , HashSet < String > ) {
161
+ fn categorize_filters ( filters : & Vec < PatternFilter > ) -> ( HashSet < String > , HashSet < String > ) {
162
162
let mut exclude_patterns_filters: HashSet < String > = HashSet :: new ( ) ;
163
163
let mut include_patterns_filters: HashSet < String > = HashSet :: new ( ) ;
164
164
165
- filters . iter ( ) . for_each ( | pattern_filter| {
165
+ for pattern_filter in filters {
166
166
if pattern_filter. exclude {
167
167
exclude_patterns_filters. insert ( pattern_filter. clone ( ) . pattern ) ;
168
168
} else {
169
169
include_patterns_filters. insert ( pattern_filter. clone ( ) . pattern ) ;
170
170
}
171
- } ) ;
171
+ }
172
172
173
173
( include_patterns_filters, exclude_patterns_filters)
174
174
}
0 commit comments