Fix stash problem when svn dcommit at dirty working space
[TortoiseGit.git] / src / TGitCache / GitStatusCache.h
blob0e31e6f5806f99ca3ea6f9108679814b15c4c825
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 /// 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);
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() {return m_directoryCache.size();}
82 int GetNumberOfWatchedPaths() {return watcher.GetNumberOfWatchedPaths();}
84 void Init();
85 void Stop();
87 void CloseWatcherHandles(HDEVNOTIFY hdev);
88 void CGitStatusCache::CloseWatcherHandles(const CTGitPath& path);
90 bool WaitToRead(DWORD waitTime = INFINITE) {return m_rwSection.WaitToRead(waitTime);}
91 bool WaitToWrite(DWORD waitTime = INFINITE) {return m_rwSection.WaitToWrite(waitTime);}
92 void Done() {m_rwSection.Done();}
93 bool IsWriter() {return m_rwSection.IsWriter();}
94 #if defined (DEBUG) || defined (_DEBUG)
95 void AssertLock() {m_rwSection.AssertLock();}
96 void AssertWriting() {m_rwSection.AssertWriting();}
97 #else
98 void AssertLock() {;}
99 void AssertWriting() {;}
100 #endif
101 bool IsPathAllowed(const CTGitPath& path) {return !!m_shellCache.IsPathAllowed(path.GetWinPath());}
102 bool IsUnversionedAsModified() {return !!m_shellCache.IsUnversionedAsModified();}
103 bool IsPathGood(const CTGitPath& path);
104 bool IsPathWatched(const CTGitPath& path) {return watcher.IsPathWatched(path);}
105 bool AddPathToWatch(const CTGitPath& path) {return watcher.AddPath(path);}
107 bool m_bClearMemory;
108 private:
109 bool RemoveCacheForDirectory(CCachedDirectory * cdir);
110 CRWSection m_rwSection;
111 CAtlList<CString> m_askedList;
112 CCachedDirectory::CachedDirMap m_directoryCache;
113 std::set<CTGitPath> m_NoWatchPaths;
114 // SVNHelper m_svnHelp;
115 ShellCache m_shellCache;
117 static CGitStatusCache* m_pInstance;
119 CFolderCrawler m_folderCrawler;
120 CShellUpdater m_shellUpdater;
122 CTGitPath m_mostRecentPath;
123 CStatusCacheEntry m_mostRecentStatus;
124 long m_mostRecentExpiresAt;
126 CDirectoryWatcher watcher;
128 friend class CCachedDirectory; // Needed for access to the SVN helpers