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 - 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.
23 #include "StatusCacheEntry.h"
24 #include "CachedDirectory.h"
25 #include "FolderCrawler.h"
26 #include "DirectoryWatcher.h"
27 #include "ShellUpdater.h"
28 #include "ReaderWriterLock.h"
30 //////////////////////////////////////////////////////////////////////////
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.
41 CGitStatusCache(void);
42 ~CGitStatusCache(void);
45 static CGitStatusCache
& Instance();
47 static void Destroy();
48 static bool SaveCache();
51 GitStatus m_GitStatus
;
52 /// Refreshes the cache.
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
, bool IsAddtoWatch
=true);
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
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() const {return m_directoryCache
.size();}
82 int GetNumberOfWatchedPaths() {return watcher
.GetNumberOfWatchedPaths();}
87 void CloseWatcherHandles(HANDLE hFile
);
88 void CloseWatcherHandles(const CTGitPath
& path
);
90 bool IsPathAllowed(const CTGitPath
& path
) {return !!m_shellCache
.IsPathAllowed(path
.GetWinPath());}
91 bool IsUnversionedAsModified() {return !!m_shellCache
.IsUnversionedAsModified();}
92 bool IsRecurseSubmodules() { return !!m_shellCache
.IsRecurseSubmodules(); }
93 bool IsPathGood(const CTGitPath
& path
);
94 bool IsPathWatched(const CTGitPath
& path
) {return watcher
.IsPathWatched(path
);}
95 bool AddPathToWatch(const CTGitPath
& path
) {return watcher
.AddPath(path
);}
96 bool BlockPath(const CTGitPath
& path
, DWORD timeout
= 0);
97 bool UnBlockPath(const CTGitPath
& path
);
98 bool RemoveTimedoutBlocks();
100 CReaderWriterLock
& GetGuard() { return m_guard
; }
103 bool RemoveCacheForDirectory(CCachedDirectory
* cdir
);
104 CReaderWriterLock m_guard
;
105 CAtlList
<CString
> m_askedList
;
106 CCachedDirectory::CachedDirMap m_directoryCache
;
107 CComAutoCriticalSection m_NoWatchPathCritSec
;
108 std::map
<CTGitPath
, DWORD
> m_NoWatchPaths
; ///< paths to block from getting crawled, and the time in ms until they're unblocked
109 // SVNHelper m_svnHelp;
110 ShellCache m_shellCache
;
112 static CGitStatusCache
* m_pInstance
;
114 CFolderCrawler m_folderCrawler
;
115 CShellUpdater m_shellUpdater
;
117 CComAutoCriticalSection m_critSec
;
118 CTGitPath m_mostRecentPath
;
119 CStatusCacheEntry m_mostRecentStatus
;
120 long m_mostRecentExpiresAt
;
122 CDirectoryWatcher watcher
;
124 friend class CCachedDirectory
; // Needed for access to the SVN helpers