Fixed issue #4133: libgit2 returned: failed to parse revision specifier (ref ending...
[TortoiseGit.git] / src / Git / GitFolderStatus.h
blobea56588f8a538d56c8579f8261cb3d8f5d227dc7
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012, 2014, 2016-2017, 2021-2023 - TortoiseGit
4 // Copyright (C) 2003-2006,2008,2011 - TortoiseSVN
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 "GitStatus.h"
23 #include "TGitPath.h"
24 #include "SmartHandle.h"
26 struct FileStatusCacheEntry
28 git_wc_status_kind status = git_wc_status_none;
29 int askedcounter = -1;
30 bool assumeValid = false;
31 bool skipWorktree = false;
34 #define GITFOLDERSTATUS_CACHETIMES 10
35 #define GITFOLDERSTATUS_CACHETIMEOUT 2000
36 #define GITFOLDERSTATUS_RECURSIVECACHETIMEOUT 4000
37 #define GITFOLDERSTATUS_FOLDER 500
38 /**
39 * \ingroup TortoiseShell
40 * This class represents a caching mechanism for the
41 * git statuses. Once a status for a versioned
42 * file is requested (GetFileStatus()) first its checked
43 * if that status is already in the cache. If it is not
44 * then the git statuses for ALL files in the same
45 * directory is fetched and cached. This is because git
46 * needs almost the same time to get one or all status (in
47 * the same directory).
48 * To prevent a cache flush for the explorer folder view
49 * the cache is only fetched for versioned files and
50 * not for folders.
52 class GitFolderStatus
54 public:
55 GitFolderStatus();
56 ~GitFolderStatus();
57 const FileStatusCacheEntry * GetFullStatus(const CTGitPath& filepath, BOOL bIsFolder);
58 const FileStatusCacheEntry * GetCachedItem(const CTGitPath& filepath);
60 FileStatusCacheEntry invalidstatus;
62 GitStatus m_GitStatus;
64 private:
65 const FileStatusCacheEntry * BuildCache(const CTGitPath& filepath, const CString& sProjectRoot, BOOL bIsFolder, BOOL bDirectFolder = FALSE);
66 ULONGLONG GetTimeoutValue();
68 void ClearCache();
70 using FileStatusMap = std::map<std::wstring, FileStatusCacheEntry>;
71 FileStatusMap m_cache;
72 ULONGLONG m_TimeStamp = 0;
73 FileStatusCacheEntry dirstat;
74 git_wc_status2_t* dirstatus = nullptr;
76 std::wstring sCacheKey;
78 CAutoGeneralHandle m_hInvalidationEvent;
80 // The item we most recently supplied status for
81 CTGitPath m_mostRecentPath;
82 const FileStatusCacheEntry* m_mostRecentStatus = nullptr;