wanders created this revision. wanders added a reviewer: clang-format. wanders added a project: clang-format. Herald added a project: clang.
No functional change intended Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D68568 Files: clang/lib/Format/Format.cpp Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -2600,6 +2600,10 @@ if (std::error_code EC = FS->makeAbsolute(Path)) return make_string_error(EC.message()); + llvm::SmallVector<std::string, 2> FilesToLookFor; + FilesToLookFor.push_back(".clang-format"); + FilesToLookFor.push_back("_clang-format"); + for (StringRef Directory = Path; !Directory.empty(); Directory = llvm::sys::path::parent_path(Directory)) { @@ -2609,43 +2613,34 @@ continue; } - SmallString<128> ConfigFile(Directory); + for (const auto &F : FilesToLookFor) { + SmallString<128> ConfigFile(Directory); - llvm::sys::path::append(ConfigFile, ".clang-format"); - LLVM_DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n"); - - Status = FS->status(ConfigFile.str()); - bool FoundConfigFile = - Status && (Status->getType() == llvm::sys::fs::file_type::regular_file); - if (!FoundConfigFile) { - // Try _clang-format too, since dotfiles are not commonly used on Windows. - ConfigFile = Directory; - llvm::sys::path::append(ConfigFile, "_clang-format"); + llvm::sys::path::append(ConfigFile, F); LLVM_DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n"); + Status = FS->status(ConfigFile.str()); - FoundConfigFile = Status && (Status->getType() == - llvm::sys::fs::file_type::regular_file); - } - if (FoundConfigFile) { - llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text = - FS->getBufferForFile(ConfigFile.str()); - if (std::error_code EC = Text.getError()) - return make_string_error(EC.message()); - if (std::error_code ec = - parseConfiguration(Text.get()->getBuffer(), &Style)) { - if (ec == ParseError::Unsuitable) { - if (!UnsuitableConfigFiles.empty()) - UnsuitableConfigFiles.append(", "); - UnsuitableConfigFiles.append(ConfigFile); - continue; + if (Status && (Status->getType() == llvm::sys::fs::file_type::regular_file)) { + llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text = + FS->getBufferForFile(ConfigFile.str()); + if (std::error_code EC = Text.getError()) + return make_string_error(EC.message()); + if (std::error_code ec = + parseConfiguration(Text.get()->getBuffer(), &Style)) { + if (ec == ParseError::Unsuitable) { + if (!UnsuitableConfigFiles.empty()) + UnsuitableConfigFiles.append(", "); + UnsuitableConfigFiles.append(ConfigFile); + continue; + } + return make_string_error("Error reading " + ConfigFile + ": " + + ec.message()); } - return make_string_error("Error reading " + ConfigFile + ": " + - ec.message()); + LLVM_DEBUG(llvm::dbgs() + << "Using configuration file " << ConfigFile << "\n"); + return Style; } - LLVM_DEBUG(llvm::dbgs() - << "Using configuration file " << ConfigFile << "\n"); - return Style; } } if (!UnsuitableConfigFiles.empty())
Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -2600,6 +2600,10 @@ if (std::error_code EC = FS->makeAbsolute(Path)) return make_string_error(EC.message()); + llvm::SmallVector<std::string, 2> FilesToLookFor; + FilesToLookFor.push_back(".clang-format"); + FilesToLookFor.push_back("_clang-format"); + for (StringRef Directory = Path; !Directory.empty(); Directory = llvm::sys::path::parent_path(Directory)) { @@ -2609,43 +2613,34 @@ continue; } - SmallString<128> ConfigFile(Directory); + for (const auto &F : FilesToLookFor) { + SmallString<128> ConfigFile(Directory); - llvm::sys::path::append(ConfigFile, ".clang-format"); - LLVM_DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n"); - - Status = FS->status(ConfigFile.str()); - bool FoundConfigFile = - Status && (Status->getType() == llvm::sys::fs::file_type::regular_file); - if (!FoundConfigFile) { - // Try _clang-format too, since dotfiles are not commonly used on Windows. - ConfigFile = Directory; - llvm::sys::path::append(ConfigFile, "_clang-format"); + llvm::sys::path::append(ConfigFile, F); LLVM_DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n"); + Status = FS->status(ConfigFile.str()); - FoundConfigFile = Status && (Status->getType() == - llvm::sys::fs::file_type::regular_file); - } - if (FoundConfigFile) { - llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text = - FS->getBufferForFile(ConfigFile.str()); - if (std::error_code EC = Text.getError()) - return make_string_error(EC.message()); - if (std::error_code ec = - parseConfiguration(Text.get()->getBuffer(), &Style)) { - if (ec == ParseError::Unsuitable) { - if (!UnsuitableConfigFiles.empty()) - UnsuitableConfigFiles.append(", "); - UnsuitableConfigFiles.append(ConfigFile); - continue; + if (Status && (Status->getType() == llvm::sys::fs::file_type::regular_file)) { + llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text = + FS->getBufferForFile(ConfigFile.str()); + if (std::error_code EC = Text.getError()) + return make_string_error(EC.message()); + if (std::error_code ec = + parseConfiguration(Text.get()->getBuffer(), &Style)) { + if (ec == ParseError::Unsuitable) { + if (!UnsuitableConfigFiles.empty()) + UnsuitableConfigFiles.append(", "); + UnsuitableConfigFiles.append(ConfigFile); + continue; + } + return make_string_error("Error reading " + ConfigFile + ": " + + ec.message()); } - return make_string_error("Error reading " + ConfigFile + ": " + - ec.message()); + LLVM_DEBUG(llvm::dbgs() + << "Using configuration file " << ConfigFile << "\n"); + return Style; } - LLVM_DEBUG(llvm::dbgs() - << "Using configuration file " << ConfigFile << "\n"); - return Style; } } if (!UnsuitableConfigFiles.empty())
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits