Remove unused variable
[TortoiseGit.git] / src / TGitCache / GitStatusCache.h
blob5b12d50828e4eedba23c58b7e6f0ac8715c61a93
1 // TortoiseGit - a Windows shell extension for easy version control
3 // External Cache Copyright (C) 2005 - 2006,2010, 2014 - TortoiseSVN
4 // Copyright (C) 2008-2011 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #pragma once
22 #include "TGitPath.h"
23 #include "StatusCacheEntry.h"
24 #include "CachedDirectory.h"
25 #include "FolderCrawler.h"
26 #include "DirectoryWatcher.h"
27 #include "ShellUpdater.h"
28 #include "ReaderWriterLock.h"
29 #include <atlcoll.h>
30 //////////////////////////////////////////////////////////////////////////
32 /**
33 * \ingroup TGitCache
34 * The main class handling the status cache.
35 * Provides access to a global object of itself which handles all
36 * the requests for status.
38 class CGitStatusCache
40 private:
41 CGitStatusCache(void);
42 ~CGitStatusCache(void);
44 public:
45 static CGitStatusCache& Instance();
46 static void Create();
47 static void Destroy();
48 static bool SaveCache();
50 public:
51 GitStatus m_GitStatus;
52 /// Refreshes the cache.
53 void Refresh();
55 /// Get the status for a single path (main entry point, called from named-pipe code
56 CStatusCacheEntry GetStatusForPath(const CTGitPath& path, DWORD flags, bool bFetch = true);
58 /// Find a directory in the cache (a new entry will be created if there isn't an existing entry)
59 CCachedDirectory * GetDirectoryCacheEntry(const CTGitPath& path, bool IsAddtoWatch=true);
60 CCachedDirectory * GetDirectoryCacheEntryNoCreate(const CTGitPath& path);
62 /// Add a folder to the background crawler's work list
63 void AddFolderForCrawling(const CTGitPath& path);
65 /// Removes the cache for a specific path, e.g. if a folder got deleted/renamed
66 void RemoveCacheForPath(const CTGitPath& path);
68 /// Removes all items from the cache
69 void ClearCache();
71 /// Call this method before getting the status for a shell request
72 void StartRequest(const CTGitPath& path);
73 /// Call this method after the data for the shell request has been gathered
74 void EndRequest(const CTGitPath& path);
76 /// Notifies the shell about file/folder status changes.
77 /// A notification is only sent for paths which aren't currently
78 /// in the list of handled shell requests to avoid deadlocks.
79 void UpdateShell(const CTGitPath& path);
81 size_t GetCacheSize() const {return m_directoryCache.size();}
82 int GetNumberOfWatchedPaths() {return watcher.GetNumberOfWatchedPaths();}
84 void Init();
85 void Stop();
87 void CloseWatcherHandles(HANDLE hFile);
88 void CloseWatcherHandles(const CTGitPath& path);
90 bool IsPathAllowed(const CTGitPath& path) {return !!m_shellCache.IsPathAllowed(path.GetWinPath());}
91 bool IsUnversionedAsModified() {return !!m_shellCache.IsUnversionedAsModified();}
92 bool IsPathGood(const CTGitPath& path);
93 bool IsPathWatched(const CTGitPath& path) {return watcher.IsPathWatched(path);}
94 bool AddPathToWatch(const CTGitPath& path) {return watcher.AddPath(path);}
95 bool BlockPath(const CTGitPath& path, DWORD timeout = 0);
96 bool UnBlockPath(const CTGitPath& path);
97 bool RemoveTimedoutBlocks();
99 CReaderWriterLock& GetGuard() { return m_guard; }
100 bool m_bClearMemory;
101 private:
102 bool RemoveCacheForDirectory(CCachedDirectory * cdir);
103 CReaderWriterLock m_guard;
104 CAtlList<CString> m_askedList;
105 CCachedDirectory::CachedDirMap m_directoryCache;
106 CComAutoCriticalSection m_NoWatchPathCritSec;
107 std::map<CTGitPath, DWORD> m_NoWatchPaths; ///< paths to block from getting crawled, and the time in ms until they're unblocked
108 // SVNHelper m_svnHelp;
109 ShellCache m_shellCache;
111 static CGitStatusCache* m_pInstance;
113 CFolderCrawler m_folderCrawler;
114 CShellUpdater m_shellUpdater;
116 CComAutoCriticalSection m_critSec;
117 CTGitPath m_mostRecentPath;
118 CStatusCacheEntry m_mostRecentStatus;
119 long m_mostRecentExpiresAt;
121 CDirectoryWatcher watcher;
123 friend class CCachedDirectory; // Needed for access to the SVN helpers