Don't touch unchanged file for in-place edit.
authorDaniel Jasper <djasper@google.com>
Wed, 30 Jan 2013 09:52:38 +0000 (09:52 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 30 Jan 2013 09:52:38 +0000 (09:52 +0000)
This fixes llvm.org/PR15087.

llvm-svn: 173919

clang-tools-extra/clang-format/ClangFormat.cpp

index 23043a3..da032d5 100644 (file)
@@ -97,6 +97,9 @@ static void format() {
   Rewriter Rewrite(Sources, LangOptions());
   tooling::applyAllReplacements(Replaces, Rewrite);
   if (Inplace) {
+    if (Replaces.size() == 0)
+      return; // Nothing changed, don't touch the file.
+
     std::string ErrorInfo;
     llvm::raw_fd_ostream FileStream(FileName.c_str(), ErrorInfo,
                                     llvm::raw_fd_ostream::F_Binary);