Moved #include "git2.h" to stdafx.h
[TortoiseGit.git] / src / TGitCache / GitStatusCache.h
blobf2a4af25d5f5c6f3108d0967396fdb8834c1891d
1 // TortoiseGit - a Windows shell extension for easy version control
3 // External Cache Copyright (C) 2005 - 2006,2010 - 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 "ReaderWriterLock.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 CloseWatcherHandles(const CTGitPath& path);
92 bool IsPathAllowed(const CTGitPath& path) {return !!m_shellCache.IsPathAllowed(path.GetWinPath());}
93 bool IsUnversionedAsModified() {return !!m_shellCache.IsUnversionedAsModified();}
94 bool IsPathGood(const CTGitPath& path);
95 bool IsPathWatched(const CTGitPath& path) {return watcher.IsPathWatched(path);}
96 bool AddPathToWatch(const CTGitPath& path) {return watcher.AddPath(path);}
97 bool BlockPath(const CTGitPath& path, DWORD timeout = 0);
98 bool UnBlockPath(const CTGitPath& path);
99 bool RemoveTimedoutBlocks();
101 CReaderWriterLock& GetGuard() { return m_guard; }
102 bool m_bClearMemory;
103 private:
104 bool RemoveCacheForDirectory(CCachedDirectory * cdir);
105 CReaderWriterLock m_guard;
106 CAtlList<CString> m_askedList;
107 CCachedDirectory::CachedDirMap m_directoryCache;
108 CComAutoCriticalSection m_NoWatchPathCritSec;
109 std::map<CTGitPath, DWORD> m_NoWatchPaths; ///< paths to block from getting crawled, and the time in ms until they're unblocked
110 // SVNHelper m_svnHelp;
111 ShellCache m_shellCache;
113 static CGitStatusCache* m_pInstance;
115 CFolderCrawler m_folderCrawler;
116 CShellUpdater m_shellUpdater;
118 CComAutoCriticalSection m_critSec;
119 CTGitPath m_mostRecentPath;
120 CStatusCacheEntry m_mostRecentStatus;
121 long m_mostRecentExpiresAt;
123 CDirectoryWatcher watcher;
125 friend class CCachedDirectory; // Needed for access to the SVN helpers