1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // External Cache Copyright (C) 2005 - 2006 - Will Dean, Stefan Kueng
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
21 #include "TGitPath.h"
\r
22 //#include "SVNHelpers.h"
\r
23 #include "StatusCacheEntry.h"
\r
24 #include "CachedDirectory.h"
\r
25 #include "FolderCrawler.h"
\r
26 #include "DirectoryWatcher.h"
\r
27 #include "ShellUpdater.h"
\r
28 #include "RWSection.h"
\r
29 #include "atlcoll.h"
\r
31 //////////////////////////////////////////////////////////////////////////
\r
34 * \ingroup TSVNCache
\r
35 * The main class handling the status cache.
\r
36 * Provides access to a global object of itself which handles all
\r
37 * the requests for status.
\r
39 class CGitStatusCache
\r
42 CGitStatusCache(void);
\r
43 ~CGitStatusCache(void);
\r
46 static CGitStatusCache& Instance();
\r
47 static void Create();
\r
48 static void Destroy();
\r
49 static bool SaveCache();
\r
52 /// Refreshes the cache.
\r
55 /// Get the status for a single path (main entry point, called from named-pipe code
\r
56 CStatusCacheEntry GetStatusForPath(const CTGitPath& path, DWORD flags, bool bFetch = true);
\r
58 /// Find a directory in the cache (a new entry will be created if there isn't an existing entry)
\r
59 CCachedDirectory * GetDirectoryCacheEntry(const CTGitPath& path);
\r
60 CCachedDirectory * GetDirectoryCacheEntryNoCreate(const CTGitPath& path);
\r
62 /// Add a folder to the background crawler's work list
\r
63 void AddFolderForCrawling(const CTGitPath& path);
\r
65 /// Removes the cache for a specific path, e.g. if a folder got deleted/renamed
\r
66 void RemoveCacheForPath(const CTGitPath& path);
\r
68 /// Removes all items from the cache
\r
71 /// Call this method before getting the status for a shell request
\r
72 void StartRequest(const CTGitPath& path);
\r
73 /// Call this method after the data for the shell request has been gathered
\r
74 void EndRequest(const CTGitPath& path);
\r
76 /// Notifies the shell about file/folder status changes.
\r
77 /// A notification is only sent for paths which aren't currently
\r
78 /// in the list of handled shell requests to avoid deadlocks.
\r
79 void UpdateShell(const CTGitPath& path);
\r
81 size_t GetCacheSize() {return m_directoryCache.size();}
\r
82 int GetNumberOfWatchedPaths() {return watcher.GetNumberOfWatchedPaths();}
\r
87 void CloseWatcherHandles(HDEVNOTIFY hdev);
\r
88 void CGitStatusCache::CloseWatcherHandles(const CTGitPath& path);
\r
90 bool WaitToRead(DWORD waitTime = INFINITE) {return m_rwSection.WaitToRead(waitTime);}
\r
91 bool WaitToWrite(DWORD waitTime = INFINITE) {return m_rwSection.WaitToWrite(waitTime);}
\r
92 void Done() {m_rwSection.Done();}
\r
93 bool IsWriter() {return m_rwSection.IsWriter();}
\r
94 #if defined (DEBUG) || defined (_DEBUG)
\r
95 void AssertLock() {m_rwSection.AssertLock();}
\r
96 void AssertWriting() {m_rwSection.AssertWriting();}
\r
98 void AssertLock() {;}
\r
99 void AssertWriting() {;}
\r
101 bool IsPathAllowed(const CTGitPath& path) {return !!m_shellCache.IsPathAllowed(path.GetWinPath());}
\r
102 bool IsUnversionedAsModified() {return !!m_shellCache.IsUnversionedAsModified();}
\r
103 bool IsPathGood(const CTGitPath& path);
\r
104 bool IsPathWatched(const CTGitPath& path) {return watcher.IsPathWatched(path);}
\r
105 bool AddPathToWatch(const CTGitPath& path) {return watcher.AddPath(path);}
\r
107 bool m_bClearMemory;
\r
109 bool RemoveCacheForDirectory(CCachedDirectory * cdir);
\r
110 CRWSection m_rwSection;
\r
111 CAtlList<CString> m_askedList;
\r
112 CCachedDirectory::CachedDirMap m_directoryCache;
\r
113 std::set<CTGitPath> m_NoWatchPaths;
\r
114 // SVNHelper m_svnHelp;
\r
115 ShellCache m_shellCache;
\r
117 static CGitStatusCache* m_pInstance;
\r
119 CFolderCrawler m_folderCrawler;
\r
120 CShellUpdater m_shellUpdater;
\r
122 CTGitPath m_mostRecentPath;
\r
123 CStatusCacheEntry m_mostRecentStatus;
\r
124 long m_mostRecentExpiresAt;
\r
126 CDirectoryWatcher watcher;
\r
128 friend class CCachedDirectory; // Needed for access to the SVN helpers
\r