TortoiseGitMerge: Adjust OVR mode cursor width to exact char width
[TortoiseGit.git] / src / TGitCache / CachedDirectory.h
blob0afe1c57a351c151f9bcea890ae6831de5f65f98
1 // TortoiseGit - a Windows shell extension for easy version control
3 // External Cache Copyright (C) 2005 - 2006, 2008, 2014 - TortoiseSVN
4 // Copyright (C) 2008-2012 - 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 "StatusCacheEntry.h"
23 #include "TGitPath.h"
25 /**
26 * \ingroup TGitCache
27 * Holds the status for a folder and all files and folders directly inside
28 * that folder.
30 #define GIT_CACHE_VERSION 2
32 class CCachedDirectory
34 public:
35 typedef std::map<CTGitPath, CCachedDirectory *> CachedDirMap;
36 typedef CachedDirMap::iterator ItDir;
38 public:
40 CCachedDirectory();
41 CCachedDirectory(const CTGitPath& directoryPath);
42 ~CCachedDirectory(void);
43 CStatusCacheEntry GetStatusForMember(const CTGitPath& path, bool bRecursive, bool bFetch = true);
44 CStatusCacheEntry GetCacheStatusForMember(const CTGitPath& path);
46 // If path is not emtpy, means fetch special file status.
47 int EnumFiles(const CTGitPath &path, bool isFull = true);
48 CStatusCacheEntry GetOwnStatus(bool bRecursive);
49 bool IsOwnStatusValid() const;
50 void Invalidate();
51 void RefreshStatus(bool bRecursive);
52 void RefreshMostImportant();
53 BOOL SaveToDisk(FILE * pFile);
54 BOOL LoadFromDisk(FILE * pFile);
55 /// Get the current full status of this folder
56 git_wc_status_kind GetCurrentFullStatus() const {return m_currentFullStatus;}
57 private:
59 CStatusCacheEntry GetStatusFromCache(const CTGitPath &path, bool bRecursive);
60 CStatusCacheEntry GetStatusFromGit(const CTGitPath &path, CString sProjectRoot);
62 // static git_error_t* GetStatusCallback(void *baton, const char *path, git_wc_status2_t *status);
63 static BOOL GetStatusCallback(const CString & path, git_wc_status_kind status, bool isDir, void * /*pUserData*/, bool assumeValid, bool skipWorktree);
64 void AddEntry(const CTGitPath& path, const git_wc_status2_t* pGitStatus, DWORD validuntil = 0);
65 CString GetCacheKey(const CTGitPath& path);
66 CString GetFullPathString(const CString& cacheKey);
67 CStatusCacheEntry LookForItemInCache(const CTGitPath& path, bool &bFound);
68 void UpdateChildDirectoryStatus(const CTGitPath& childDir, git_wc_status_kind childStatus);
70 // Calculate the complete, composite status from ourselves, our files, and our descendants
71 git_wc_status_kind CalculateRecursiveStatus();
73 // Update our composite status and deal with things if it's changed
74 void UpdateCurrentStatus();
77 private:
78 CComAutoCriticalSection m_critSec;
79 CComAutoCriticalSection m_critSecPath;
81 CTGitPath m_currentStatusFetchingPath;
82 // The cache of files and directories within this directory
83 typedef std::map<CString, CStatusCacheEntry> CacheEntryMap;
84 CacheEntryMap m_entryCache;
86 /// A vector if iterators to child directories - used to put-together recursive status
87 typedef std::map<CTGitPath, git_wc_status_kind> ChildDirStatus;
88 ChildDirStatus m_childDirectories;
90 // The path of the directory with this object looks after
91 CTGitPath m_directoryPath;
93 // The status of THIS directory (not a composite of children or members)
94 CStatusCacheEntry m_ownStatus;
96 // Our current fully recursive status
97 git_wc_status_kind m_currentFullStatus;
99 // The most important status from all our file entries
100 git_wc_status_kind m_mostImportantFileStatus;
102 bool m_bRecursive; // used in the status callback
103 friend class CGitStatusCache;