@@ -113,9 +113,9 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
113
113
}
114
114
let rustfmt_config = t ! ( std:: fs:: read_to_string( & rustfmt_config) ) ;
115
115
let rustfmt_config: RustfmtConfig = t ! ( toml:: from_str( & rustfmt_config) ) ;
116
- let mut ignore_fmt = ignore:: overrides:: OverrideBuilder :: new ( & build. src ) ;
116
+ let mut fmt_override = ignore:: overrides:: OverrideBuilder :: new ( & build. src ) ;
117
117
for ignore in rustfmt_config. ignore {
118
- ignore_fmt . add ( & format ! ( "!{ignore}" ) ) . expect ( & ignore) ;
118
+ fmt_override . add ( & format ! ( "!{ignore}" ) ) . expect ( & ignore) ;
119
119
}
120
120
let git_available = match Command :: new ( "git" )
121
121
. arg ( "--version" )
@@ -152,14 +152,16 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
152
152
. map ( |entry| {
153
153
entry. split ( ' ' ) . nth ( 1 ) . expect ( "every git status entry should list a path" )
154
154
} ) ;
155
+ let mut untracked_count = 0 ;
155
156
for untracked_path in untracked_paths {
156
157
println ! ( "skip untracked path {untracked_path} during rustfmt invocations" ) ;
157
158
// The leading `/` makes it an exact match against the
158
159
// repository root, rather than a glob. Without that, if you
159
160
// have `foo.rs` in the repository root it will also match
160
161
// against anything like `compiler/rustc_foo/src/foo.rs`,
161
162
// preventing the latter from being formatted.
162
- ignore_fmt. add ( & format ! ( "!/{untracked_path}" ) ) . expect ( & untracked_path) ;
163
+ untracked_count += 1 ;
164
+ fmt_override. add ( & format ! ( "!/{untracked_path}" ) ) . expect ( & untracked_path) ;
163
165
}
164
166
// Only check modified files locally to speed up runtime.
165
167
// We still check all files in CI to avoid bugs in `get_modified_rs_files` letting regressions slip through;
@@ -172,10 +174,25 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
172
174
println ! ( "formatting modified file {file}" ) ;
173
175
}
174
176
} else {
175
- println ! ( "formatting {} modified files" , files. len( ) ) ;
177
+ let pluralized = |count| if count > 1 { "files" } else { "file" } ;
178
+ let untracked_msg = if untracked_count == 0 {
179
+ "" . to_string ( )
180
+ } else {
181
+ format ! (
182
+ ", skipped {} untracked {}" ,
183
+ untracked_count,
184
+ pluralized( untracked_count) ,
185
+ )
186
+ } ;
187
+ println ! (
188
+ "formatting {} modified {}{}" ,
189
+ files. len( ) ,
190
+ pluralized( files. len( ) ) ,
191
+ untracked_msg
192
+ ) ;
176
193
}
177
194
for file in files {
178
- ignore_fmt . add ( & format ! ( "/{file}" ) ) . expect ( & file) ;
195
+ fmt_override . add ( & format ! ( "/{file}" ) ) . expect ( & file) ;
179
196
}
180
197
}
181
198
Ok ( None ) => { }
@@ -196,7 +213,7 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
196
213
println ! ( "Could not find usable git. Skipping git-aware format checks" ) ;
197
214
}
198
215
199
- let ignore_fmt = ignore_fmt . build ( ) . unwrap ( ) ;
216
+ let fmt_override = fmt_override . build ( ) . unwrap ( ) ;
200
217
201
218
let rustfmt_path = build. initial_rustfmt ( ) . unwrap_or_else ( || {
202
219
eprintln ! ( "./x.py fmt is not supported on this channel" ) ;
@@ -252,7 +269,7 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
252
269
None => WalkBuilder :: new ( src. clone ( ) ) ,
253
270
}
254
271
. types ( matcher)
255
- . overrides ( ignore_fmt )
272
+ . overrides ( fmt_override )
256
273
. build_parallel ( ) ;
257
274
258
275
// there is a lot of blocking involved in spawning a child process and reading files to format.
0 commit comments