some spaces-tabs code cleanup
[TortoiseGit.git] / src / TGitCache / GitStatusCache.h
bloba61a0a0b125fdd5c43972efeaa354556413c46dc
1 // TortoiseGit - a Windows shell extension for easy version control
3 // External Cache Copyright (C) 2005 - 2006 - Will Dean, Stefan Kueng
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 "SVNHelpers.h"
24 #include "StatusCacheEntry.h"
25 #include "CachedDirectory.h"
26 #include "FolderCrawler.h"
27 #include "DirectoryWatcher.h"
28 #include "ShellUpdater.h"
29 #include "RWSection.h"
30 #include "atlcoll.h"
32 //////////////////////////////////////////////////////////////////////////
34 /**
35 * \ingroup TSVNCache
36 * The main class handling the status cache.
37 * Provides access to a global object of itself which handles all
38 * the requests for status.
40 class CGitStatusCache
42 private:
43 CGitStatusCache(void);
44 ~CGitStatusCache(void);
46 public:
47 static CGitStatusCache& Instance();
48 static void Create();
49 static void Destroy();
50 static bool SaveCache();
52 public:
53 GitStatus m_GitStatus;
54 /// Refreshes the cache.
55 void Refresh();
57 /// Get the status for a single path (main entry point, called from named-pipe code
58 CStatusCacheEntry GetStatusForPath(const CTGitPath& path, DWORD flags, bool bFetch = true);
60 /// Find a directory in the cache (a new entry will be created if there isn't an existing entry)
61 CCachedDirectory * GetDirectoryCacheEntry(const CTGitPath& path, bool IsAddtoWatch=true);
62 CCachedDirectory * GetDirectoryCacheEntryNoCreate(const CTGitPath& path);
64 /// Add a folder to the background crawler's work list
65 void AddFolderForCrawling(const CTGitPath& path);
67 /// Removes the cache for a specific path, e.g. if a folder got deleted/renamed
68 void RemoveCacheForPath(const CTGitPath& path);
70 /// Removes all items from the cache
71 void ClearCache();
73 /// Call this method before getting the status for a shell request
74 void StartRequest(const CTGitPath& path);
75 /// Call this method after the data for the shell request has been gathered
76 void EndRequest(const CTGitPath& path);
78 /// Notifies the shell about file/folder status changes.
79 /// A notification is only sent for paths which aren't currently
80 /// in the list of handled shell requests to avoid deadlocks.
81 void UpdateShell(const CTGitPath& path);
83 size_t GetCacheSize() {return m_directoryCache.size();}
84 int GetNumberOfWatchedPaths() {return watcher.GetNumberOfWatchedPaths();}
86 void Init();
87 void Stop();
89 void CloseWatcherHandles(HDEVNOTIFY hdev);
90 void CGitStatusCache::CloseWatcherHandles(const CTGitPath& path);
92 bool WaitToRead(DWORD waitTime = INFINITE) {return m_rwSection.WaitToRead(waitTime);}
93 bool WaitToWrite(DWORD waitTime = INFINITE) {return m_rwSection.WaitToWrite(waitTime);}
94 void Done() {m_rwSection.Done();}
95 bool IsWriter() {return m_rwSection.IsWriter();}
96 #if defined (DEBUG) || defined (_DEBUG)
97 void AssertLock() {m_rwSection.AssertLock();}
98 void AssertWriting() {m_rwSection.AssertWriting();}
99 #else
100 void AssertLock() {;}
101 void AssertWriting() {;}
102 #endif
103 bool IsPathAllowed(const CTGitPath& path) {return !!m_shellCache.IsPathAllowed(path.GetWinPath());}
104 bool IsUnversionedAsModified() {return !!m_shellCache.IsUnversionedAsModified();}
105 bool IsPathGood(const CTGitPath& path);
106 bool IsPathWatched(const CTGitPath& path) {return watcher.IsPathWatched(path);}
107 bool AddPathToWatch(const CTGitPath& path) {return watcher.AddPath(path);}
109 bool m_bClearMemory;
110 private:
111 bool RemoveCacheForDirectory(CCachedDirectory * cdir);
112 CRWSection m_rwSection;
113 CAtlList<CString> m_askedList;
114 CCachedDirectory::CachedDirMap m_directoryCache;
115 std::set<CTGitPath> m_NoWatchPaths;
116 // SVNHelper m_svnHelp;
117 ShellCache m_shellCache;
119 static CGitStatusCache* m_pInstance;
121 CFolderCrawler m_folderCrawler;
122 CShellUpdater m_shellUpdater;
124 CTGitPath m_mostRecentPath;
125 CStatusCacheEntry m_mostRecentStatus;
126 long m_mostRecentExpiresAt;
128 CDirectoryWatcher watcher;
130 friend class CCachedDirectory; // Needed for access to the SVN helpers