Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

genemichaels: apply patch to only write files if changed #365303

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/crates/genemichaels/src/main.rs b/crates/genemichaels/src/main.rs
index 724b38a..2fb23d0 100644
--- a/crates/genemichaels/src/main.rs
+++ b/crates/genemichaels/src/main.rs
@@ -348,10 +348,11 @@ impl FormatPool {
log.log_with(loga::INFO, "Skipping due to skip comment", ea!());
return Ok(());
}
- fs::write(
- &file,
- process_file_contents(log, &config, &source).context("Error doing formatting")?.as_bytes(),
- ).context("Error writing formatted code back")?;
+ let processed = process_file_contents(log, &config, &source).context("Error doing formatting")?;
+ if source != processed {
+ log.log_with(loga::INFO, "Writing newly file", ea!());
+ fs::write(&file, processed.as_bytes()).context("Error writing formatted code back")?;
+ }
return Ok(());
}).stack_context(log, "Error formatting file");
match res {
8 changes: 8 additions & 0 deletions pkgs/by-name/ge/genemichaels/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ rustPlatform.buildRustPackage rec {
hash = "sha256-qPyIC9AbRQI+inBft7Dd5R5v+tXtJcZdiV4lBIBwpyM=";
};

patches = [
# TODO(@djacu): remove this if this patch is merged and the version is
# bumped to a release that has this change
# See: https://github.com/andrewbaxter/genemichaels/issues/95
# See: https://github.com/andrewbaxter/genemichaels/pull/96
./genemichaels-only-write-if-changed.patch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be better to fetch the patch from GitHub rather than vendoring it in-tree

Suggested change
./genemichaels-only-write-if-changed.patch
(fetchpatch {
url = "https://github.com/andrewbaxter/genemichaels/commit/3c58f090888053b5165dbb0292b5974293851e2a.patch";
hash = "sha256-vxtO9N6P6rcfGhIfagr2fT83o0lM6J1tOckxarMJkL8=";
})

];

cargoHash = "sha256-yPxgYf8N3Dqns/uKhdM++jpzG7zTPhCVVq+7WA9G/SM=";

cargoBuildFlags = [ "--package ${pname}" ];
Expand Down
Loading