OSDN Git Service

Improve log speed.
[tortoisegit/TortoiseGitJp.git] / src / TGitCache / GitStatusCache.h
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // External Cache Copyright (C) 2005 - 2006 - Will Dean, Stefan Kueng\r
4 \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
9 \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
14 \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
18 //\r
19 #pragma once\r
20 \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
30 \r
31 //////////////////////////////////////////////////////////////////////////\r
32 \r
33 /**\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
38  */\r
39 class CGitStatusCache\r
40 {\r
41 private:\r
42         CGitStatusCache(void);\r
43         ~CGitStatusCache(void);\r
44 \r
45 public:\r
46         static CGitStatusCache& Instance();\r
47         static void Create();\r
48         static void Destroy();\r
49         static bool SaveCache();\r
50 \r
51 public:\r
52         /// Refreshes the cache.\r
53         void Refresh();\r
54 \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
57 \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
61 \r
62         /// Add a folder to the background crawler's work list\r
63         void AddFolderForCrawling(const CTGitPath& path);\r
64 \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
67 \r
68         /// Removes all items from the cache\r
69         void ClearCache();\r
70         \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
75         \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
80 \r
81         size_t GetCacheSize() {return m_directoryCache.size();}\r
82         int GetNumberOfWatchedPaths() {return watcher.GetNumberOfWatchedPaths();}\r
83 \r
84         void Init();\r
85         void Stop();\r
86 \r
87         void CloseWatcherHandles(HDEVNOTIFY hdev);\r
88         void CGitStatusCache::CloseWatcherHandles(const CTGitPath& path);\r
89 \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
97 #else\r
98         void AssertLock() {;}\r
99         void AssertWriting() {;}\r
100 #endif\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
106 \r
107         bool m_bClearMemory;\r
108 private:\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
116 \r
117         static CGitStatusCache* m_pInstance;\r
118 \r
119         CFolderCrawler m_folderCrawler;\r
120         CShellUpdater m_shellUpdater;\r
121 \r
122         CTGitPath m_mostRecentPath;\r
123         CStatusCacheEntry m_mostRecentStatus;\r
124         long m_mostRecentExpiresAt;\r
125 \r
126         CDirectoryWatcher watcher;\r
127 \r
128         friend class CCachedDirectory;  // Needed for access to the SVN helpers\r
129 };\r