Update version number to 1.4.3.0
[TortoiseGit.git] / src / TGitCache / CachedDirectory.h
blob93465e8d4789914616bbed23d94c1b8d7fdf4830
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 #define GIT_CACHE_VERSION 2
31 class CCachedDirectory
33 public:
34 typedef std::map<CTGitPath, CCachedDirectory *> CachedDirMap;
35 typedef CachedDirMap::iterator ItDir;
37 public:
39 CCachedDirectory();
40 CCachedDirectory(const CTGitPath& directoryPath);
41 ~CCachedDirectory(void);
42 CStatusCacheEntry GetStatusForMember(const CTGitPath& path, bool bRecursive, bool bFetch = true);
44 // If path is not emtpy, means fetch special file status.
45 int EnumFiles(CTGitPath *path = NULL, bool isFull=true);
46 CStatusCacheEntry GetOwnStatus(bool bRecursive);
47 bool IsOwnStatusValid() const;
48 void Invalidate();
49 void RefreshStatus(bool bRecursive);
50 void RefreshMostImportant();
51 BOOL SaveToDisk(FILE * pFile);
52 BOOL LoadFromDisk(FILE * pFile);
53 /// Get the current full status of this folder
54 git_wc_status_kind GetCurrentFullStatus() {return m_currentFullStatus;}
55 private:
56 // static git_error_t* GetStatusCallback(void *baton, const char *path, git_wc_status2_t *status);
57 static BOOL GetStatusCallback(CString & path, git_wc_status_kind status,bool isDir, void *pUserData);
58 void AddEntry(const CTGitPath& path, const git_wc_status2_t* pGitStatus, DWORD validuntil = 0);
59 CString GetCacheKey(const CTGitPath& path);
60 CString GetFullPathString(const CString& cacheKey);
61 CStatusCacheEntry LookForItemInCache(const CTGitPath& path, bool &bFound);
62 void UpdateChildDirectoryStatus(const CTGitPath& childDir, git_wc_status_kind childStatus);
64 // Calculate the complete, composite status from ourselves, our files, and our descendants
65 git_wc_status_kind CalculateRecursiveStatus();
67 // Update our composite status and deal with things if it's changed
68 void UpdateCurrentStatus();
71 private:
72 CComAutoCriticalSection m_critSec;
73 CComAutoCriticalSection m_critSecPath;
75 CTGitPath m_currentStatusFetchingPath;
76 DWORD m_currentStatusFetchingPathTicks;
77 // The cache of files and directories within this directory
78 typedef std::map<CString, CStatusCacheEntry> CacheEntryMap;
79 CacheEntryMap m_entryCache;
81 /// A vector if iterators to child directories - used to put-together recursive status
82 typedef std::map<CTGitPath, git_wc_status_kind> ChildDirStatus;
83 ChildDirStatus m_childDirectories;
85 // The timestamp of the .git\index file. For an unversioned directory, this will be zero
86 __int64 m_indexFileTime;
87 bool m_FullStatusFetched;
88 CGitHash m_Head;
90 std::vector<__int64> m_IgnoreFileTimeList;
91 // The timestamp of the .SVN\props dir. For an unversioned directory, this will be zero
92 // __int64 m_propsFileTime;
94 // The path of the directory with this object looks after
95 CTGitPath m_directoryPath;
97 // The status of THIS directory (not a composite of children or members)
98 CStatusCacheEntry m_ownStatus;
100 // Our current fully recursive status
101 git_wc_status_kind m_currentFullStatus;
102 bool m_bCurrentFullStatusValid;
104 // The most important status from all our file entries
105 git_wc_status_kind m_mostImportantFileStatus;
107 bool m_bRecursive; // used in the status callback
108 friend class CGitStatusCache;