Skip to content

Commit

Permalink
Merge pull request #17 from cmarcusreid/ignoreIndexLock
Browse files Browse the repository at this point in the history
Ignore file change events to "index.lock" and ".git" when invalidatin…
  • Loading branch information
cmarcusreid committed Jan 5, 2016
2 parents 701e3c9 + 743dd3b commit 399ae71
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/GitStatusCache/src/CacheInvalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ void CacheInvalidator::MonitorRepositoryDirectories(const Git::Status& status)

void CacheInvalidator::OnFileChanged(DirectoryMonitor::Token token, const boost::filesystem::path& path, DirectoryMonitor::FileAction action)
{
if (CacheInvalidator::ShouldIgnoreFileChange(path))
{
Log("CacheInvalidator.OnFileChanged.IgnoringFileChange", Severity::Spam)
<< R"(Ignoring file change. { "filePath": ")" << path.c_str() << R"(" })";
return;
}

std::string repositoryPath;
{
ReadLock readLock(m_tokensToRepositoriesMutex);
Expand All @@ -61,4 +68,13 @@ void CacheInvalidator::OnFileChanged(DirectoryMonitor::Token token, const boost:
}

m_cachePrimer.SchedulePrimingForRepositoryPathInFiveSeconds(repositoryPath);
}

/*static*/ bool CacheInvalidator::ShouldIgnoreFileChange(const boost::filesystem::path& path)
{
if (!path.has_filename())
return false;

auto filename = path.filename();
return filename.wstring() == L"index.lock" || filename.wstring() == L".git";
}
5 changes: 5 additions & 0 deletions src/GitStatusCache/src/CacheInvalidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class CacheInvalidator
std::unordered_map<DirectoryMonitor::Token, std::string> m_tokensToRepositories;
boost::shared_mutex m_tokensToRepositoriesMutex;

/**
* Checks if the file change can be safely ignored.
*/
static bool ShouldIgnoreFileChange(const boost::filesystem::path& path);

/**
* Handles file change notifications by invalidating cache entries and scheduling priming.
*/
Expand Down

0 comments on commit 399ae71

Please sign in to comment.