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