From 51ac4643458df6e5f163e2983d8d7dd7474c7d14 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Sun, 3 Nov 2019 17:03:48 -0600 Subject: [PATCH 1/2] deprecate: --backup option --- Configurations.md | 2 +- src/bin/main.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Configurations.md b/Configurations.md index 0064f561720..00aafa10247 100644 --- a/Configurations.md +++ b/Configurations.md @@ -2444,7 +2444,7 @@ Internal option ## `make_backup` -Internal option, use `--backup` +Internal option, deprecated ## `print_misformatted_file_names` diff --git a/src/bin/main.rs b/src/bin/main.rs index ccbfb4052e2..72bf91db45b 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -521,6 +521,12 @@ fn deprecate_skip_children() { eprintln!("{}: {}", Red.bold().paint("Deprecation"), msg); } +fn deprecate_backup() { + let msg = "Option --backup is deprecated as this responsibility should be handled \ + by a version control system"; + eprintln!("{}: {}", Red.bold().paint("Deprecation"), msg); +} + impl GetOptsOptions { pub fn from_matches(matches: &Matches) -> Result { let mut options = GetOptsOptions::default(); @@ -608,6 +614,7 @@ impl GetOptsOptions { } if matches.opt_present("backup") { + deprecate_backup(); options.backup = true; } From 1abbb4b11d5abb83abe5daa26b647adc3e72d6ef Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Wed, 6 Nov 2019 20:01:51 -0600 Subject: [PATCH 2/2] deprecate: remove --backup entirely --- Configurations.md | 4 ---- src/bin/main.rs | 16 ---------------- src/config/mod.rs | 2 -- src/emitter.rs | 2 -- src/emitter/files_with_backup.rs | 31 ------------------------------- src/lib.rs | 3 --- 6 files changed, 58 deletions(-) delete mode 100644 src/emitter/files_with_backup.rs diff --git a/Configurations.md b/Configurations.md index 00aafa10247..a13fe062d89 100644 --- a/Configurations.md +++ b/Configurations.md @@ -2442,10 +2442,6 @@ Break comments to fit on the line Internal option -## `make_backup` - -Internal option, deprecated - ## `print_misformatted_file_names` Internal option, use `-l` or `--files-with-diff` diff --git a/src/bin/main.rs b/src/bin/main.rs index 72bf91db45b..4ecc81b2856 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -114,7 +114,6 @@ fn make_opts() -> Options { "[files|stdout]" }; opts.optopt("", "emit", "What data to emit and how", emit_opts); - opts.optflag("", "backup", "Backup any modified files."); opts.optopt( "", "config-path", @@ -505,7 +504,6 @@ struct GetOptsOptions { config_path: Option, inline_config: HashMap, emit_mode: Option, - backup: bool, check: bool, edition: Option, color: Option, @@ -521,12 +519,6 @@ fn deprecate_skip_children() { eprintln!("{}: {}", Red.bold().paint("Deprecation"), msg); } -fn deprecate_backup() { - let msg = "Option --backup is deprecated as this responsibility should be handled \ - by a version control system"; - eprintln!("{}: {}", Red.bold().paint("Deprecation"), msg); -} - impl GetOptsOptions { pub fn from_matches(matches: &Matches) -> Result { let mut options = GetOptsOptions::default(); @@ -613,11 +605,6 @@ impl GetOptsOptions { options.edition = Some(edition_from_edition_str(edition_str)?); } - if matches.opt_present("backup") { - deprecate_backup(); - options.backup = true; - } - if matches.opt_present("files-with-diff") { options.print_misformatted_file_names = true; } @@ -681,9 +668,6 @@ impl CliOptions for GetOptsOptions { } else if let Some(emit_mode) = self.emit_mode { config.set().emit_mode(emit_mode); } - if self.backup { - config.set().make_backup(true); - } if let Some(color) = self.color { config.set().color(color); } diff --git a/src/config/mod.rs b/src/config/mod.rs index 94f390ceef4..698a3224591 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -151,7 +151,6 @@ create_config! { "'small' heuristic values"; emit_mode: EmitMode, EmitMode::Files, false, "What emit Mode to use when none is supplied"; - make_backup: bool, false, false, "Backup changed files"; print_misformatted_file_names: bool, false, true, "Prints the names of mismatched files that were formatted. Prints the names of \ files that would be formated when used with `--check` mode. "; @@ -552,7 +551,6 @@ report_todo = "Never" report_fixme = "Never" ignore = [] emit_mode = "Files" -make_backup = false "#, env!("CARGO_PKG_VERSION") ); diff --git a/src/emitter.rs b/src/emitter.rs index dc2c99a301e..25774a35855 100644 --- a/src/emitter.rs +++ b/src/emitter.rs @@ -1,7 +1,6 @@ pub(crate) use self::checkstyle::*; pub(crate) use self::diff::*; pub(crate) use self::files::*; -pub(crate) use self::files_with_backup::*; pub(crate) use self::json::*; pub(crate) use self::modified_lines::*; pub(crate) use self::stdout::*; @@ -12,7 +11,6 @@ use std::path::Path; mod checkstyle; mod diff; mod files; -mod files_with_backup; mod json; mod modified_lines; mod stdout; diff --git a/src/emitter/files_with_backup.rs b/src/emitter/files_with_backup.rs deleted file mode 100644 index 4c15f6fa5ec..00000000000 --- a/src/emitter/files_with_backup.rs +++ /dev/null @@ -1,31 +0,0 @@ -use super::*; -use std::fs; - -#[derive(Debug, Default)] -pub(crate) struct FilesWithBackupEmitter; - -impl Emitter for FilesWithBackupEmitter { - fn emit_formatted_file( - &mut self, - _output: &mut dyn Write, - FormattedFile { - filename, - original_text, - formatted_text, - }: FormattedFile<'_>, - ) -> Result { - let filename = ensure_real_path(filename); - if original_text != formatted_text { - // Do a little dance to make writing safer - write to a temp file - // rename the original to a .bk, then rename the temp file to the - // original. - let tmp_name = filename.with_extension("tmp"); - let bk_name = filename.with_extension("bk"); - - fs::write(&tmp_name, formatted_text)?; - fs::rename(filename, bk_name)?; - fs::rename(tmp_name, filename)?; - } - Ok(EmitterResult::default()) - } -} diff --git a/src/lib.rs b/src/lib.rs index dbd9469908e..eab23dffff0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -478,9 +478,6 @@ impl<'b, T: Write + 'b> Session<'b, T> { pub(crate) fn create_emitter<'a>(config: &Config) -> Box { match config.emit_mode() { - EmitMode::Files if config.make_backup() => { - Box::new(emitter::FilesWithBackupEmitter::default()) - } EmitMode::Files => Box::new(emitter::FilesEmitter::new( config.print_misformatted_file_names(), )),