Skip to content

Don't overwrite files if they are unchanged #296

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

Merged
merged 1 commit into from
Apr 21, 2022

Conversation

myyra
Copy link
Contributor

@myyra myyra commented Apr 21, 2022

Always writing to the file, even if unchanged, updates the modified time and prevents incremental builds in Xcode. This PR adds a simple equal check before actually writing anything, preserving timestamps if nothing in the output was changed.

I don't remember this being an issue for me before, but I also couldn't find any change that would've started to cause this. In any case, this completely resolves the problem.

In my testing with a small folder of files, this change also makes the formatting slightly faster.

Always writing to the file, even if unchanged, updates the modified time
and prevents incremental builds in Xcode.
@myyra myyra changed the title Don't Overwrite Files If They Are Unchanged Don't overwrite files if they are unchanged Apr 21, 2022
Copy link
Member

@allevato allevato left a comment

Choose a reason for hiding this comment

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

This is a nice improvement, thank you!

@allevato allevato merged commit f30e81e into swiftlang:main Apr 21, 2022
@myyra myyra deleted the prevent-overwriting-unchanged branch April 22, 2022 05:41
allevato added a commit to allevato/swift-format that referenced this pull request Sep 13, 2022
…nged

Don't overwrite files if they are unchanged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants