r264275 - Revert "removed redundant comment in format::getStyle."
Eric Liu via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 24 06:22:29 PDT 2016
Author: ioeric
Date: Thu Mar 24 08:22:28 2016
New Revision: 264275
URL: http://llvm.org/viewvc/llvm-project?rev=264275&view=rev
Log:
Revert "removed redundant comment in format::getStyle."
This reverts commit r264254.
Modified:
cfe/trunk/lib/Format/Format.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=264275&r1=264274&r2=264275&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu Mar 24 08:22:28 2016
@@ -2099,7 +2099,10 @@ static FormatStyle::LanguageKind getLang
}
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
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<std::unique_ptr<llvm::MemoryBuffer>> Text =
- llvm::MemoryBuffer::getFile(ConfigFile.c_str());
+ FS->getBufferForFile(ConfigFile.str());
if (std::error_code EC = Text.getError()) {
llvm::errs() << EC.message() << "\n";
break;
More information about the cfe-commits
mailing list