Add whitelist/blacklist to $cquery/freshenIndex

This commit is contained in:
Fangrui Song 2018-01-20 11:34:37 -08:00
parent 273af8306f
commit 2e0f14bef8
2 changed files with 10 additions and 9 deletions

View File

@ -35,8 +35,6 @@ template <typename T>
struct Id {
size_t id;
static constexpr size_t INVALID_ID = static_cast<size_t>(-1);
Id() : id(0) {} // Needed for containers. Do not use directly.
explicit Id(size_t id) : id(id) {}

View File

@ -1,4 +1,5 @@
#include "cache_manager.h"
#include "match.h"
#include "message_handler.h"
#include "platform.h"
#include "project.h"
@ -11,23 +12,23 @@
namespace {
struct Ipc_CqueryFreshenIndex : public RequestMessage<Ipc_CqueryFreshenIndex> {
const static IpcId kIpcId = IpcId::CqueryFreshenIndex;
// FIXME fresh partial files
std::vector<std::string> whitelist;
std::vector<std::string> blacklist;
};
MAKE_REFLECT_STRUCT(Ipc_CqueryFreshenIndex, id);
MAKE_REFLECT_STRUCT(Ipc_CqueryFreshenIndex, id, whitelist, blacklist);
REGISTER_IPC_MESSAGE(Ipc_CqueryFreshenIndex);
struct CqueryFreshenIndexHandler : MessageHandler {
IpcId GetId() const override { return IpcId::CqueryFreshenIndex; }
void Run(std::unique_ptr<BaseIpcMessage> request) override {
struct CqueryFreshenIndexHandler : BaseMessageHandler<Ipc_CqueryFreshenIndex> {
void Run(Ipc_CqueryFreshenIndex* request) override {
LOG_S(INFO) << "Freshening " << project->entries.size() << " files";
// TODO: think about this flow and test it more.
GroupMatch matcher(request->whitelist, request->blacklist);
// Unmark all files whose timestamp has changed.
std::unique_ptr<ICacheManager> cache_manager = ICacheManager::Make(config);
for (const auto& file : db->files) {
if (!file.def)
if (!file.def || !matcher.IsMatch(file.def->path))
continue;
optional<int64_t> modification_timestamp =
@ -47,6 +48,8 @@ struct CqueryFreshenIndexHandler : MessageHandler {
// Send index requests for every file.
project->ForAllFilteredFiles(
config, [&](int i, const Project::Entry& entry) {
if (!matcher.IsMatch(entry.filename))
return;
optional<std::string> content = ReadContent(entry.filename);
if (!content) {
LOG_S(ERROR) << "When freshening index, cannot read file "