integrate libgit2 read tree function
[TortoiseGit.git] / src / Git / GitFolderStatus.h
blob81970d91ef3d80a7a1c1c91ed2cd3c46ff05dbbe
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2006,2008 - Stefan Kueng
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 "GitStatus.h"
22 #include "TGitPath.h"
24 /**
25 * \ingroup TortoiseShell
26 * a simple utility class:
27 * stores unique copies of given string values,
28 * i.e. for a given value, always the same const char*
29 * will be returned.
31 * The strings returned are owned by the pool!
33 class StringPool
35 public:
37 StringPool() {emptyString[0] = 0;}
38 ~StringPool() {clear();}
40 /**
41 * Return a string equal to value from the internal pool.
42 * If no such string is available, a new one is allocated.
43 * NULL is valid for value.
45 const char* GetString (const char* value);
47 /**
48 * invalidates all strings returned by GetString()
49 * frees all internal data
51 void clear();
53 private:
55 // comparator: compare C-style strings
57 struct LessString
59 bool operator()(const char* lhs, const char* rhs) const
61 return strcmp (lhs, rhs) < 0;
65 // store the strings in a map
66 // caution: modifying the map must not modify the string pointers
68 typedef std::set<const char*, LessString> pool_type;
69 pool_type pool;
70 char emptyString[1];
74 typedef struct FileStatusCacheEntry
76 git_wc_status_kind status;
77 const char* author; ///< points to a (possibly) shared value
78 const char* url; ///< points to a (possibly) shared value
79 const char* owner; ///< points to a (possible) lock owner
80 bool needslock;
81 git_revnum_t rev;
82 int askedcounter;
83 //git_lock_t * lock;
84 bool tree_conflict;
85 } FileStatusCacheEntry;
87 #define GITFOLDERSTATUS_CACHETIMES 10
88 #define GITFOLDERSTATUS_CACHETIMEOUT 2000
89 #define GITFOLDERSTATUS_RECURSIVECACHETIMEOUT 4000
90 #define GITFOLDERSTATUS_FOLDER 500
91 /**
92 * \ingroup TortoiseShell
93 * This class represents a caching mechanism for the
94 * subversion statuses. Once a status for a versioned
95 * file is requested (GetFileStatus()) first its checked
96 * if that status is already in the cache. If it is not
97 * then the subversion statuses for ALL files in the same
98 * directory is fetched and cached. This is because subversion
99 * needs almost the same time to get one or all status (in
100 * the same directory).
101 * To prevent a cache flush for the explorer folder view
102 * the cache is only fetched for versioned files and
103 * not for folders.
105 class GitFolderStatus
107 public:
108 GitFolderStatus(void);
109 ~GitFolderStatus(void);
110 const FileStatusCacheEntry * GetFullStatus(const CTGitPath& filepath, BOOL bIsFolder, BOOL bColumnProvider = FALSE);
111 const FileStatusCacheEntry * GetCachedItem(const CTGitPath& filepath);
113 FileStatusCacheEntry invalidstatus;
115 GitStatus m_GitStatus;
117 private:
118 const FileStatusCacheEntry * BuildCache(const CTGitPath& filepath, const CString& sProjectRoot, BOOL bIsFolder, BOOL bDirectFolder = FALSE);
119 DWORD GetTimeoutValue();
120 //static git_error_t* fillstatusmap (void *baton, const char *path, git_wc_status2_t *status, apr_pool_t *pool);
121 //static git_error_t* findfolderstatus (void *baton, const char *path, git_wc_status2_t *status, apr_pool_t *pool);
122 static BOOL fillstatusmap(const struct wgFile_s *pFile, void *pUserData);
123 static void fillstatusmap_idx(CString &path,git_wc_status_kind status,void *pdata);
125 static CTGitPath folderpath;
126 void ClearCache();
128 int m_nCounter;
129 typedef std::map<stdstring, FileStatusCacheEntry> FileStatusMap;
130 FileStatusMap m_cache;
131 DWORD m_TimeStamp;
132 FileStatusCacheEntry dirstat;
133 FileStatusCacheEntry filestat;
134 git_wc_status2_t * dirstatus;
135 //apr_pool_t * rootpool;
137 // merging these pools won't save memory
138 // but access will become slower
140 StringPool authors;
141 StringPool urls;
142 StringPool owners;
143 char emptyString[1];
145 stdstring sCacheKey;
147 HANDLE m_hInvalidationEvent;
149 // The item we most recently supplied status for
150 CTGitPath m_mostRecentPath;
151 const FileStatusCacheEntry* m_mostRecentStatus;