Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
assert(!(!pathnamesRef.empty() && !fileSettingsRef.empty()));

if (!fileSettingsRef.empty()) {
// TODO: de-duplicate

std::list<FileSettings> fileSettings;
if (!mSettings.fileFilters.empty()) {
// filter only for the selected filenames from all project files
Expand All @@ -225,6 +223,8 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
fileSettings = fileSettingsRef;
}

// TODO: de-duplicate

mFileSettings.clear();

frontend::applyLang(fileSettings, mSettings, mEnforcedLang);
Expand Down Expand Up @@ -265,19 +265,6 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
return false;
}

// de-duplicate files
{
auto it = filesResolved.begin();
while (it != filesResolved.end()) {
const std::string& absname = Path::getAbsoluteFilePath(it->spath());
// TODO: log if duplicated files were dropped
filesResolved.erase(std::remove_if(std::next(it), filesResolved.end(), [&](const FileWithDetails& entry) {
return Path::getAbsoluteFilePath(entry.spath()) == absname;
}), filesResolved.end());
++it;
}
}

std::list<FileWithDetails> files;
if (!mSettings.fileFilters.empty()) {
files = filterFiles(mSettings.fileFilters, filesResolved);
Expand All @@ -291,6 +278,19 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
files = std::move(filesResolved);
}

// de-duplicate files
{
auto it = files.begin();
while (it != files.end()) {
const std::string& absname = it->abspath();
// TODO: log if duplicated files were dropped
files.erase(std::remove_if(std::next(it), files.end(), [&](const FileWithDetails& entry) {
return entry.abspath() == absname;
}), files.end());
++it;
}
}

frontend::applyLang(files, mSettings, mEnforcedLang);

// sort the markup last
Expand Down
10 changes: 10 additions & 0 deletions lib/filesettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class FileWithDetails
{
mPath = std::move(path);
mPathSimplified = Path::simplifyPath(mPath);
mPathAbsolute.clear();
}

const std::string& path() const
Expand All @@ -62,6 +63,14 @@ class FileWithDetails
return mPathSimplified;
}

const std::string& abspath() const
{
// use delayed resolution as it will fail for files which do not exist
if (mPathAbsolute.empty())
mPathAbsolute = Path::getAbsoluteFilePath(mPath);
return mPathAbsolute;
}

std::size_t size() const
{
return mSize;
Expand Down Expand Up @@ -89,6 +98,7 @@ class FileWithDetails
private:
std::string mPath;
std::string mPathSimplified;
mutable std::string mPathAbsolute;
Standards::Language mLang = Standards::Language::None;
std::size_t mSize;
std::size_t mFsFileId{0};
Expand Down
Loading