OSDN Git Service

GitStatusListCtrl port build complete
[tortoisegit/TortoiseGitJp.git] / Git / GitStatus.h
1 #pragma once\r
2 \r
3 #ifdef _MFC_VER\r
4 //#     include "SVNPrompt.h"\r
5 #endif\r
6 #include "TGitPath.h"\r
7 \r
8 #pragma warning (push,1)\r
9 typedef std::basic_string<wchar_t> wide_string;\r
10 #ifdef UNICODE\r
11 #       define stdstring wide_string\r
12 #else\r
13 #       define stdstring std::string\r
14 #endif\r
15 #pragma warning (pop)\r
16 \r
17 #include "TGitPath.h"\r
18 \r
19 typedef enum type_git_wc_status_kind\r
20 {\r
21         git_wc_status_none,\r
22         git_wc_status_unversioned,\r
23         git_wc_status_ignored,\r
24         git_wc_status_normal,\r
25         git_wc_status_external,\r
26         git_wc_status_incomplete,\r
27         git_wc_status_missing,\r
28         git_wc_status_deleted,\r
29         git_wc_status_replaced,\r
30         git_wc_status_modified,\r
31         git_wc_status_merged,\r
32         git_wc_status_added,\r
33         git_wc_status_conflicted,\r
34         git_wc_status_obstructed,\r
35 \r
36 }git_wc_status_kind;\r
37 \r
38 typedef enum\r
39 {\r
40         git_depth_empty,\r
41         git_depth_infinity,\r
42         git_depth_unknown,\r
43         git_depth_files,\r
44         git_depth_immediates,\r
45 }git_depth_t;\r
46 \r
47 \r
48 #define GIT_REV_ZERO _T("0000000000000000000000000000000000000000")\r
49 typedef CString git_revnum_t;\r
50 typedef int git_error_t;\r
51 \r
52 typedef struct git_wc_status2_t\r
53\r
54   /** The status of the entries text. */\r
55   git_wc_status_kind text_status;\r
56 \r
57   /** The status of the entries properties. */\r
58   git_wc_status_kind prop_status;\r
59 }git_wc_status2;\r
60 \r
61 #define MAX_STATUS_STRING_LENGTH                256\r
62 \r
63 /**\r
64  * \ingroup Git\r
65  * Handles Subversion status of working copies.\r
66  */\r
67 class GitStatus\r
68 {\r
69 public:\r
70         GitStatus(bool * pbCanceled = NULL);\r
71         ~GitStatus(void);\r
72 \r
73 \r
74         /**\r
75          * Reads the Subversion status of the working copy entry. No\r
76          * recurse is done, even if the entry is a directory.\r
77          * If the status of the text and property part are different\r
78          * then the more important status is returned.\r
79          */\r
80         static git_wc_status_kind GetAllStatus(const CTGitPath& path, git_depth_t depth = git_depth_empty);\r
81 \r
82         /**\r
83          * Reads the Subversion status of the working copy entry and all its\r
84          * subitems. The resulting status is determined by using priorities for\r
85          * each status. The status with the highest priority is then returned.\r
86          * If the status of the text and property part are different then\r
87          * the more important status is returned.\r
88          */\r
89         static git_wc_status_kind GetAllStatusRecursive(const CTGitPath& path);\r
90 \r
91         /**\r
92          * Returns the status which is more "important" of the two statuses specified.\r
93          * This is used for the "recursive" status functions on folders - i.e. which status\r
94          * should be returned for a folder which has several files with different statuses\r
95          * in it.\r
96          */                                     \r
97         static git_wc_status_kind GetMoreImportant(git_wc_status_kind status1, git_wc_status_kind status2);\r
98         \r
99         /**\r
100          * Checks if a status is "important", i.e. if the status indicates that the user should know about it.\r
101          * E.g. a "normal" status is not important, but "modified" is.\r
102          * \param status the status to check\r
103          */\r
104         static BOOL IsImportant(git_wc_status_kind status) {return (GetMoreImportant(git_wc_status_added, status)==status);}\r
105 \r
106         /**\r
107          * Reads the Subversion text status of the working copy entry. No\r
108          * recurse is done, even if the entry is a directory.\r
109          * The result is stored in the public member variable status.\r
110          * Use this method if you need detailed information about a file/folder, not just the raw status (like "normal", "modified").\r
111          * \r
112          * \param path the pathname of the entry\r
113          * \param update true if the status should be updated with the repository. Default is false.\r
114          * \return If update is set to true the HEAD revision of the repository is returned. If update is false then -1 is returned.\r
115          * \remark If the return value is -2 then the status could not be obtained.\r
116          */\r
117         git_revnum_t GetStatus(const CTGitPath& path, bool update = false, bool noignore = false, bool noexternals = false);\r
118 \r
119         /**\r
120          * Returns a string representation of a Subversion status.\r
121          * \param status the status enum\r
122          * \param string a string representation\r
123          */\r
124         static void GetStatusString(git_wc_status_kind status, size_t buflen, TCHAR * string);\r
125         static void GetStatusString(HINSTANCE hInst, git_wc_status_kind status, TCHAR * string, int size, WORD lang);\r
126 \r
127         /**\r
128          * Returns the string representation of a depth.\r
129          */\r
130 #ifdef _MFC_VER\r
131         static CString GetDepthString(git_depth_t depth);\r
132 #endif\r
133         static void GetDepthString(HINSTANCE hInst, git_depth_t depth, TCHAR * string, int size, WORD lang);\r
134 \r
135         /**\r
136          * Returns the status of the first file of the given path. Use GetNextFileStatus() to obtain\r
137          * the status of the next file in the list.\r
138          * \param path the path of the folder from where the status list should be obtained\r
139          * \param retPath the path of the file for which the status was returned\r
140          * \param update set this to true if you want the status to be updated with the repository (needs network access)\r
141          * \param recurse true to fetch the status recursively\r
142          * \param bNoIgnore true to not fetch the ignored files\r
143          * \param bNoExternals true to not fetch the status of included Git:externals\r
144          * \return the status\r
145          */\r
146         git_wc_status2_t * GetFirstFileStatus(const CTGitPath& path, CTGitPath& retPath, bool update = false, git_depth_t depth = git_depth_infinity, bool bNoIgnore = true, bool bNoExternals = false);\r
147         unsigned int GetFileCount() const {return /*apr_hash_count(m_statushash);*/0;}\r
148         unsigned int GetVersionedCount() const;\r
149         /**\r
150          * Returns the status of the next file in the file list. If no more files are in the list then NULL is returned.\r
151          * See GetFirstFileStatus() for details.\r
152          */\r
153         git_wc_status2_t * GetNextFileStatus(CTGitPath& retPath);\r
154         /**\r
155          * Checks if a path is an external folder.\r
156          * This is necessary since Subversion returns two entries for external folders: one with the status Git_wc_status_external\r
157          * and one with the 'real' status of that folder. GetFirstFileStatus() and GetNextFileStatus() only return the 'real'\r
158          * status, so with this method it's possible to check if the status also is Git_wc_status_external.\r
159          */\r
160         bool IsExternal(const CTGitPath& path) const;\r
161         /**\r
162          * Checks if a path is in an external folder.\r
163          */\r
164         bool IsInExternal(const CTGitPath& path) const;\r
165 \r
166         /**\r
167          * Clears the memory pool.\r
168          */\r
169         void ClearPool();\r
170 \r
171         /**\r
172          * This member variable hold the status of the last call to GetStatus().\r
173          */\r
174         git_wc_status2_t *                      status;                         ///< the status result of GetStatus()\r
175 \r
176         git_revnum_t                            headrev;                        ///< the head revision fetched with GetFirstStatus()\r
177 \r
178         bool *                                          m_pbCanceled;\r
179 #ifdef _MFC_VER\r
180 friend class Git;       // So that Git can get to our m_err\r
181         /**\r
182          * Returns the last error message as a CString object.\r
183          */\r
184         CString GetLastErrorMsg() const;\r
185 \r
186         /** \r
187          * Set a list of paths which will be considered when calling GetFirstFileStatus.\r
188          * If a filter is set, then GetFirstFileStatus/GetNextFileStatus will only return items which are in the filter list\r
189          */\r
190         void SetFilter(const CTGitPathList& fileList);\r
191         void ClearFilter();\r
192 \r
193 #else\r
194         /**\r
195          * Returns the last error message as a CString object.\r
196          */\r
197         stdstring GetLastErrorMsg() const;\r
198 #endif\r
199 \r
200 \r
201 protected:\r
202 //      apr_pool_t *                            m_pool;                 ///< the memory pool\r
203 private:\r
204         typedef struct sort_item\r
205         {\r
206                 const void *key;\r
207 //              apr_ssize_t klen;\r
208                 void *value;\r
209         } sort_item;\r
210 \r
211         typedef struct hashbaton_t\r
212         {\r
213                 GitStatus*              pThis;\r
214 //              apr_hash_t *    hash;\r
215 //              apr_hash_t *    exthash;\r
216         } hash_baton_t;\r
217 \r
218 //      git_client_ctx_t *                      ctx;\r
219         git_wc_status_kind                      m_allstatus;    ///< used by GetAllStatus and GetAllStatusRecursive\r
220         git_error_t *                           m_err;                  ///< Subversion error baton\r
221 \r
222 #ifdef _MFC_VER\r
223 //      GitPrompt                                       m_prompt;\r
224 #endif\r
225 \r
226         /**\r
227          * Returns a numeric value indicating the importance of a status. \r
228          * A higher number indicates a more important status.\r
229          */\r
230         static int GetStatusRanking(git_wc_status_kind status);\r
231 \r
232         /**\r
233          * Callback function which collects the raw status from a Git_client_status() function call\r
234          */\r
235 //      static git_error_t * getallstatus (void *baton, const char *path, git_wc_status2_t *status, apr_pool_t *pool);\r
236 \r
237         /**\r
238          * Callback function which stores the raw status from a Git_client_status() function call\r
239          * in a hash table.\r
240          */\r
241 //      static git_error_t * getstatushash (void *baton, const char *path, git_wc_status2_t *status, apr_pool_t *pool);\r
242 \r
243         /**\r
244          * helper function to sort a hash to an array\r
245          */\r
246 //      static apr_array_header_t * sort_hash (apr_hash_t *ht, int (*comparison_func) (const sort_item *,\r
247 //                                                                              const sort_item *), apr_pool_t *pool);\r
248 \r
249         /**\r
250          * Callback function used by qsort() which does the comparison of two elements\r
251          */\r
252         static int __cdecl sort_compare_items_as_paths (const sort_item *a, const sort_item *b);\r
253 \r
254         //for GetFirstFileStatus and GetNextFileStatus\r
255 //      apr_hash_t *                            m_statushash;\r
256 //      apr_array_header_t *            m_statusarray;\r
257         unsigned int                            m_statushashindex;\r
258 //      apr_hash_t *                            m_externalhash;\r
259 \r
260 #pragma warning(push)\r
261 #pragma warning(disable: 4200)\r
262         struct STRINGRESOURCEIMAGE\r
263         {\r
264                 WORD nLength;\r
265                 WCHAR achString[];\r
266         };\r
267 #pragma warning(pop)    // C4200\r
268 \r
269         static int LoadStringEx(HINSTANCE hInstance, UINT uID, LPTSTR lpBuffer, int nBufferMax, WORD wLanguage);\r
270         static git_error_t* cancel(void *baton);\r
271 \r
272         // A sorted list of filenames (in Git format, in lowercase) \r
273         // when this list is set, we only pick-up files during a GetStatus which are found in this list\r
274         typedef std::vector<std::string> StdStrAVector;\r
275         StdStrAVector m_filterFileList;\r
276 };\r
277 \r
278 \r
279