From 295915ceb727301fdea8cf11c2a871ccd1b5981f Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Thu, 24 Mar 2016 13:22:28 +0000 Subject: [PATCH] Revert "removed redundant comment in format::getStyle." This reverts commit r264254. llvm-svn: 264275 --- clang/lib/Format/Format.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 31dc259..6d03b62 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -2099,7 +2099,10 @@ static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) { } FormatStyle getStyle(StringRef StyleName, StringRef FileName, - StringRef FallbackStyle) { + StringRef FallbackStyle, vfs::FileSystem *FS) { + if (!FS) { + FS = vfs::getRealFileSystem().get(); + } FormatStyle Style = getLLVMStyle(); Style.Language = getLanguageByFileName(FileName); if (!getPredefinedStyle(FallbackStyle, Style.Language, &Style)) { @@ -2130,28 +2133,35 @@ FormatStyle getStyle(StringRef StyleName, StringRef FileName, llvm::sys::fs::make_absolute(Path); for (StringRef Directory = Path; !Directory.empty(); Directory = llvm::sys::path::parent_path(Directory)) { - if (!llvm::sys::fs::is_directory(Directory)) + + auto Status = FS->status(Directory); + if (!Status || + Status->getType() != llvm::sys::fs::file_type::directory_file) { continue; + } + SmallString<128> ConfigFile(Directory); llvm::sys::path::append(ConfigFile, ".clang-format"); DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n"); - bool IsFile = false; // Ignore errors from is_regular_file: we only need to know if we can read // the file or not. - llvm::sys::fs::is_regular_file(Twine(ConfigFile), IsFile); - + Status = FS->status(ConfigFile.str()); + bool IsFile = + Status && (Status->getType() == llvm::sys::fs::file_type::regular_file); if (!IsFile) { // Try _clang-format too, since dotfiles are not commonly used on Windows. ConfigFile = Directory; llvm::sys::path::append(ConfigFile, "_clang-format"); DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n"); - llvm::sys::fs::is_regular_file(Twine(ConfigFile), IsFile); + Status = FS->status(ConfigFile.str()); + IsFile = Status && + (Status->getType() == llvm::sys::fs::file_type::regular_file); } if (IsFile) { llvm::ErrorOr> Text = - llvm::MemoryBuffer::getFile(ConfigFile.c_str()); + FS->getBufferForFile(ConfigFile.str()); if (std::error_code EC = Text.getError()) { llvm::errs() << EC.message() << "\n"; break; -- 2.7.4