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