OSDN Git Service

Add Save Special Version to anther file
[tortoisegit/TortoiseGitJp.git] / src / Git / GitFolderStatus.h
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2006,2008 - Stefan Kueng\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 \r
19 #pragma once\r
20 \r
21 #include "GitStatus.h"\r
22 #include "TGitPath.h"\r
23 \r
24 /**\r
25  * \ingroup TortoiseShell\r
26  * a simple utility class:\r
27  * stores unique copies of given string values,\r
28  * i.e. for a given value, always the same const char*\r
29  * will be returned.\r
30  * \r
31  * The strings returned are owned by the pool!\r
32  */\r
33 class StringPool\r
34 {\r
35 public:\r
36 \r
37         StringPool() {emptyString[0] = 0;}\r
38         ~StringPool() {clear();}\r
39         \r
40         /**\r
41          * Return a string equal to value from the internal pool.\r
42          * If no such string is available, a new one is allocated.\r
43          * NULL is valid for value.\r
44          */\r
45         const char* GetString (const char* value);\r
46         \r
47         /**\r
48          * invalidates all strings returned by GetString()\r
49          * frees all internal data\r
50          */\r
51         void clear();\r
52         \r
53 private:\r
54 \r
55         // comparator: compare C-style strings\r
56         \r
57         struct LessString\r
58         {\r
59                 bool operator()(const char* lhs, const char* rhs) const\r
60                 {\r
61                         return strcmp (lhs, rhs) < 0;\r
62                 }\r
63         };\r
64         \r
65         // store the strings in a map\r
66         // caution: modifying the map must not modify the string pointers\r
67         \r
68         typedef std::set<const char*, LessString> pool_type;\r
69         pool_type pool;\r
70         char emptyString[1];\r
71 };\r
72 \r
73 \r
74 typedef struct FileStatusCacheEntry\r
75 {\r
76         git_wc_status_kind              status;\r
77         const char*                             author;         ///< points to a (possibly) shared value\r
78         const char*                             url;            ///< points to a (possibly) shared value\r
79         const char*                             owner;          ///< points to a (possible) lock owner\r
80         bool                                    needslock;\r
81         git_revnum_t                    rev;\r
82         int                                             askedcounter;\r
83         //git_lock_t *                  lock;\r
84         bool                                    tree_conflict;\r
85 } FileStatusCacheEntry;\r
86 \r
87 #define GITFOLDERSTATUS_CACHETIMES                              10\r
88 #define GITFOLDERSTATUS_CACHETIMEOUT                    2000\r
89 #define GITFOLDERSTATUS_RECURSIVECACHETIMEOUT   4000\r
90 #define GITFOLDERSTATUS_FOLDER                                  500\r
91 /**\r
92  * \ingroup TortoiseShell\r
93  * This class represents a caching mechanism for the\r
94  * subversion statuses. Once a status for a versioned\r
95  * file is requested (GetFileStatus()) first its checked\r
96  * if that status is already in the cache. If it is not\r
97  * then the subversion statuses for ALL files in the same\r
98  * directory is fetched and cached. This is because subversion\r
99  * needs almost the same time to get one or all status (in\r
100  * the same directory).\r
101  * To prevent a cache flush for the explorer folder view\r
102  * the cache is only fetched for versioned files and\r
103  * not for folders.\r
104  */\r
105 class GitFolderStatus\r
106 {\r
107 public:\r
108         GitFolderStatus(void);\r
109         ~GitFolderStatus(void);\r
110         const FileStatusCacheEntry *    GetFullStatus(const CTGitPath& filepath, BOOL bIsFolder, BOOL bColumnProvider = FALSE);\r
111         const FileStatusCacheEntry *    GetCachedItem(const CTGitPath& filepath);\r
112 \r
113         FileStatusCacheEntry            invalidstatus;\r
114 \r
115 private:\r
116         const FileStatusCacheEntry * BuildCache(const CTGitPath& filepath, const CString& sProjectRoot, BOOL bIsFolder, BOOL bDirectFolder = FALSE);\r
117         DWORD                           GetTimeoutValue();\r
118         //static git_error_t*   fillstatusmap (void *baton, const char *path, git_wc_status2_t *status, apr_pool_t *pool);\r
119         //static git_error_t*   findfolderstatus (void *baton, const char *path, git_wc_status2_t *status, apr_pool_t *pool);\r
120         static BOOL                     fillstatusmap(const struct wgFile_s *pFile, void *pUserData);\r
121         static void                     fillstatusmap_idx(CString &path,git_wc_status_kind status,void *pdata);\r
122 \r
123         static CTGitPath        folderpath;\r
124         void                            ClearCache();\r
125         \r
126         int                                     m_nCounter;\r
127         typedef std::map<stdstring, FileStatusCacheEntry> FileStatusMap;\r
128         FileStatusMap                   m_cache;\r
129         DWORD                                   m_TimeStamp;\r
130         FileStatusCacheEntry    dirstat;\r
131         FileStatusCacheEntry    filestat;\r
132         git_wc_status2_t *              dirstatus;\r
133         //apr_pool_t *                  rootpool;\r
134 \r
135         // merging these pools won't save memory\r
136         // but access will become slower\r
137         \r
138         StringPool              authors;       \r
139         StringPool              urls;\r
140         StringPool              owners;\r
141         char                    emptyString[1];\r
142 \r
143         stdstring               sCacheKey;\r
144 \r
145         HANDLE                  m_hInvalidationEvent;\r
146 \r
147         // The item we most recently supplied status for \r
148         CTGitPath               m_mostRecentPath;\r
149         const FileStatusCacheEntry* m_mostRecentStatus;\r
150 };\r
151 \r