Merge branch 'master' of git://github.com/Jopie64/tortoisegit
[TortoiseGit.git] / src / TGitCache / CachedDirectory.h
blob4d32ec0996fb1238c82ae8327c0c7d4a15cd1c62
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // External Cache Copyright (C) 2005 - 2006, 2008 - TortoiseSVN
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 "StatusCacheEntry.h"
22 #include "TGitPath.h"
24 /**
25 * \ingroup TSVNCache
26 * Holds the status for a folder and all files and folders directly inside
27 * that folder.
29 class CCachedDirectory
31 public:
32 typedef std::map<CTGitPath, CCachedDirectory *> CachedDirMap;
33 typedef CachedDirMap::iterator ItDir;
35 public:
37 CCachedDirectory();
38 CCachedDirectory(const CTGitPath& directoryPath);
39 ~CCachedDirectory(void);
40 CStatusCacheEntry GetStatusForMember(const CTGitPath& path, bool bRecursive, bool bFetch = true);
41 CStatusCacheEntry GetOwnStatus(bool bRecursive);
42 bool IsOwnStatusValid() const;
43 void Invalidate();
44 void RefreshStatus(bool bRecursive);
45 void RefreshMostImportant();
46 BOOL SaveToDisk(FILE * pFile);
47 BOOL LoadFromDisk(FILE * pFile);
48 /// Get the current full status of this folder
49 git_wc_status_kind GetCurrentFullStatus() {return m_currentFullStatus;}
50 private:
51 // static git_error_t* GetStatusCallback(void *baton, const char *path, git_wc_status2_t *status);
52 static BOOL GetStatusCallback(const struct wgFile_s *pFile, void *pUserData);
53 void AddEntry(const CTGitPath& path, const git_wc_status2_t* pGitStatus, DWORD validuntil = 0);
54 CString GetCacheKey(const CTGitPath& path);
55 CString GetFullPathString(const CString& cacheKey);
56 CStatusCacheEntry LookForItemInCache(const CTGitPath& path, bool &bFound);
57 void UpdateChildDirectoryStatus(const CTGitPath& childDir, git_wc_status_kind childStatus);
59 // Calculate the complete, composite status from ourselves, our files, and our descendants
60 git_wc_status_kind CalculateRecursiveStatus();
62 // Update our composite status and deal with things if it's changed
63 void UpdateCurrentStatus();
66 private:
67 CComAutoCriticalSection m_critSec;
68 CComAutoCriticalSection m_critSecPath;
70 CTGitPath m_currentStatusFetchingPath;
71 DWORD m_currentStatusFetchingPathTicks;
72 // The cache of files and directories within this directory
73 typedef std::map<CString, CStatusCacheEntry> CacheEntryMap;
74 CacheEntryMap m_entryCache;
76 /// A vector if iterators to child directories - used to put-together recursive status
77 typedef std::map<CTGitPath, git_wc_status_kind> ChildDirStatus;
78 ChildDirStatus m_childDirectories;
80 // The timestamp of the .git\index file. For an unversioned directory, this will be zero
81 __int64 m_indexFileTime;
82 // The timestamp of the .SVN\props dir. For an unversioned directory, this will be zero
83 // __int64 m_propsFileTime;
85 // The path of the directory with this object looks after
86 CTGitPath m_directoryPath;
88 // The status of THIS directory (not a composite of children or members)
89 CStatusCacheEntry m_ownStatus;
91 // Our current fully recursive status
92 git_wc_status_kind m_currentFullStatus;
93 bool m_bCurrentFullStatusValid;
95 // The most important status from all our file entries
96 git_wc_status_kind m_mostImportantFileStatus;
98 bool m_bRecursive; // used in the status callback
99 friend class CGitStatusCache;