Fixed issue #4141: Cannot remove remote: "usage: git remote remove <name>"
[TortoiseGit.git] / src / TGitCache / CachedDirectory.h
blob4da9ea3e3d5f7d6f3fdaf97de6ff7fbb40fdebe2
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, 2014, 2016-2017, 2021-2023 - 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 using CachedDirMap = std::map<CTGitPath, CCachedDirectory*>;
37 public:
39 CCachedDirectory();
40 CCachedDirectory(const CTGitPath& directoryPath);
41 ~CCachedDirectory();
42 CStatusCacheEntry GetStatusForMember(const CTGitPath& path, bool bRecursive, bool bFetch = true);
43 CString GetProjectRoot() const;
45 private:
46 CStatusCacheEntry GetCacheStatusForMember(const CTGitPath& path);
48 // If path is not emtpy, means fetch special file status.
49 int EnumFiles(const CTGitPath& path, CString sProjectRoot, const CString& sSubPath, bool isSelf);
50 CStatusCacheEntry GetOwnStatus(bool bRecursive);
51 bool IsOwnStatusValid() const;
52 public:
53 void Invalidate();
54 void RefreshStatus(bool bRecursive);
55 private:
56 void RefreshMostImportant(bool bUpdateShell = true);
57 BOOL SaveToDisk(FILE * pFile);
58 BOOL LoadFromDisk(FILE * pFile);
59 public:
60 /// Get the current full status of this folder
61 git_wc_status_kind GetCurrentFullStatus() const {return m_currentFullStatus;}
62 private:
64 CStatusCacheEntry GetStatusFromCache(const CTGitPath &path, bool bRecursive);
65 CStatusCacheEntry GetStatusFromGit(const CTGitPath &path, const CString& sProjectRoot, bool isSelf);
67 static BOOL GetStatusCallback(const CString& path, const git_wc_status2_t* status, bool isDir, __int64 lastwritetime, void* baton);
68 void AddEntry(const CTGitPath& path, const git_wc_status2_t* pGitStatus, __int64 lastwritetime);
69 CString GetCacheKey(const CTGitPath& path);
70 CString GetFullPathString(const CString& cacheKey);
71 void UpdateChildDirectoryStatus(const CTGitPath& childDir, git_wc_status_kind childStatus);
73 // Calculate the complete, composite status from ourselves, our files, and our descendants
74 git_wc_status_kind CalculateRecursiveStatus();
76 // Update our composite status and deal with things if it's changed
77 void UpdateCurrentStatus();
78 void SetChildStatus(const CString& childDir, git_wc_status_kind childStatus);
79 void KeepChildStatus(const CString& childDir);
81 private:
82 CComAutoCriticalSection m_critSec;
84 // The cache of files and directories within this directory
85 using CacheEntryMap = std::map<CString, CStatusCacheEntry>;
86 CacheEntryMap m_entryCache;
87 CacheEntryMap m_entryCache_tmp; // used for updating m_entryCache and removing "removed" entries
89 /// A vector if iterators to child directories - used to put-together recursive status
90 using ChildDirStatus = std::map<CString, git_wc_status_kind>;
91 ChildDirStatus m_childDirectories;
92 ChildDirStatus m_childDirectories_tmp; // used for updating m_childDirectories and removing "removed" entries
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 = git_wc_status_none;
103 // The most important status from all our file entries
104 git_wc_status_kind m_mostImportantFileStatus = git_wc_status_none;
106 bool m_bRecursive = true; // used in the status callback
107 friend class CGitStatusCache;