@@ -2600,6 +2600,10 @@ llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,
2600
2600
if (std::error_code EC = FS->makeAbsolute (Path))
2601
2601
return make_string_error (EC.message ());
2602
2602
2603
+ llvm::SmallVector<std::string, 2 > FilesToLookFor;
2604
+ FilesToLookFor.push_back (" .clang-format" );
2605
+ FilesToLookFor.push_back (" _clang-format" );
2606
+
2603
2607
for (StringRef Directory = Path; !Directory.empty ();
2604
2608
Directory = llvm::sys::path::parent_path (Directory)) {
2605
2609
@@ -2609,43 +2613,35 @@ llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,
2609
2613
continue ;
2610
2614
}
2611
2615
2612
- SmallString<128 > ConfigFile (Directory);
2613
-
2614
- llvm::sys::path::append (ConfigFile, " .clang-format" );
2615
- LLVM_DEBUG (llvm::dbgs () << " Trying " << ConfigFile << " ...\n " );
2616
+ for (const auto &F : FilesToLookFor) {
2617
+ SmallString<128 > ConfigFile (Directory);
2616
2618
2617
- Status = FS->status (ConfigFile.str ());
2618
- bool FoundConfigFile =
2619
- Status && (Status->getType () == llvm::sys::fs::file_type::regular_file);
2620
- if (!FoundConfigFile) {
2621
- // Try _clang-format too, since dotfiles are not commonly used on Windows.
2622
- ConfigFile = Directory;
2623
- llvm::sys::path::append (ConfigFile, " _clang-format" );
2619
+ llvm::sys::path::append (ConfigFile, F);
2624
2620
LLVM_DEBUG (llvm::dbgs () << " Trying " << ConfigFile << " ...\n " );
2621
+
2625
2622
Status = FS->status (ConfigFile.str ());
2626
- FoundConfigFile = Status && (Status->getType () ==
2627
- llvm::sys::fs::file_type::regular_file);
2628
- }
2629
2623
2630
- if (FoundConfigFile) {
2631
- llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text =
2632
- FS->getBufferForFile (ConfigFile.str ());
2633
- if (std::error_code EC = Text.getError ())
2634
- return make_string_error (EC.message ());
2635
- if (std::error_code ec =
2636
- parseConfiguration (Text.get ()->getBuffer (), &Style)) {
2637
- if (ec == ParseError::Unsuitable) {
2638
- if (!UnsuitableConfigFiles.empty ())
2639
- UnsuitableConfigFiles.append (" , " );
2640
- UnsuitableConfigFiles.append (ConfigFile);
2641
- continue ;
2624
+ if (Status &&
2625
+ (Status->getType () == llvm::sys::fs::file_type::regular_file)) {
2626
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text =
2627
+ FS->getBufferForFile (ConfigFile.str ());
2628
+ if (std::error_code EC = Text.getError ())
2629
+ return make_string_error (EC.message ());
2630
+ if (std::error_code ec =
2631
+ parseConfiguration (Text.get ()->getBuffer (), &Style)) {
2632
+ if (ec == ParseError::Unsuitable) {
2633
+ if (!UnsuitableConfigFiles.empty ())
2634
+ UnsuitableConfigFiles.append (" , " );
2635
+ UnsuitableConfigFiles.append (ConfigFile);
2636
+ continue ;
2637
+ }
2638
+ return make_string_error (" Error reading " + ConfigFile + " : " +
2639
+ ec.message ());
2642
2640
}
2643
- return make_string_error (" Error reading " + ConfigFile + " : " +
2644
- ec.message ());
2641
+ LLVM_DEBUG (llvm::dbgs ()
2642
+ << " Using configuration file " << ConfigFile << " \n " );
2643
+ return Style;
2645
2644
}
2646
- LLVM_DEBUG (llvm::dbgs ()
2647
- << " Using configuration file " << ConfigFile << " \n " );
2648
- return Style;
2649
2645
}
2650
2646
}
2651
2647
if (!UnsuitableConfigFiles.empty ())
0 commit comments