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.
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"
31 //////////////////////////////////////////////////////////////////////////
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.
42 CGitStatusCache(void);
43 ~CGitStatusCache(void);
46 static CGitStatusCache
& Instance();
48 static void Destroy();
49 static bool SaveCache();
52 GitStatus m_GitStatus
;
53 /// Refreshes the cache.
56 /// Get the status for a single path (main entry point, called from named-pipe code
57 CStatusCacheEntry
GetStatusForPath(const CTGitPath
& path
, DWORD flags
, bool bFetch
= true);
59 /// Find a directory in the cache (a new entry will be created if there isn't an existing entry)
60 CCachedDirectory
* GetDirectoryCacheEntry(const CTGitPath
& path
);
61 CCachedDirectory
* GetDirectoryCacheEntryNoCreate(const CTGitPath
& path
);
63 /// Add a folder to the background crawler's work list
64 void AddFolderForCrawling(const CTGitPath
& path
);
66 /// Removes the cache for a specific path, e.g. if a folder got deleted/renamed
67 void RemoveCacheForPath(const CTGitPath
& path
);
69 /// Removes all items from the cache
72 /// Call this method before getting the status for a shell request
73 void StartRequest(const CTGitPath
& path
);
74 /// Call this method after the data for the shell request has been gathered
75 void EndRequest(const CTGitPath
& path
);
77 /// Notifies the shell about file/folder status changes.
78 /// A notification is only sent for paths which aren't currently
79 /// in the list of handled shell requests to avoid deadlocks.
80 void UpdateShell(const CTGitPath
& path
);
82 size_t GetCacheSize() {return m_directoryCache
.size();}
83 int GetNumberOfWatchedPaths() {return watcher
.GetNumberOfWatchedPaths();}
88 void CloseWatcherHandles(HDEVNOTIFY hdev
);
89 void CGitStatusCache::CloseWatcherHandles(const CTGitPath
& path
);
91 bool WaitToRead(DWORD waitTime
= INFINITE
) {return m_rwSection
.WaitToRead(waitTime
);}
92 bool WaitToWrite(DWORD waitTime
= INFINITE
) {return m_rwSection
.WaitToWrite(waitTime
);}
93 void Done() {m_rwSection
.Done();}
94 bool IsWriter() {return m_rwSection
.IsWriter();}
95 #if defined (DEBUG) || defined (_DEBUG)
96 void AssertLock() {m_rwSection
.AssertLock();}
97 void AssertWriting() {m_rwSection
.AssertWriting();}
100 void AssertWriting() {;}
102 bool IsPathAllowed(const CTGitPath
& path
) {return !!m_shellCache
.IsPathAllowed(path
.GetWinPath());}
103 bool IsUnversionedAsModified() {return !!m_shellCache
.IsUnversionedAsModified();}
104 bool IsPathGood(const CTGitPath
& path
);
105 bool IsPathWatched(const CTGitPath
& path
) {return watcher
.IsPathWatched(path
);}
106 bool AddPathToWatch(const CTGitPath
& path
) {return watcher
.AddPath(path
);}
110 bool RemoveCacheForDirectory(CCachedDirectory
* cdir
);
111 CRWSection m_rwSection
;
112 CAtlList
<CString
> m_askedList
;
113 CCachedDirectory::CachedDirMap m_directoryCache
;
114 std::set
<CTGitPath
> m_NoWatchPaths
;
115 // SVNHelper m_svnHelp;
116 ShellCache m_shellCache
;
118 static CGitStatusCache
* m_pInstance
;
120 CFolderCrawler m_folderCrawler
;
121 CShellUpdater m_shellUpdater
;
123 CTGitPath m_mostRecentPath
;
124 CStatusCacheEntry m_mostRecentStatus
;
125 long m_mostRecentExpiresAt
;
127 CDirectoryWatcher watcher
;
129 friend class CCachedDirectory
; // Needed for access to the SVN helpers