TortoiseGitBlame: Diff shown in wrong order
[TortoiseGit.git] / src / TGitCache / GitStatusCache.h
blob90c10d8b11217109479c6e3c836d67fd5b6c5e81
1 // TortoiseGit - a Windows shell extension for easy version control
3 // External Cache Copyright (C) 2005 - 2006,2010, 2014 - TortoiseSVN
4 // Copyright (C) 2008-2011, 2017 - 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 "StatusCacheEntry.h"
24 #include "CachedDirectory.h"
25 #include "FolderCrawler.h"
26 #include "DirectoryWatcher.h"
27 #include "ShellUpdater.h"
28 #include "ReaderWriterLock.h"
29 #include <atlcoll.h>
30 //////////////////////////////////////////////////////////////////////////
32 /**
33 * \ingroup TGitCache
34 * The main class handling the status cache.
35 * Provides access to a global object of itself which handles all
36 * the requests for status.
38 class CGitStatusCache
40 private:
41 CGitStatusCache(void);
42 ~CGitStatusCache(void);
44 public:
45 static CGitStatusCache& Instance();
46 static void Create();
47 static void Destroy();
48 static bool SaveCache();
50 public:
51 GitStatus m_GitStatus;
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);
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 /// Notifies the shell about file/folder status changes.
72 /// A notification is only sent for paths which aren't currently
73 /// in the list of handled shell requests to avoid deadlocks.
74 void UpdateShell(const CTGitPath& path);
76 size_t GetCacheSize() const {return m_directoryCache.size();}
77 int GetNumberOfWatchedPaths() {return watcher.GetNumberOfWatchedPaths();}
79 void Init();
80 void Stop();
82 void CloseWatcherHandles(HANDLE hFile);
83 void CloseWatcherHandles(const CTGitPath& path);
85 bool IsPathAllowed(const CTGitPath& path) {return !!m_shellCache.IsPathAllowed(path.GetWinPath());}
86 bool IsUnversionedAsModified() {return !!m_shellCache.IsUnversionedAsModified();}
87 bool IsRecurseSubmodules() { return !!m_shellCache.IsRecurseSubmodules(); }
88 bool IsPathGood(const CTGitPath& path);
89 bool IsPathWatched(const CTGitPath& path) {return watcher.IsPathWatched(path);}
90 bool AddPathToWatch(const CTGitPath& path) {return watcher.AddPath(path);}
91 bool BlockPath(const CTGitPath& path, ULONGLONG timeout = 0);
92 bool UnBlockPath(const CTGitPath& path);
93 bool RemoveTimedoutBlocks();
95 CReaderWriterLock& GetGuard() { return m_guard; }
96 bool m_bClearMemory;
97 private:
98 static CString GetSpecialFolder(REFKNOWNFOLDERID rfid);
99 bool RemoveCacheForDirectory(CCachedDirectory * cdir);
100 CReaderWriterLock m_guard;
101 CReaderWriterLock m_guardcacheddirectories;
102 CAtlList<CString> m_askedList;
103 CCachedDirectory::CachedDirMap m_directoryCache;
104 CComAutoCriticalSection m_NoWatchPathCritSec;
105 std::map<CTGitPath, ULONGLONG> m_NoWatchPaths; ///< paths to block from getting crawled, and the time in ms until they're unblocked
106 ShellCache m_shellCache;
108 static CGitStatusCache* m_pInstance;
110 CFolderCrawler m_folderCrawler;
111 CShellUpdater m_shellUpdater;
113 CComAutoCriticalSection m_critSec;
114 CTGitPath m_mostRecentPath;
115 CStatusCacheEntry m_mostRecentStatus;
116 LONGLONG m_mostRecentExpiresAt;
118 CDirectoryWatcher watcher;
120 friend class CCachedDirectory; // Needed for access to the SVN helpers